From a96fcb236fa2cc2e624b34553487dd1595f1b601 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 30 Oct 2023 15:11:12 +0100 Subject: [PATCH] refactor: set type for mimetype aware adapters --- .php-cs-fixer.dist.php | 2 +- spec/Gaufrette/FilesystemSpec.php | 2 +- src/Gaufrette/Adapter/AsyncAwsS3.php | 4 ++-- src/Gaufrette/Adapter/AwsS3.php | 2 +- src/Gaufrette/Adapter/AzureBlobStorage.php | 2 +- src/Gaufrette/Adapter/InMemory.php | 2 +- src/Gaufrette/Adapter/Local.php | 3 ++- src/Gaufrette/Adapter/MimeTypeProvider.php | 4 ++-- src/Gaufrette/FilesystemInterface.php | 2 +- 9 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2f829560f..d68945fde 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -21,7 +21,7 @@ 'no_break_comment' => false, 'no_extra_blank_lines' => true, 'no_spaces_around_offset' => true, - 'no_trailing_comma_in_singleline' => true, + 'no_trailing_comma_in_singleline_array' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, diff --git a/spec/Gaufrette/FilesystemSpec.php b/spec/Gaufrette/FilesystemSpec.php index 6924bad5f..f40b13b01 100644 --- a/spec/Gaufrette/FilesystemSpec.php +++ b/spec/Gaufrette/FilesystemSpec.php @@ -322,7 +322,7 @@ function it_delegates_checksum_calculation_to_adapter_when_adapter_is_checksum_c $extendedAdapter->read('filename')->shouldNotBeCalled(); $extendedAdapter->checksum('filename')->shouldBeCalled()->willReturn(12); - $this->checksum('filename')->shouldReturn("12"); + $this->checksum('filename')->shouldReturn('12'); } function it_delegates_mime_type_resolution_to_adapter_when_adapter_is_mime_type_provider(ExtendedAdapter $extendedAdapter) diff --git a/src/Gaufrette/Adapter/AsyncAwsS3.php b/src/Gaufrette/Adapter/AsyncAwsS3.php index 972cdf38d..a11b7cd9b 100644 --- a/src/Gaufrette/Adapter/AsyncAwsS3.php +++ b/src/Gaufrette/Adapter/AsyncAwsS3.php @@ -176,11 +176,11 @@ public function size(string $key): int return (int) $result->getContentLength(); } - public function mimeType(string $key): string + public function mimeType(string $key): string|bool { $result = $this->service->headObject($this->getOptions($key)); - return $result->getContentType(); + return $result->getContentType() ?: false; } /** diff --git a/src/Gaufrette/Adapter/AwsS3.php b/src/Gaufrette/Adapter/AwsS3.php index ace91dc4f..9e9141de5 100644 --- a/src/Gaufrette/Adapter/AwsS3.php +++ b/src/Gaufrette/Adapter/AwsS3.php @@ -173,7 +173,7 @@ public function size(string $key): int } } - public function mimeType(string $key): string|bool + public function mimeType(string $key): bool|string { try { $result = $this->service->headObject($this->getOptions($key)); diff --git a/src/Gaufrette/Adapter/AzureBlobStorage.php b/src/Gaufrette/Adapter/AzureBlobStorage.php index f94d03b28..5352e5bc0 100644 --- a/src/Gaufrette/Adapter/AzureBlobStorage.php +++ b/src/Gaufrette/Adapter/AzureBlobStorage.php @@ -286,7 +286,7 @@ public function size(string $key): int /** * {@inheritdoc} */ - public function mimeType(string $key): string + public function mimeType(string $key): string|bool { $this->init(); list($containerName, $key) = $this->tokenizeKey($key); diff --git a/src/Gaufrette/Adapter/InMemory.php b/src/Gaufrette/Adapter/InMemory.php index 7f76b3881..f87d68924 100644 --- a/src/Gaufrette/Adapter/InMemory.php +++ b/src/Gaufrette/Adapter/InMemory.php @@ -120,7 +120,7 @@ public function isDirectory(string $path): bool return false; } - public function mimeType(string $key): string + public function mimeType(string $key): bool|string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); diff --git a/src/Gaufrette/Adapter/Local.php b/src/Gaufrette/Adapter/Local.php index e19af1a1b..e56da5f0a 100644 --- a/src/Gaufrette/Adapter/Local.php +++ b/src/Gaufrette/Adapter/Local.php @@ -183,11 +183,12 @@ public function size(string $key): int } /** + * {@inheritdoc} * @throws \OutOfBoundsException If the computed path is out of the directory * @throws \InvalidArgumentException if the directory already exists * @throws \RuntimeException if the directory could not be created */ - public function mimeType(string $key): string + public function mimeType(string $key): bool|string { $fileInfo = new \finfo(FILEINFO_MIME_TYPE); diff --git a/src/Gaufrette/Adapter/MimeTypeProvider.php b/src/Gaufrette/Adapter/MimeTypeProvider.php index 53617beaf..863e9a75e 100644 --- a/src/Gaufrette/Adapter/MimeTypeProvider.php +++ b/src/Gaufrette/Adapter/MimeTypeProvider.php @@ -10,7 +10,7 @@ interface MimeTypeProvider { /** - * Returns the mime type of the specified key. + * @return false|string the mime type of the specified key. */ - public function mimeType(string $key): string; + public function mimeType(string $key): string|bool; } diff --git a/src/Gaufrette/FilesystemInterface.php b/src/Gaufrette/FilesystemInterface.php index 9a686ab8f..57d16dd76 100644 --- a/src/Gaufrette/FilesystemInterface.php +++ b/src/Gaufrette/FilesystemInterface.php @@ -167,7 +167,7 @@ public function createFile($key); * * @param string $key * - * @return string + * @return string|false * * @throws \InvalidArgumentException If $key is invalid */