Skip to content

Commit

Permalink
add missing return types
Browse files Browse the repository at this point in the history
  • Loading branch information
frasmage committed Apr 6, 2024
1 parent 1c3a5a7 commit 660f127
Show file tree
Hide file tree
Showing 29 changed files with 254 additions and 247 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ All SourceAdapter classes have been significantly refactored.
### Other
- Improved MediableCollection annotions to support generic types
- Removed the `\Plank\Mediable\Stream` class in favor of the `guzzlehttp/psr7` implementation. This removes the direct dependency on the `psr/http-message` library.
- `\Plank\Mediable\HandlesMediaUploadExceptions::transformMediaUploadException()` parameter and return type changed from `\Exception` to `\Throwable`.

## 5.5.0 - 2022-05-09
- Filename and pathname sanitization will use the app locale when transliterating UTF-8 characters to ascii.
Expand Down
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Install the necessary command line tools for the types of images that you are working with. See [spatie/image-optimizer documentation](https://github.com/spatie/image-optimizer/blob/main/README.md#optimization-tools) for installation instructions on various operating systems.
* add the `image_optimization.enabled` and `image_optimization.optimizers` configs to the `config/mediable.php` file. See the [sample configuration file](https://github.com/plank/laravel-mediable/blob/master/config/mediable.php) for a recommended baseline setup.
* The `ImageManipulation::usingHashForFilename()` method has been renamed to `ImageManipulation::isUsingHashForFilename()` to avoid confusion with the `useHashForFilename()` method.
* `\Plank\Mediable\HandlesMediaUploadExceptions::transformMediaUploadException()` parameter and return type changed from `\Exception` to `\Throwable`.

## 4.x to 5.x

Expand Down
6 changes: 3 additions & 3 deletions src/HandlesMediaUploadExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ trait HandlesMediaUploadExceptions
/**
* Transform a MediaUploadException into an HttpException.
*
* @param \Exception $e
* @return \Exception
* @param \Throwable $e
* @return \Throwable
*/
protected function transformMediaUploadException(Exception $e): Exception
protected function transformMediaUploadException(\Throwable $e): \Throwable
{
if ($e instanceof MediaUploadException) {
$status_code = $this->getStatusCodeForMediaUploadException($e);
Expand Down
4 changes: 2 additions & 2 deletions src/ImageManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(callable $callback)
$this->setOptimizers(config('mediable.image_optimization.optimizers', []));
}

public static function make(callable $callback)
public static function make(callable $callback): self
{
return new self($callback);
}
Expand Down Expand Up @@ -411,7 +411,7 @@ public function getOptimizerChain(): OptimizerChain
return $chain;
}

private function setOptimizers(array $customOptimizers)
private function setOptimizers(array $customOptimizers): void
{
foreach ($customOptimizers as $optimizerClass => $args) {
if (!is_a($optimizerClass, Optimizer::class, true)) {
Expand Down
2 changes: 1 addition & 1 deletion src/ImageManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function determineFilename(
return sprintf('%s-%s', $originalMedia->filename, $variant->variant_name);
}

public function validateMedia(Media $media)
public function validateMedia(Media $media): void
{
if ($media->aggregate_type != Media::TYPE_IMAGE) {
throw ImageManipulationException::invalidMediaType($media->aggregate_type);
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/CreateImageVariants.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct($models, $variantNames, bool $forceRecreate = false)
$this->forceRecreate = $forceRecreate;
}

public function handle()
public function handle(): void
{
foreach ($this->getModels() as $model) {
foreach ($this->getVariantNames() as $variantName) {
Expand Down
4 changes: 2 additions & 2 deletions src/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function scopeWhereIsOriginal(Builder $q): void
$q->whereNull('original_media_id');
}

public function scopeWhereIsVariant(Builder $q, string $variant_name = null)
public function scopeWhereIsVariant(Builder $q, string $variant_name = null): void
{
$q->whereNotNull('original_media_id');
if ($variant_name) {
Expand Down Expand Up @@ -407,7 +407,7 @@ public function contents(): string
* Get a read stream to the file
* @return StreamInterface
*/
public function stream()
public function stream(): StreamInterface
{
$stream = $this->storage()->readStream($this->getDiskPath());
if (method_exists(Utils::class, 'streamFor')) {
Expand Down
2 changes: 1 addition & 1 deletion src/UrlGenerators/BaseUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function isPubliclyAccessible(): bool
* @param mixed $default
* @return mixed
*/
protected function getDiskConfig(string $key, $default = null)
protected function getDiskConfig(string $key, $default = null): mixed
{
return $this->config->get("filesystems.disks.{$this->media->disk}.{$key}", $default);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Integration/Commands/ImportMediaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getEnvironmentSetUp($app)
$app['config']->set('mediable.strict_type_checking', false);
}

public function test_it_creates_media_for_unmatched_files()
public function test_it_creates_media_for_unmatched_files(): void
{
$artisan = $this->getArtisan();
$media1 = factory(Media::class)->make(['disk' => 'tmp', 'filename' => 'foo']);
Expand All @@ -42,7 +42,7 @@ public function test_it_creates_media_for_unmatched_files()
);
}

public function test_it_creates_media_for_unmatched_files_in_directory()
public function test_it_creates_media_for_unmatched_files_in_directory(): void
{
$artisan = $this->getArtisan();
$media1 = factory(Media::class)->make(
Expand All @@ -60,7 +60,7 @@ public function test_it_creates_media_for_unmatched_files_in_directory()
$this->assertEquals(['bar'], Media::pluck('filename')->toArray());
}

public function test_it_creates_media_for_unmatched_files_non_recursively()
public function test_it_creates_media_for_unmatched_files_non_recursively(): void
{
$artisan = $this->getArtisan();
$media1 = factory(Media::class)->make(
Expand All @@ -81,7 +81,7 @@ public function test_it_creates_media_for_unmatched_files_non_recursively()
$this->assertEquals(['foo'], Media::pluck('filename')->toArray());
}

public function test_it_skips_files_of_unmatched_aggregate_type()
public function test_it_skips_files_of_unmatched_aggregate_type(): void
{
$artisan = $this->getArtisan();
$filesystem = app(FilesystemManager::class);
Expand All @@ -105,7 +105,7 @@ public function test_it_skips_files_of_unmatched_aggregate_type()
);
}

public function test_it_updates_existing_media()
public function test_it_updates_existing_media(): void
{
$artisan = $this->getArtisan();
$media1 = factory(Media::class)->create(
Expand Down Expand Up @@ -141,7 +141,7 @@ public function test_it_updates_existing_media()
);
}

protected function getArtisan()
protected function getArtisan(): Artisan
{
return app(Artisan::class);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/Commands/PruneMediaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function setUp(): void
$this->withoutMockingConsoleOutput();
}

public function test_it_deletes_media_without_files()
public function test_it_deletes_media_without_files(): void
{
$artisan = $this->getArtisan();
$media1 = factory(Media::class)->create(['id' => 1, 'disk' => 'tmp']);
Expand All @@ -29,7 +29,7 @@ public function test_it_deletes_media_without_files()
$this->assertEquals("Pruned 1 record(s).\n", $artisan->output());
}

public function test_it_prunes_directory()
public function test_it_prunes_directory(): void
{
$artisan = $this->getArtisan();
$media1 = factory(Media::class)->create(
Expand All @@ -45,7 +45,7 @@ public function test_it_prunes_directory()
$this->assertEquals("Pruned 1 record(s).\n", $artisan->output());
}

public function test_it_prunes_non_recursively()
public function test_it_prunes_non_recursively(): void
{
$artisan = $this->getArtisan();
$media1 = factory(Media::class)->create(
Expand All @@ -61,7 +61,7 @@ public function test_it_prunes_non_recursively()
$this->assertEquals("Pruned 1 record(s).\n", $artisan->output());
}

public function getArtisan()
public function getArtisan(): Artisan
{
return app(Artisan::class);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Commands/SyncMediaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SyncMediaCommandTest extends TestCase
{
public function test_it_calls_prune_and_install()
public function test_it_calls_prune_and_install(): void
{
$this->withoutMockingConsoleOutput();
/** @var SyncMediaCommand $command */
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function setUp(): void
$this->useDatabase();
}

public function test_it_can_use_different_connection()
public function test_it_can_use_different_connection(): void
{
$media = factory(Media::class)->create(['id' => 1]);
$mediable = factory(SampleMediable::class)->create();
Expand All @@ -32,7 +32,7 @@ public function test_it_can_use_different_connection()
$this->assertEquals(1, $mediable->firstMedia('foo')->id);
}

protected function setupConnection()
protected function setupConnection(): void
{
$this->app['config']->set('database.connections.my_connection', [
'driver' => 'sqlite',
Expand Down
24 changes: 12 additions & 12 deletions tests/Integration/HandlesMediaExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class HandlesMediaExceptionsTest extends TestCase
{
public function test_it_returns_a_403_for_disallowed_disk()
public function test_it_returns_a_403_for_disallowed_disk(): void
{
$e = (new SampleExceptionHandler())->render(
ForbiddenException::diskNotAllowed('foo')
Expand All @@ -24,7 +24,7 @@ public function test_it_returns_a_403_for_disallowed_disk()
$this->assertHttpException($e, 403);
}

public function test_it_returns_a_404_for_missing_file()
public function test_it_returns_a_404_for_missing_file(): void
{
$e = (new SampleExceptionHandler())->render(
FileNotFoundException::fileNotFound('non/existing.jpg')
Expand All @@ -33,7 +33,7 @@ public function test_it_returns_a_404_for_missing_file()
$this->assertHttpException($e, 404);
}

public function test_it_returns_a_409_on_duplicate_file()
public function test_it_returns_a_409_on_duplicate_file(): void
{
$e = (new SampleExceptionHandler())->render(
FileExistsException::fileExists('already/existing.jpg')
Expand All @@ -42,7 +42,7 @@ public function test_it_returns_a_409_on_duplicate_file()
$this->assertHttpException($e, 409);
}

public function test_it_returns_a_413_for_too_big_file()
public function test_it_returns_a_413_for_too_big_file(): void
{
$e = (new SampleExceptionHandler())->render(
FileSizeException::fileIsTooBig(3, 2)
Expand All @@ -51,7 +51,7 @@ public function test_it_returns_a_413_for_too_big_file()
$this->assertHttpException($e, 413);
}

public function test_it_returns_a_415_for_type_mismatch()
public function test_it_returns_a_415_for_type_mismatch(): void
{
$e = (new SampleExceptionHandler())->render(
FileNotSupportedException::strictTypeMismatch('text/foo', 'bar')
Expand All @@ -60,7 +60,7 @@ public function test_it_returns_a_415_for_type_mismatch()
$this->assertHttpException($e, 415);
}

public function test_it_returns_a_415_for_unknown_type()
public function test_it_returns_a_415_for_unknown_type(): void
{
$e = (new SampleExceptionHandler())->render(
FileNotSupportedException::unrecognizedFileType('text/foo', 'bar')
Expand All @@ -69,7 +69,7 @@ public function test_it_returns_a_415_for_unknown_type()
$this->assertHttpException($e, 415);
}

public function test_it_returns_a_415_for_restricted_type()
public function test_it_returns_a_415_for_restricted_type(): void
{
$e = (new SampleExceptionHandler())->render(
FileNotSupportedException::mimeRestricted('text/foo', ['text/bar'])
Expand All @@ -78,7 +78,7 @@ public function test_it_returns_a_415_for_restricted_type()
$this->assertHttpException($e, 415);
}

public function test_it_returns_a_415_for_restricted_extension()
public function test_it_returns_a_415_for_restricted_extension(): void
{
$e = (new SampleExceptionHandler())->render(
FileNotSupportedException::extensionRestricted('foo', ['bar'])
Expand All @@ -87,7 +87,7 @@ public function test_it_returns_a_415_for_restricted_extension()
$this->assertHttpException($e, 415);
}

public function test_it_returns_a_415_for_restricted_aggregate_type()
public function test_it_returns_a_415_for_restricted_aggregate_type(): void
{
$e = (new SampleExceptionHandler())->render(
FileNotSupportedException::aggregateTypeRestricted('foo', ['bar'])
Expand All @@ -96,7 +96,7 @@ public function test_it_returns_a_415_for_restricted_aggregate_type()
$this->assertHttpException($e, 415);
}

public function test_it_returns_a_500_for_other_exception_types()
public function test_it_returns_a_500_for_other_exception_types(): void
{
$e = (new SampleExceptionHandler())->render(
new ConfigurationException()
Expand All @@ -105,7 +105,7 @@ public function test_it_returns_a_500_for_other_exception_types()
$this->assertHttpException($e, 500);
}

public function test_it_skips_any_other_exception()
public function test_it_skips_any_other_exception(): void
{
$e = (new SampleExceptionHandler())->render(
new Exception()
Expand All @@ -114,7 +114,7 @@ public function test_it_skips_any_other_exception()
$this->assertFalse($e instanceof HttpException);
}

protected function assertHttpException($e, $code)
protected function assertHttpException($e, $code): void
{
$this->assertInstanceOf(HttpException::class, $e);
/** @var HttpException $e */
Expand Down
14 changes: 7 additions & 7 deletions tests/Integration/Helpers/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class FileTest extends TestCase
{
public function test_it_provides_a_cleaned_dirname()
public function test_it_provides_a_cleaned_dirname(): void
{
$this->assertEquals('', File::cleanDirname(''));
$this->assertEquals('', File::cleanDirname('/'));
Expand All @@ -16,43 +16,43 @@ public function test_it_provides_a_cleaned_dirname()
$this->assertEquals('foo/bar', File::cleanDirname('/foo/bar/baz.jpg'));
}

public function test_it_converts_bytes_to_readable_strings()
public function test_it_converts_bytes_to_readable_strings(): void
{
$this->assertEquals('0 B', File::readableSize(0));
$this->assertEquals('1 KB', File::readableSize(1025, 0));
$this->assertEquals('1.1 MB', File::readableSize(1024 * 1024 + 1024 * 100, 2));
}

public function test_it_guesses_the_extension_given_a_mime_type()
public function test_it_guesses_the_extension_given_a_mime_type(): void
{
$this->assertEquals('png', File::guessExtension('image/png'));
}

public function test_it_sanitizes_filenames()
public function test_it_sanitizes_filenames(): void
{
$this->assertEquals(
'hello-world-what-ss_new-with.you',
File::sanitizeFileName("héllo/world! \\ \t whàt\'ß_new with.you?", 'en')
);
}

public function test_it_sanitizes_filenames_with_locale()
public function test_it_sanitizes_filenames_with_locale(): void
{
$this->assertEquals(
'hello-world-what-sz_new-with.you',
File::sanitizeFileName("héllo/world! \\ \t whàt\'ß_new with.you?", 'de_at')
);
}

public function test_it_sanitizes_paths()
public function test_it_sanitizes_paths(): void
{
$this->assertEquals(
'hello/world-what-s_new-with.you',
File::sanitizePath("/héllo/world! \\ \t whàt\'ς_new with.you??")
);
}

public function test_it_joins_path_components()
public function test_it_joins_path_components(): void
{
$this->assertEquals('', File::joinPathComponents('', ''));
$this->assertEquals('foo', File::joinPathComponents('foo', ''));
Expand Down
Loading

0 comments on commit 660f127

Please sign in to comment.