From f1f7c12fbb9007b82f7f8f527a4013a9dbd7872b Mon Sep 17 00:00:00 2001 From: Daniel Jakob Date: Tue, 13 Feb 2024 19:30:57 +0100 Subject: [PATCH] Enforce some more rector rules --- composer.lock | 64 +++++++++---------- rector.php | 11 +++- src/Api/Search/SearchApplication.php | 7 +- src/Component/Io/Lib/PopenWrapper.php | 2 +- .../Io/Transcoder/TranscodingHandler.php | 6 +- src/Component/Tag/Container/AudioFile.php | 22 +++---- tests/Api/Common/LogoutApplicationTest.php | 2 +- tests/Bootstrap/InitTest.php | 2 +- 8 files changed, 63 insertions(+), 53 deletions(-) diff --git a/composer.lock b/composer.lock index a0018ad..e0ccb21 100644 --- a/composer.lock +++ b/composer.lock @@ -1605,16 +1605,16 @@ }, { "name": "illuminate/collections", - "version": "v10.43.0", + "version": "v10.44.0", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", - "reference": "221c1ee944cb20ed807a8a5e8668552d6ca736ff" + "reference": "5cedaba39e331cffd73a01cf27ea83229fa11fba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/221c1ee944cb20ed807a8a5e8668552d6ca736ff", - "reference": "221c1ee944cb20ed807a8a5e8668552d6ca736ff", + "url": "https://api.github.com/repos/illuminate/collections/zipball/5cedaba39e331cffd73a01cf27ea83229fa11fba", + "reference": "5cedaba39e331cffd73a01cf27ea83229fa11fba", "shasum": "" }, "require": { @@ -1656,11 +1656,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-01-22T13:55:20+00:00" + "time": "2024-02-09T15:56:19+00:00" }, { "name": "illuminate/conditionable", - "version": "v10.43.0", + "version": "v10.44.0", "source": { "type": "git", "url": "https://github.com/illuminate/conditionable.git", @@ -1706,7 +1706,7 @@ }, { "name": "illuminate/contracts", - "version": "v10.43.0", + "version": "v10.44.0", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", @@ -1754,7 +1754,7 @@ }, { "name": "illuminate/macroable", - "version": "v10.43.0", + "version": "v10.44.0", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -1800,16 +1800,16 @@ }, { "name": "illuminate/support", - "version": "v10.43.0", + "version": "v10.44.0", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "6edb9350a0d13be5cea52718280e0025d3957895" + "reference": "d757670dcd91b0125d0f3ab82a38cc2ad39d2acf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/6edb9350a0d13be5cea52718280e0025d3957895", - "reference": "6edb9350a0d13be5cea52718280e0025d3957895", + "url": "https://api.github.com/repos/illuminate/support/zipball/d757670dcd91b0125d0f3ab82a38cc2ad39d2acf", + "reference": "d757670dcd91b0125d0f3ab82a38cc2ad39d2acf", "shasum": "" }, "require": { @@ -1867,7 +1867,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-01-29T14:56:21+00:00" + "time": "2024-02-13T14:50:39+00:00" }, { "name": "intervention/image", @@ -2064,16 +2064,16 @@ }, { "name": "laravel/pint", - "version": "v1.13.10", + "version": "v1.13.11", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "e2b5060885694ca30ac008c05dc9d47f10ed1abf" + "reference": "60a163c3e7e3346a1dec96d3e6f02e6465452552" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/e2b5060885694ca30ac008c05dc9d47f10ed1abf", - "reference": "e2b5060885694ca30ac008c05dc9d47f10ed1abf", + "url": "https://api.github.com/repos/laravel/pint/zipball/60a163c3e7e3346a1dec96d3e6f02e6465452552", + "reference": "60a163c3e7e3346a1dec96d3e6f02e6465452552", "shasum": "" }, "require": { @@ -2084,13 +2084,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.47.1", - "illuminate/view": "^10.41.0", + "friendsofphp/php-cs-fixer": "^3.49.0", + "illuminate/view": "^10.43.0", "larastan/larastan": "^2.8.1", "laravel-zero/framework": "^10.3.0", "mockery/mockery": "^1.6.7", "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.31.0" + "pestphp/pest": "^2.33.6" }, "bin": [ "builds/pint" @@ -2126,7 +2126,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-01-22T09:04:15+00:00" + "time": "2024-02-13T17:20:13+00:00" }, { "name": "laravel/serializable-closure", @@ -6813,16 +6813,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.57", + "version": "1.10.58", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e" + "reference": "a23518379ec4defd9e47cbf81019526861623ec2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1627b1d03446904aaa77593f370c5201d2ecc34e", - "reference": "1627b1d03446904aaa77593f370c5201d2ecc34e", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a23518379ec4defd9e47cbf81019526861623ec2", + "reference": "a23518379ec4defd9e47cbf81019526861623ec2", "shasum": "" }, "require": { @@ -6871,20 +6871,20 @@ "type": "tidelift" } ], - "time": "2024-01-24T11:51:34+00:00" + "time": "2024-02-12T20:02:57+00:00" }, { "name": "phpstan/phpstan-doctrine", - "version": "1.3.61", + "version": "1.3.62", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-doctrine.git", - "reference": "f3f1dae3551ce4b10f5e2fb2c24e3004e6c34fe1" + "reference": "f3abbd8e93e12fed8091be3aeec216b06bed0950" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/f3f1dae3551ce4b10f5e2fb2c24e3004e6c34fe1", - "reference": "f3f1dae3551ce4b10f5e2fb2c24e3004e6c34fe1", + "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/f3abbd8e93e12fed8091be3aeec216b06bed0950", + "reference": "f3abbd8e93e12fed8091be3aeec216b06bed0950", "shasum": "" }, "require": { @@ -6941,9 +6941,9 @@ "description": "Doctrine extensions for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-doctrine/issues", - "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.3.61" + "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.3.62" }, - "time": "2024-02-09T13:43:08+00:00" + "time": "2024-02-12T11:52:17+00:00" }, { "name": "phpstan/phpstan-mockery", diff --git a/rector.php b/rector.php index 0bd0a30..d92612e 100644 --- a/rector.php +++ b/rector.php @@ -10,7 +10,16 @@ return RectorConfig::configure() ->withImportNames() ->withPhpSets(php82: true) - ->withPreparedSets(deadCode: true, codeQuality: true, codingStyle: true) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + instanceOf: true, + earlyReturn: true, + strictBooleans: true + ) ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', diff --git a/src/Api/Search/SearchApplication.php b/src/Api/Search/SearchApplication.php index aa3feea..8c59d1a 100644 --- a/src/Api/Search/SearchApplication.php +++ b/src/Api/Search/SearchApplication.php @@ -4,6 +4,7 @@ namespace Uxmp\Core\Api\Search; +use JsonSerializable; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Uxmp\Core\Api\AbstractApiApplication; @@ -53,19 +54,19 @@ protected function run( 'items' => [ 'albums' => array_values( array_map( - fn (AlbumInterface $album) => $this->resultItemFactory->createAlbumListItem($album), + fn (AlbumInterface $album): JsonSerializable => $this->resultItemFactory->createAlbumListItem($album), $this->albumRepository->search($searchTerm) ) ), 'artists' => array_values( array_map( - fn (ArtistInterface $artist) => $this->resultItemFactory->createArtistListItem($artist), + fn (ArtistInterface $artist): JsonSerializable => $this->resultItemFactory->createArtistListItem($artist), $this->artistRepository->search($searchTerm) ) ), 'songs' => array_values( array_map( - fn (SongInterface $song) => $this->resultItemFactory->createSongListItem($song, $song->getAlbum()), + fn (SongInterface $song): JsonSerializable => $this->resultItemFactory->createSongListItem($song, $song->getAlbum()), $this->songRepository->search($searchTerm) ) ), diff --git a/src/Component/Io/Lib/PopenWrapper.php b/src/Component/Io/Lib/PopenWrapper.php index 367cb46..47e3efb 100644 --- a/src/Component/Io/Lib/PopenWrapper.php +++ b/src/Component/Io/Lib/PopenWrapper.php @@ -28,7 +28,7 @@ public function run(string $command): mixed return null; } - register_shutdown_function(static fn () => fclose($handle)); + register_shutdown_function(static fn (): bool => fclose($handle)); return $handle; } diff --git a/src/Component/Io/Transcoder/TranscodingHandler.php b/src/Component/Io/Transcoder/TranscodingHandler.php index 4386a32..19905d7 100644 --- a/src/Component/Io/Transcoder/TranscodingHandler.php +++ b/src/Component/Io/Transcoder/TranscodingHandler.php @@ -38,10 +38,10 @@ public function __invoke(int $length): string } return $chunk; - } else { - // return only null (if the content length is greater than the actual size) - return str_repeat("\0", $length); } + + // return only null (if the content length is greater than the actual size) + return str_repeat("\0", $length); } private function read(int $length): string diff --git a/src/Component/Tag/Container/AudioFile.php b/src/Component/Tag/Container/AudioFile.php index caa650d..c8777fb 100644 --- a/src/Component/Tag/Container/AudioFile.php +++ b/src/Component/Tag/Container/AudioFile.php @@ -83,7 +83,7 @@ public function setTitle(string $title): AudioFileInterface public function getTitleClean(): string { - return $this->stringHelper->filterForSearch($this->getTitle()); + return $this->stringHelper->filterForSearch($this->title); } public function getMbid(): string @@ -110,7 +110,7 @@ public function setArtistTitle(string $artistTitle): AudioFileInterface public function getArtistTitleClean(): string { - return $this->stringHelper->filterForSearch($this->getArtistTitle()); + return $this->stringHelper->filterForSearch($this->artistTitle); } public function getArtistMbid(): string @@ -138,7 +138,7 @@ public function setAlbumTitle(string $albumTitle): AudioFileInterface public function getAlbumTitleClean(): string { return $this->stringHelper->filterForSearch( - $this->getAlbumTitle() + $this->albumTitle ); } @@ -268,15 +268,15 @@ public function setLength(int $length): AudioFileInterface public function apply(SongInterface $song): void { $song - ->setTitle($this->getTitle()) + ->setTitle($this->title) ->setSearchTitle($this->getTitleClean()) - ->setTrackNumber($this->getTrackNumber()) - ->setFilename($this->getFilename()) - ->setMbid($this->getMbid()) - ->setLength($this->getLength()) - ->setYear($this->getYear()) - ->setMimeType($this->getMimeType()) - ->setFileSize($this->getFileSize()) + ->setTrackNumber($this->trackNumber) + ->setFilename($this->filename) + ->setMbid($this->mbid) + ->setLength($this->length) + ->setYear($this->year) + ->setMimeType($this->mimeType) + ->setFileSize($this->fileSize) ; } } diff --git a/tests/Api/Common/LogoutApplicationTest.php b/tests/Api/Common/LogoutApplicationTest.php index 6ac2c97..0732d80 100644 --- a/tests/Api/Common/LogoutApplicationTest.php +++ b/tests/Api/Common/LogoutApplicationTest.php @@ -65,7 +65,7 @@ public function testRunPerformsLogout(): void $response->shouldReceive('withHeader') ->with( 'Set-Cookie', - Mockery::on(static fn ($value) => str_starts_with( + Mockery::on(static fn ($value): bool => str_starts_with( (string) $value, sprintf( '%s=; path=%s/play; Expires=', diff --git a/tests/Bootstrap/InitTest.php b/tests/Bootstrap/InitTest.php index 6ef5a49..df0720c 100644 --- a/tests/Bootstrap/InitTest.php +++ b/tests/Bootstrap/InitTest.php @@ -14,7 +14,7 @@ public function testRunRuns(): void $this->assertSame( $foo, - Init::run(static fn () => $foo), + Init::run(static fn (): string => $foo), ); } }