From d7a621cf157d5156a8a1dcf6ee473997854ae084 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 14 Dec 2022 16:20:33 +0900 Subject: [PATCH 01/11] chore: add declare(strict_types=1) in rector.php --- rector.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 3693ab193..45666d734 100644 --- a/rector.php +++ b/rector.php @@ -1,5 +1,7 @@ sets([SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_74, PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, PHPUnitSetList::PHPUNIT_80]); + $rectorConfig->sets([ + SetList::DEAD_CODE, + LevelSetList::UP_TO_PHP_74, + PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, + PHPUnitSetList::PHPUNIT_80, + ]); + $rectorConfig->parallel(); + // The paths to refactor (can also be supplied with CLI arguments) $rectorConfig->paths([ __DIR__ . '/src/', From e646b54150ab564302df7412e60267106ca44ab1 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 14 Dec 2022 16:24:09 +0900 Subject: [PATCH 02/11] chore: remove deprecated TypedPropertyRector --- rector.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rector.php b/rector.php index 45666d734..6d154c21a 100644 --- a/rector.php +++ b/rector.php @@ -128,8 +128,4 @@ $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); $rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); - $rectorConfig - ->ruleWithConfiguration(TypedPropertyRector::class, [ - TypedPropertyRector::INLINE_PUBLIC => false, - ]); }; From 61a6e6b107c568483d0651cbb02736ede3e1e7b0 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 15 Dec 2022 09:12:39 +0900 Subject: [PATCH 03/11] chore: add rector.php to php-cs-fixer --- .php-cs-fixer.dist.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2446c56f6..5636649d5 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -13,7 +13,10 @@ __DIR__ . '/tests/', ]) ->exclude('build') - ->append([__FILE__]); + ->append([ + __FILE__, + __DIR__ . '/rector.php', + ]); $overrides = [ 'declare_strict_types' => true, From a0fe79d7f988ed64b2b7d9e2aa4f3821c2fb2dc7 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 15 Dec 2022 09:14:26 +0900 Subject: [PATCH 04/11] chore: update rector version --- .github/workflows/rector.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index a50424b12..20bccfe77 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -63,5 +63,5 @@ jobs: - name: Analyze for refactoring run: | - composer global require --dev rector/rector:^0.13.3 + composer global require --dev rector/rector:^0.15.1 rector process --dry-run --no-progress-bar From 7813e6803ef0e180f992bb40c75cc686e52f99bd Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 15 Dec 2022 09:19:20 +0900 Subject: [PATCH 05/11] chore: add rector rules From CodeIgniter4 repository. --- rector.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 6d154c21a..420d813eb 100644 --- a/rector.php +++ b/rector.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector; +use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector; use Rector\CodeQuality\Rector\For_\ForToForeachRector; use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector; @@ -32,8 +33,8 @@ use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector; use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; -use Rector\Php74\Rector\Property\TypedPropertyRector; use Rector\PHPUnit\Set\PHPUnitSetList; +use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; @@ -106,6 +107,9 @@ __DIR__ . '/src/Models/UserModel.php', ], ]); + // auto import fully qualified class names + $rectorConfig->importNames(); + $rectorConfig->rule(SimplifyUselessVariableRector::class); $rectorConfig->rule(RemoveAlwaysElseRector::class); $rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class); @@ -128,4 +132,7 @@ $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); $rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); + $rectorConfig->rule(StringClassNameToClassConstantRector::class); + $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); + $rectorConfig->rule(CompleteDynamicPropertiesRector::class); }; From e48867bcfd12cfdafb9823db6d9195f043263974 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 15 Dec 2022 09:21:04 +0900 Subject: [PATCH 06/11] test: remove unused property --- tests/Authorization/AuthorizableTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Authorization/AuthorizableTest.php b/tests/Authorization/AuthorizableTest.php index b1e42e051..7f8c2f502 100644 --- a/tests/Authorization/AuthorizableTest.php +++ b/tests/Authorization/AuthorizableTest.php @@ -23,14 +23,11 @@ final class AuthorizableTest extends TestCase protected $refresh = true; protected $namespace; - protected UserModel $model; protected function setUp(): void { parent::setUp(); - $this->model = new UserModel(); - // Refresh should take care of this.... db_connect()->table('auth_groups_users')->truncate(); db_connect()->table('auth_permissions_users')->truncate(); From 6668d6cbd233745ba8519610c7860f96c11fd75b Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 15 Dec 2022 09:23:28 +0900 Subject: [PATCH 07/11] test: run rector --- tests/Authentication/AuthenticationTest.php | 2 +- .../Authenticators/AccessTokenAuthenticatorTest.php | 2 +- .../Authenticators/SessionAuthenticatorTest.php | 4 ++-- tests/Authentication/Filters/AbstractFilterTest.php | 1 + tests/Authentication/HasAccessTokensTest.php | 2 +- tests/Unit/CompositionValidatorTest.php | 4 ++-- tests/Unit/DictionaryValidatorTest.php | 2 +- tests/Unit/NothingPersonalValidatorTest.php | 2 +- tests/Unit/PwnedValidatorTest.php | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/Authentication/AuthenticationTest.php b/tests/Authentication/AuthenticationTest.php index cfa55d880..58b92ce10 100644 --- a/tests/Authentication/AuthenticationTest.php +++ b/tests/Authentication/AuthenticationTest.php @@ -16,7 +16,7 @@ */ final class AuthenticationTest extends DatabaseTestCase { - protected Authentication $auth; + private Authentication $auth; protected function setUp(): void { diff --git a/tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php b/tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php index dd0f379ea..c829295dc 100644 --- a/tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php +++ b/tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php @@ -22,7 +22,7 @@ */ final class AccessTokenAuthenticatorTest extends DatabaseTestCase { - protected AccessTokens $auth; + private AccessTokens $auth; protected function setUp(): void { diff --git a/tests/Authentication/Authenticators/SessionAuthenticatorTest.php b/tests/Authentication/Authenticators/SessionAuthenticatorTest.php index bba1eed8a..e3d87d623 100644 --- a/tests/Authentication/Authenticators/SessionAuthenticatorTest.php +++ b/tests/Authentication/Authenticators/SessionAuthenticatorTest.php @@ -27,9 +27,9 @@ final class SessionAuthenticatorTest extends TestCase use DatabaseTestTrait; use FakeUser; - protected Session $auth; + private Session $auth; protected $namespace; - protected $events; + private MockEvents $events; protected function setUp(): void { diff --git a/tests/Authentication/Filters/AbstractFilterTest.php b/tests/Authentication/Filters/AbstractFilterTest.php index 3a1f97059..29c6f5f4b 100644 --- a/tests/Authentication/Filters/AbstractFilterTest.php +++ b/tests/Authentication/Filters/AbstractFilterTest.php @@ -18,6 +18,7 @@ abstract class AbstractFilterTest extends TestCase use FeatureTestTrait; use AuthenticationTesting; + protected string $routeFilter; protected $namespace; protected string $alias; protected string $classname; diff --git a/tests/Authentication/HasAccessTokensTest.php b/tests/Authentication/HasAccessTokensTest.php index 6d5880607..4d0025fe4 100644 --- a/tests/Authentication/HasAccessTokensTest.php +++ b/tests/Authentication/HasAccessTokensTest.php @@ -15,7 +15,7 @@ */ final class HasAccessTokensTest extends DatabaseTestCase { - protected User $user; + private User $user; protected function setUp(): void { diff --git a/tests/Unit/CompositionValidatorTest.php b/tests/Unit/CompositionValidatorTest.php index d1a9fbe1d..151475f62 100644 --- a/tests/Unit/CompositionValidatorTest.php +++ b/tests/Unit/CompositionValidatorTest.php @@ -14,8 +14,8 @@ */ final class CompositionValidatorTest extends TestCase { - protected CompositionValidator $validator; - protected Auth $config; + private CompositionValidator $validator; + private Auth $config; protected function setUp(): void { diff --git a/tests/Unit/DictionaryValidatorTest.php b/tests/Unit/DictionaryValidatorTest.php index 10b736adb..97fbf4072 100644 --- a/tests/Unit/DictionaryValidatorTest.php +++ b/tests/Unit/DictionaryValidatorTest.php @@ -13,7 +13,7 @@ */ final class DictionaryValidatorTest extends CIUnitTestCase { - protected DictionaryValidator $validator; + private DictionaryValidator $validator; protected function setUp(): void { diff --git a/tests/Unit/NothingPersonalValidatorTest.php b/tests/Unit/NothingPersonalValidatorTest.php index 0e588b6c7..1bef57ea7 100644 --- a/tests/Unit/NothingPersonalValidatorTest.php +++ b/tests/Unit/NothingPersonalValidatorTest.php @@ -14,7 +14,7 @@ */ final class NothingPersonalValidatorTest extends CIUnitTestCase { - protected NothingPersonalValidator $validator; + private NothingPersonalValidator $validator; protected function setUp(): void { diff --git a/tests/Unit/PwnedValidatorTest.php b/tests/Unit/PwnedValidatorTest.php index 9898feeb5..8c86706fb 100644 --- a/tests/Unit/PwnedValidatorTest.php +++ b/tests/Unit/PwnedValidatorTest.php @@ -18,7 +18,7 @@ */ final class PwnedValidatorTest extends CIUnitTestCase { - protected PwnedValidator $validator; + private PwnedValidator $validator; protected function setUp(): void { From 0561a63ccd8e7afddd620febe9911ff7fd783948 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 15 Dec 2022 10:05:13 +0900 Subject: [PATCH 08/11] chore: add rector rules From devkit. --- rector.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 420d813eb..38bfeb75b 100644 --- a/rector.php +++ b/rector.php @@ -38,13 +38,14 @@ use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; +use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->sets([ SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_74, PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, - PHPUnitSetList::PHPUNIT_80, + PHPUnitSetList::PHPUNIT_100, ]); $rectorConfig->parallel(); @@ -132,6 +133,11 @@ $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); $rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); + $rectorConfig + ->ruleWithConfiguration(TypedPropertyFromAssignsRector::class, [ + // Set to false if you use in libraries, or it does create breaking changes. + TypedPropertyFromAssignsRector::INLINE_PUBLIC => false, + ]); $rectorConfig->rule(StringClassNameToClassConstantRector::class); $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); $rectorConfig->rule(CompleteDynamicPropertiesRector::class); From 6dfb295eda336cdc7aa0cfdb1af6edbf1b89cd43 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 15 Dec 2022 10:30:50 +0900 Subject: [PATCH 09/11] chore: skip AnnotationWithValueToAttributeRector --- rector.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rector.php b/rector.php index 38bfeb75b..9c80d7d0f 100644 --- a/rector.php +++ b/rector.php @@ -33,6 +33,7 @@ use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector; use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; +use Rector\PHPUnit\Rector\Class_\AnnotationWithValueToAttributeRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector; @@ -85,6 +86,7 @@ // Note: requires php 8 RemoveUnusedPromotedPropertyRector::class, + AnnotationWithValueToAttributeRector::class, // Ignore tests that might make calls without a result RemoveEmptyMethodCallRector::class => [ From a319eb067ced1349cee35a98bebdd2338522a522 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 15 Dec 2022 10:32:30 +0900 Subject: [PATCH 10/11] test: run rector --- tests/Language/AbstractTranslationTestCase.php | 4 ++-- tests/Unit/FilterInCliTest.php | 2 +- tests/Unit/NothingPersonalValidatorTest.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Language/AbstractTranslationTestCase.php b/tests/Language/AbstractTranslationTestCase.php index c9f954a0d..ef768f884 100644 --- a/tests/Language/AbstractTranslationTestCase.php +++ b/tests/Language/AbstractTranslationTestCase.php @@ -305,12 +305,12 @@ final public function testAllConfiguredLanguageKeysAreInOrder(string $locale): v /** * @return string[][] */ - final public function localesProvider(): iterable + final public static function localesProvider(): iterable { $locale = self::$locales[static::class] ?? null; if (null === $locale) { - $this->fail('The locale code should be defined in the $locales property.'); + static::fail('The locale code should be defined in the $locales property.'); } return [$locale => [$locale]]; diff --git a/tests/Unit/FilterInCliTest.php b/tests/Unit/FilterInCliTest.php index fc5da2208..dd96fc09a 100644 --- a/tests/Unit/FilterInCliTest.php +++ b/tests/Unit/FilterInCliTest.php @@ -31,7 +31,7 @@ public function testWhenInCliDoNothing(FilterInterface $filter): void $filter->before($clirequest); } - public function filterProvider(): Generator + public static function filterProvider(): Generator { yield from [ [new AuthRates()], diff --git a/tests/Unit/NothingPersonalValidatorTest.php b/tests/Unit/NothingPersonalValidatorTest.php index 1bef57ea7..c1bc93c1f 100644 --- a/tests/Unit/NothingPersonalValidatorTest.php +++ b/tests/Unit/NothingPersonalValidatorTest.php @@ -180,7 +180,7 @@ public function testIsNotPersonalFalsePositivesCaughtByIsNotSimilar($password): $this->assertNotSame($isNotPersonal, $isNotSimilar); } - public function passwordProvider(): array + public static function passwordProvider(): array { return [ ['JoeTheCaptain'], @@ -225,7 +225,7 @@ public function testConfigPersonalFieldsValues($firstName, $lastName, $expected) $this->assertSame($expected, $result->isOK()); } - public function firstLastNameProvider() + public static function firstLastNameProvider() { return [ [ @@ -275,7 +275,7 @@ public function testMaxSimilarityZeroTurnsOffSimilarityCalculation($maxSimilarit $this->assertSame($expected, $result->isOK()); } - public function maxSimilarityProvider() + public static function maxSimilarityProvider() { return [ [ From 23c2527d029e70615dbc219afddbf189fa4670a4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 16 Dec 2022 17:13:33 +0900 Subject: [PATCH 11/11] chore: remove TypedPropertyFromAssignsRector config It is included in LevelSetList::UP_TO_PHP_74. --- rector.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/rector.php b/rector.php index 9c80d7d0f..4906a8213 100644 --- a/rector.php +++ b/rector.php @@ -39,7 +39,6 @@ use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; -use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->sets([ @@ -135,11 +134,6 @@ $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); $rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); - $rectorConfig - ->ruleWithConfiguration(TypedPropertyFromAssignsRector::class, [ - // Set to false if you use in libraries, or it does create breaking changes. - TypedPropertyFromAssignsRector::INLINE_PUBLIC => false, - ]); $rectorConfig->rule(StringClassNameToClassConstantRector::class); $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); $rectorConfig->rule(CompleteDynamicPropertiesRector::class);