diff --git a/composer.json b/composer.json index b78fc51a3c2..c0fe173f500 100644 --- a/composer.json +++ b/composer.json @@ -57,9 +57,7 @@ "webmozart/assert": "^1.9" }, "require-dev": { - "cweagans/composer-patches": "^1.7", "friendsofphp/php-cs-fixer": "^2.16", - "migrify/vendor-patches": "^0.3.49", "nette/application": "^3.0", "nette/di": "^3.0", "nette/forms": "^3.0", @@ -346,12 +344,5 @@ "config": { "sort-packages": true, "process-timeout": 0 - }, - "extra": { - "patches": { - "symplify/monorepo-builder": [ - "patches/symplify-monorepo-builder-packages-split-src-packagetorepositorysplitter-php.patch" - ] - } } } diff --git a/config/set/code-quality.php b/config/set/code-quality.php index 3545b6f8c54..cff274b221b 100644 --- a/config/set/code-quality.php +++ b/config/set/code-quality.php @@ -55,6 +55,7 @@ use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector use Rector\CodeQuality\Rector\LogicalAnd\AndAssignsToSeparateLinesRector; use Rector\CodeQuality\Rector\LogicalAnd\LogicalToBooleanRector; use Rector\CodeQuality\Rector\Name\FixClassCaseSensitivityNameRector; +use Rector\CodeQuality\Rector\New_\NewStaticToNewSelfRector; use Rector\CodeQuality\Rector\NotEqual\CommonNotEqualRector; use Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector; use Rector\CodeQuality\Rector\Ternary\ArrayKeyExistsTernaryThenValueToCoalescingRector; @@ -69,157 +70,94 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura return static function (ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); - $services->set(CombinedAssignRector::class); - $services->set(SimplifyEmptyArrayCheckRector::class); - $services->set(ForeachToInArrayRector::class); - $services->set(SimplifyForeachToCoalescingRector::class); - $services->set(InArrayAndArrayKeysToArrayKeyExistsRector::class); - $services->set(SimplifyFuncGetArgsCountRector::class); - $services->set(SimplifyInArrayValuesRector::class); - $services->set(SimplifyStrposLowerRector::class); - $services->set(GetClassToInstanceOfRector::class); - $services->set(SimplifyArraySearchRector::class); - $services->set(SimplifyConditionsRector::class); - $services->set(SimplifyIfNotNullReturnRector::class); - $services->set(SimplifyIfReturnBoolRector::class); - $services->set(SimplifyUselessVariableRector::class); - $services->set(UnnecessaryTernaryExpressionRector::class); - $services->set(RemoveExtraParametersRector::class); - $services->set(SimplifyDeMorganBinaryRector::class); - $services->set(SimplifyTautologyTernaryRector::class); - $services->set(SimplifyForeachToArrayFilterRector::class); - $services->set(SingleInArrayToCompareRector::class); - $services->set(SimplifyIfElseToTernaryRector::class); - $services->set(JoinStringConcatRector::class); - $services->set(ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class); - $services->set(SimplifyIfIssetToNullCoalescingRector::class); - $services->set(ExplicitBoolCompareRector::class); - $services->set(CombineIfRector::class); - $services->set(UseIdenticalOverEqualWithSameTypeRector::class); - $services->set(SimplifyDuplicatedTernaryRector::class); - $services->set(SimplifyBoolIdenticalTrueRector::class); - $services->set(SimplifyRegexPatternRector::class); - $services->set(BooleanNotIdenticalToNotIdenticalRector::class); - $services->set(CallableThisArrayToAnonymousFunctionRector::class); - $services->set(AndAssignsToSeparateLinesRector::class); - $services->set(ForToForeachRector::class); - $services->set(CompactToVariablesRector::class); - $services->set(CompleteDynamicPropertiesRector::class); - $services->set(IsAWithStringWithThirdArgumentRector::class); - $services->set(StrlenZeroToIdenticalEmptyStringRector::class); - $services->set(RemoveAlwaysTrueConditionSetInConstructorRector::class); - $services->set(ThrowWithPreviousExceptionRector::class); - $services->set(RemoveSoleValueSprintfRector::class); - $services->set(ShortenElseIfRector::class); - $services->set(UseInterfaceOverImplementationInConstructorRector::class); - $services->set(AddPregQuoteDelimiterRector::class); - $services->set(ArrayMergeOfNonArraysToSimpleArrayRector::class); - $services->set(IntvalToTypeCastRector::class); - $services->set(ArrayKeyExistsTernaryThenValueToCoalescingRector::class); - $services->set(AbsolutizeRequireAndIncludePathRector::class); - $services->set(ChangeArrayPushToArrayAssignRector::class); - $services->set(ForRepeatedCountToOwnVariableRector::class); - $services->set(ForeachItemsAssignToEmptyArrayToAssignRector::class); - $services->set(InlineIfToExplicitIfRector::class); - $services->set(ArrayKeysAndInArrayToArrayKeyExistsRector::class); - $services->set(SplitListAssignToSeparateLineRector::class); - $services->set(UnusedForeachValueToArrayKeysRector::class); - $services->set(ArrayThisCallToThisMethodCallRector::class); - $services->set(CommonNotEqualRector::class); - - $services->set(RenameFunctionRector::class) - ->call('configure', [[ - RenameFunctionRector::OLD_FUNCTION_TO_NEW_FUNCTION => [ - 'split' => 'explode', - 'join' => 'implode', - 'sizeof' => 'count', - # https://www.php.net/manual/en/aliases.php - 'chop' => 'rtrim', - 'doubleval' => 'floatval', - 'gzputs' => 'gzwrites', - 'fputs' => 'fwrite', - 'ini_alter' => 'ini_set', - 'is_double' => 'is_float', - 'is_integer' => 'is_int', - 'is_long' => 'is_int', - 'is_real' => 'is_float', - 'is_writeable' => 'is_writable', - 'key_exists' => 'array_key_exists', - 'pos' => 'current', - 'strchr' => 'strstr', - # mb - 'mbstrcut' => 'mb_strcut', - 'mbstrlen' => 'mb_strlen', - 'mbstrpos' => 'mb_strpos', - 'mbstrrpos' => 'mb_strrpos', - 'mbsubstr' => 'mb_substr', - ], - ]]); - + $services->set(RenameFunctionRector::class)->call('configure', [[ + RenameFunctionRector::OLD_FUNCTION_TO_NEW_FUNCTION => [ + 'split' => 'explode', + 'join' => 'implode', + 'sizeof' => 'count', + # https://www.php.net/manual/en/aliases.php + 'chop' => 'rtrim', + 'doubleval' => 'floatval', + 'gzputs' => 'gzwrites', + 'fputs' => 'fwrite', + 'ini_alter' => 'ini_set', + 'is_double' => 'is_float', + 'is_integer' => 'is_int', + 'is_long' => 'is_int', + 'is_real' => 'is_float', + 'is_writeable' => 'is_writable', + 'key_exists' => 'array_key_exists', + 'pos' => 'current', + 'strchr' => 'strstr', + # mb + 'mbstrcut' => 'mb_strcut', + 'mbstrlen' => 'mb_strlen', + 'mbstrpos' => 'mb_strpos', + 'mbstrrpos' => 'mb_strrpos', + 'mbsubstr' => 'mb_substr', + ], + ]]); $services->set(SetTypeToCastRector::class); - $services->set(LogicalToBooleanRector::class); - $services->set(VarToPublicPropertyRector::class); - $services->set(FixClassCaseSensitivityNameRector::class); - $services->set(IssetOnPropertyObjectToPropertyExistsRector::class); + $services->set(NewStaticToNewSelfRector::class); }; diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index 5d808155767..74c2d1f4b4c 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# All 595 Rectors Overview +# All 596 Rectors Overview - [Projects](#projects) --- @@ -8,7 +8,7 @@ - [Architecture](#architecture) (2) - [Autodiscovery](#autodiscovery) (4) - [CakePHP](#cakephp) (6) -- [CodeQuality](#codequality) (59) +- [CodeQuality](#codequality) (60) - [CodingStyle](#codingstyle) (33) - [DeadCode](#deadcode) (41) - [Decouple](#decouple) (1) @@ -941,11 +941,12 @@ Change `foreach()` items assign to empty array to direct assign { public function run($items) { - $items2 = []; + $collectedItems = []; + - foreach ($items as $item) { -- $items2[] = $item; +- $collectedItems[] = $item; - } -+ $items2 = $items; ++ $collectedItems = $items; } } ``` @@ -1122,6 +1123,26 @@ Change OR, AND to ||, && with more common understanding

+### `NewStaticToNewSelfRector` + +- class: [`Rector\CodeQuality\Rector\New_\NewStaticToNewSelfRector`](/rules/code-quality/src/Rector/New_/NewStaticToNewSelfRector.php) +- [test fixtures](/rules/code-quality/tests/Rector/New_/NewStaticToNewSelfRector/Fixture) + +Change unsafe new `static()` to new `self()` + +```diff + class SomeClass + { + public function build() + { +- return new static(); ++ return new self(); + } + } +``` + +

+ ### `RemoveAlwaysTrueConditionSetInConstructorRector` - class: [`Rector\CodeQuality\Rector\FunctionLike\RemoveAlwaysTrueConditionSetInConstructorRector`](/rules/code-quality/src/Rector/FunctionLike/RemoveAlwaysTrueConditionSetInConstructorRector.php) diff --git a/patches/symplify-monorepo-builder-packages-split-src-packagetorepositorysplitter-php.patch b/patches/symplify-monorepo-builder-packages-split-src-packagetorepositorysplitter-php.patch deleted file mode 100644 index 40d5e213a68..00000000000 --- a/patches/symplify-monorepo-builder-packages-split-src-packagetorepositorysplitter-php.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- /dev/null -+++ ../packages/split/src/PackageToRepositorySplitter.php -@@ -80,7 +80,7 @@ - $this->symfonyStyle->warning($message); - } - -- $tag = $this->gitManager->getMostRecentTag($rootDirectory); -+ // $tag = $this->gitManager->getMostRecentTag($rootDirectory); - } - - // If branch not set, default to current branch -@@ -87,7 +87,7 @@ - $branch = $branch ?? $this->gitManager->getCurrentBranch(); - - // If branch doesn't exist on origin, push it -- if (! $this->gitManager->doesBranchExistOnRemote($branch)) { -+ if (! $this->gitManager->doesBranchExistOnRemote($branch) && $tag === null) { - $missingBranchMessage = sprintf('Branch "%s" does not exist on origin, pushing it...', $branch); - $this->symfonyStyle->note($missingBranchMessage); - $this->symfonyStyle->writeln($this->gitManager->pushBranchToRemoteOrigin($branch)); diff --git a/rules/code-quality/src/Rector/New_/NewStaticToNewSelfRector.php b/rules/code-quality/src/Rector/New_/NewStaticToNewSelfRector.php new file mode 100644 index 00000000000..df6bb6b7416 --- /dev/null +++ b/rules/code-quality/src/Rector/New_/NewStaticToNewSelfRector.php @@ -0,0 +1,82 @@ +getAttribute(AttributeKey::CLASS_NODE); + if (! $class instanceof Class_) { + return null; + } + + if (! $class->isFinal()) { + return null; + } + + if (! $this->isName($node->class, 'static')) { + return null; + } + + $node->class = new Name('self'); + + return $node; + } +} diff --git a/rules/code-quality/tests/Rector/New_/NewStaticToNewSelfRector/Fixture/fixture.php.inc b/rules/code-quality/tests/Rector/New_/NewStaticToNewSelfRector/Fixture/fixture.php.inc new file mode 100644 index 00000000000..7c3f11c76b3 --- /dev/null +++ b/rules/code-quality/tests/Rector/New_/NewStaticToNewSelfRector/Fixture/fixture.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules/code-quality/tests/Rector/New_/NewStaticToNewSelfRector/Fixture/skip_non_final.php.inc b/rules/code-quality/tests/Rector/New_/NewStaticToNewSelfRector/Fixture/skip_non_final.php.inc new file mode 100644 index 00000000000..cbb97f66857 --- /dev/null +++ b/rules/code-quality/tests/Rector/New_/NewStaticToNewSelfRector/Fixture/skip_non_final.php.inc @@ -0,0 +1,11 @@ +doTestFileInfo($fileInfo); + } + + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return NewStaticToNewSelfRector::class; + } +}