From 2d4ee605c1edac15b01c6beea04c2b09bd5c65c3 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 17 Nov 2026 12:30:32 +0100 Subject: [PATCH] [Set] Remove deprecated SetList::EARLY_RETURN, INSTANCEOF and IF constants --- config/set/early-return.php | 10 ---------- config/set/if.php | 10 ---------- config/set/instanceof.php | 10 ---------- src/Configuration/Option.php | 5 +++++ .../Parameter/SimpleParameterProvider.php | 1 + src/Configuration/RectorConfigBuilder.php | 20 +++++++++++++------ src/Console/Command/ProcessCommand.php | 1 + src/Console/Command/ValidateConfigCommand.php | 1 + src/Reporting/DeprecatedRulesReporter.php | 19 ++++++++++++++++++ src/Set/ValueObject/SetList.php | 15 -------------- .../Command/ValidateConfigCommandTest.php | 9 +++++++++ 11 files changed, 50 insertions(+), 51 deletions(-) delete mode 100644 config/set/early-return.php delete mode 100644 config/set/if.php delete mode 100644 config/set/instanceof.php diff --git a/config/set/early-return.php b/config/set/early-return.php deleted file mode 100644 index 4d7a1077583..00000000000 --- a/config/set/early-return.php +++ /dev/null @@ -1,10 +0,0 @@ -rules([]); -}; diff --git a/config/set/if.php b/config/set/if.php deleted file mode 100644 index 2faf066c142..00000000000 --- a/config/set/if.php +++ /dev/null @@ -1,10 +0,0 @@ -rules([]); -}; diff --git a/config/set/instanceof.php b/config/set/instanceof.php deleted file mode 100644 index bdd7eb6f575..00000000000 --- a/config/set/instanceof.php +++ /dev/null @@ -1,10 +0,0 @@ -rules([]); -}; diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index 82000e10f74..65b8e438eb3 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -228,6 +228,11 @@ final class Option */ public const string DEPRECATED_COMPOSER_BASED_ARGS = 'deprecated_composer_based_args'; + /** + * @internal For reporting deprecated withPreparedSets() arguments + */ + public const string DEPRECATED_PREPARED_SETS_ARGS = 'deprecated_prepared_sets_args'; + /** * @internal For collect skipped start with short open tag files to be reported */ diff --git a/src/Configuration/Parameter/SimpleParameterProvider.php b/src/Configuration/Parameter/SimpleParameterProvider.php index 6a7203d0d9f..2f9e0df167e 100644 --- a/src/Configuration/Parameter/SimpleParameterProvider.php +++ b/src/Configuration/Parameter/SimpleParameterProvider.php @@ -39,6 +39,7 @@ final class SimpleParameterProvider Option::SKIPPED_START_WITH_SHORT_OPEN_TAG_FILES, Option::DEPRECATED_ATTRIBUTES_SETS_ARGS, Option::DEPRECATED_COMPOSER_BASED_ARGS, + Option::DEPRECATED_PREPARED_SETS_ARGS, Option::LEVEL_OVERFLOWS, Option::COMPOSER_BOUND_RULE_CONFIGURATIONS, Option::ROOT_STANDALONE_REGISTERED_RULES, diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index e5f8dba9e88..ed68e724d4d 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -604,9 +604,9 @@ public function withPhpSets( /** * @param bool $naming @deprecated The naming set often causes conflicting variable and param names; use a coding standard tool instead - * @param bool $instanceOf @deprecated Use $codeQuality instead, as most instanceof rules were moved there - * @param bool $if @deprecated Use $codeQuality and $codingStyle instead, as the if rules were moved there or deprecated - * @param bool $earlyReturn @deprecated Use $codeQuality instead, as all early return rules were moved there + * @param bool $instanceOf @deprecated No longer applied, use $codeQuality instead, as most instanceof rules were moved there + * @param bool $if @deprecated No longer applied, use $codeQuality and $codingStyle instead, as the if rules were moved there or deprecated + * @param bool $earlyReturn @deprecated No longer applied, use $codeQuality instead, as all early return rules were moved there */ public function withPreparedSets( bool $deadCode = false, @@ -635,6 +635,17 @@ public function withPreparedSets( Notifier::notifyDeprecatedNamingSet(); } + $deprecatedArgs = [ + 'instanceOf' => $instanceOf, + 'if' => $if, + 'earlyReturn' => $earlyReturn, + ]; + foreach ($deprecatedArgs as $deprecatedArgName => $isEnabled) { + if ($isEnabled) { + SimpleParameterProvider::addParameter(Option::DEPRECATED_PREPARED_SETS_ARGS, $deprecatedArgName); + } + } + $setMap = [ SetList::DEAD_CODE => $deadCode, SetList::CODE_QUALITY => $codeQuality, @@ -644,9 +655,6 @@ public function withPreparedSets( SetList::PRIVATIZATION => $privatization, SetList::NAMING => $naming, SetList::NAMED_ARGS => $namedArgs, - SetList::INSTANCEOF => $instanceOf, - SetList::IF => $if, - SetList::EARLY_RETURN => $earlyReturn, SetList::CARBON => $carbon, SetList::RECTOR_PRESET => $rectorPreset, PHPUnitSetList::PHPUNIT_CODE_QUALITY => $phpunitCodeQuality, diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 00a5c1b52f6..023379c3d1f 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -187,6 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->deprecatedRulesReporter->reportDeprecatedSkippedRules(); $this->deprecatedRulesReporter->reportDeprecatedAttributesSetsArgs(); $this->deprecatedRulesReporter->reportDeprecatedComposerBasedArgs(); + $this->deprecatedRulesReporter->reportDeprecatedPreparedSetsArgs(); $this->missConfigurationReporter->reportSkippedNeverRegisteredRules(); $this->missConfigurationReporter->reportSkippedNonRectorClasses(); diff --git a/src/Console/Command/ValidateConfigCommand.php b/src/Console/Command/ValidateConfigCommand.php index 66fe3d548eb..164d414816f 100644 --- a/src/Console/Command/ValidateConfigCommand.php +++ b/src/Console/Command/ValidateConfigCommand.php @@ -61,6 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $issueCount += $this->deprecatedRulesReporter->reportDeprecatedSkippedRules(); $issueCount += $this->deprecatedRulesReporter->reportDeprecatedAttributesSetsArgs(); $issueCount += $this->deprecatedRulesReporter->reportDeprecatedComposerBasedArgs(); + $issueCount += $this->deprecatedRulesReporter->reportDeprecatedPreparedSetsArgs(); $issueCount += $this->missConfigurationReporter->reportSkippedNeverRegisteredRules(); $issueCount += $this->missConfigurationReporter->reportSkippedNonRectorClasses(); diff --git a/src/Reporting/DeprecatedRulesReporter.php b/src/Reporting/DeprecatedRulesReporter.php index 373c20f1295..054c995b603 100644 --- a/src/Reporting/DeprecatedRulesReporter.php +++ b/src/Reporting/DeprecatedRulesReporter.php @@ -94,4 +94,23 @@ public function reportDeprecatedComposerBasedArgs(): int return $reportedCount; } + + public function reportDeprecatedPreparedSetsArgs(): int + { + /** @var string[] $deprecatedPreparedSetsArgs */ + $deprecatedPreparedSetsArgs = SimpleParameterProvider::provideArrayParameter( + Option::DEPRECATED_PREPARED_SETS_ARGS + ); + + $reportedCount = 0; + foreach (array_unique($deprecatedPreparedSetsArgs) as $deprecatedPreparedSetsArg) { + $this->symfonyStyle->warning(sprintf( + 'The "->withPreparedSets(%s: true)" argument is deprecated and no longer applied. Its rules were moved to the "codeQuality" and "codingStyle" sets, use them instead.', + $deprecatedPreparedSetsArg + )); + ++$reportedCount; + } + + return $reportedCount; + } } diff --git a/src/Set/ValueObject/SetList.php b/src/Set/ValueObject/SetList.php index cce352d9877..93617bafe7c 100644 --- a/src/Set/ValueObject/SetList.php +++ b/src/Set/ValueObject/SetList.php @@ -35,21 +35,6 @@ final class SetList public const string TYPE_DECLARATION_DOCBLOCKS = __DIR__ . '/../../../config/set/type-declaration-docblocks.php'; - /** - * @deprecated Use code-quality set instead, as all early return rules were moved there - */ - public const string EARLY_RETURN = __DIR__ . '/../../../config/set/early-return.php'; - - /** - * @deprecated Use code-quality set instead, as most instanceof rules were moved there - */ - public const string INSTANCEOF = __DIR__ . '/../../../config/set/instanceof.php'; - - /** - * @deprecated Use code-quality and coding-style sets instead, as the if rules were moved there or deprecated - */ - public const string IF = __DIR__ . '/../../../config/set/if.php'; - public const string CARBON = __DIR__ . '/../../../config/set/datetime-to-carbon.php'; public const string BEHAT_ANNOTATIONS_TO_ATTRIBUTES = __DIR__ . '/../../../config/set/behat-annotations-to-attributes.php'; diff --git a/tests/Console/Command/ValidateConfigCommandTest.php b/tests/Console/Command/ValidateConfigCommandTest.php index 00e534c1233..897c3d6ea85 100644 --- a/tests/Console/Command/ValidateConfigCommandTest.php +++ b/tests/Console/Command/ValidateConfigCommandTest.php @@ -39,6 +39,7 @@ protected function setUp(): void Option::SKIPPED_START_WITH_SHORT_OPEN_TAG_FILES, Option::DEPRECATED_ATTRIBUTES_SETS_ARGS, Option::DEPRECATED_COMPOSER_BASED_ARGS, + Option::DEPRECATED_PREPARED_SETS_ARGS, Option::ROOT_STANDALONE_REGISTERED_RULES, Option::SET_REGISTERED_RULES, ] as $optionName) { @@ -74,6 +75,14 @@ public function testFailsOnDeprecatedRegisteredRule(): void $this->assertSame(ExitCode::FAILURE, $this->commandTester->execute([])); } + public function testFailsOnDeprecatedPreparedSetsArg(): void + { + SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, [OrdSingleByteRector::class]); + SimpleParameterProvider::setParameter(Option::DEPRECATED_PREPARED_SETS_ARGS, ['earlyReturn']); + + $this->assertSame(ExitCode::FAILURE, $this->commandTester->execute([])); + } + public function testSucceedsOnCleanConfig(): void { SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, [OrdSingleByteRector::class]);