Skip to content

Commit

Permalink
refactor: set type for mimetype aware adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Oct 30, 2023
1 parent 94d89cd commit bf12aef
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spec/Gaufrette/FilesystemSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Gaufrette/Adapter/AsyncAwsS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Gaufrette/Adapter/AwsS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/Gaufrette/Adapter/AzureBlobStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Gaufrette/Adapter/InMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/Gaufrette/Adapter/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/Gaufrette/Adapter/MimeTypeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/Gaufrette/FilesystemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function createFile($key);
*
* @param string $key
*
* @return string
* @return string|false
*
* @throws \InvalidArgumentException If $key is invalid
*/
Expand Down

0 comments on commit bf12aef

Please sign in to comment.