From c4e4d1068856ea4efc13719d1ac7e0644707eaf3 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 31 Jul 2026 22:48:20 +0200 Subject: [PATCH] [Configuration] Deprecate withPhp53Sets() ... withPhp74Sets(), suggest withPhpLevel() These 9 methods existed only as a PHP 7.4-compatible workaround for withPhpSets(), which uses named arguments. withPhpLevel() covers the same need with a positional argument and raises the PHP level one rule at a time. The methods are kept and marked @deprecated, they only report a warning. The sets themselves are no longer added. --- src/Configuration/Option.php | 5 +++ src/Configuration/RectorConfigBuilder.php | 38 +++++++++++++++-------- src/Console/Command/ProcessCommand.php | 1 + src/Console/Notifier.php | 2 +- src/Reporting/DeprecatedRulesReporter.php | 15 +++++++++ 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index ee2f0679c74..ee05a0314ab 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -237,6 +237,11 @@ final class Option */ public const string CACHE_META_EXTENSIONS = 'cache_meta_extensions'; + /** + * @internal For reporting deprecated withPhp53Sets() ... withPhp74Sets() methods + */ + public const string DEPRECATED_PHP_SETS_METHODS = 'deprecated_php_sets_methods'; + /** * @internal For collect skipped start with short open tag files to be reported */ diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index d52cef9042d..310e823e52e 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -616,53 +616,58 @@ public function withPhpSets( return $this->addPhpLevelSets($pickedPhpVersions[0]); } - /** - * Following methods are suitable for PHP 7.4 and lower, before named args - * Let's keep them without warning, in case Rector is run on both PHP 7.4 and PHP 8.0 in CI - */ + #[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')] public function withPhp53Sets(): self { - return $this->addPhpLevelSets(PhpVersion::PHP_53); + return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__); } + #[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')] public function withPhp54Sets(): self { - return $this->addPhpLevelSets(PhpVersion::PHP_54); + return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__); } + #[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')] public function withPhp55Sets(): self { - return $this->addPhpLevelSets(PhpVersion::PHP_55); + return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__); } + #[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')] public function withPhp56Sets(): self { - return $this->addPhpLevelSets(PhpVersion::PHP_56); + return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__); } + #[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')] public function withPhp70Sets(): self { - return $this->addPhpLevelSets(PhpVersion::PHP_70); + return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__); } + #[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')] public function withPhp71Sets(): self { - return $this->addPhpLevelSets(PhpVersion::PHP_71); + return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__); } + #[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')] public function withPhp72Sets(): self { - return $this->addPhpLevelSets(PhpVersion::PHP_72); + return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__); } + #[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')] public function withPhp73Sets(): self { - return $this->addPhpLevelSets(PhpVersion::PHP_73); + return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__); } + #[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')] public function withPhp74Sets(): self { - return $this->addPhpLevelSets(PhpVersion::PHP_74); + return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__); } // there is no withPhp80Sets() and above, @@ -1193,6 +1198,13 @@ private function addPhpLevelSets(int $phpVersion): self return $this; } + private function reportDeprecatedPhpSetsMethod(string $methodName): self + { + SimpleParameterProvider::addParameter(Option::DEPRECATED_PHP_SETS_METHODS, $methodName); + + return $this; + } + /** * @param array> $availableRules */ diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 2c84e03df1a..53219616a8c 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -185,6 +185,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->deprecatedRulesReporter->reportDeprecatedSkippedRules(); $this->deprecatedRulesReporter->reportDeprecatedRectorUnsupportedMethods(); $this->deprecatedRulesReporter->reportDeprecatedCacheMetaExtensions(); + $this->deprecatedRulesReporter->reportDeprecatedPhpSetsMethods(); $this->missConfigurationReporter->reportSkippedNeverRegisteredRules(); $this->missConfigurationReporter->reportUnusedSkips($processResult); diff --git a/src/Console/Notifier.php b/src/Console/Notifier.php index 2e4dd184c93..76fd77bcd12 100644 --- a/src/Console/Notifier.php +++ b/src/Console/Notifier.php @@ -35,7 +35,7 @@ public static function errorWithPhpSetsNotSuitableForPHP74AndLower(): void } throw new InvalidConfigurationException( - 'The "->withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use more explicit "->withPhp53Sets()" ... "->withPhp74Sets()" in lower PHP versions instead.' + 'The "->withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use "->withPhpLevel()" in lower PHP versions instead.' ); } } diff --git a/src/Reporting/DeprecatedRulesReporter.php b/src/Reporting/DeprecatedRulesReporter.php index c607b457c36..2b9ff2601a9 100644 --- a/src/Reporting/DeprecatedRulesReporter.php +++ b/src/Reporting/DeprecatedRulesReporter.php @@ -69,6 +69,21 @@ public function reportDeprecatedCacheMetaExtensions(): void } } + public function reportDeprecatedPhpSetsMethods(): void + { + /** @var string[] $deprecatedPhpSetsMethods */ + $deprecatedPhpSetsMethods = SimpleParameterProvider::provideArrayParameter( + Option::DEPRECATED_PHP_SETS_METHODS + ); + + foreach (array_unique($deprecatedPhpSetsMethods) as $deprecatedPhpSetsMethod) { + $this->symfonyStyle->warning(sprintf( + 'The "->%s()" method is deprecated and no longer applied. Use "->withPhpLevel()" instead, to raise PHP level one rule at a time.', + $deprecatedPhpSetsMethod + )); + } + } + public function reportDeprecatedRectorUnsupportedMethods(): void { // to be added in related PR