From 965cea8095821044f45abf7a9df7a20b50bc3d59 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 7 Aug 2026 17:47:44 +0200 Subject: [PATCH 1/2] deprecate symfonyRoute and symfonyValidator args in withAttributesSets(), as covered by symfony arg --- src/Configuration/Option.php | 5 +++++ src/Configuration/RectorConfigBuilder.php | 25 ++++++----------------- src/Console/Command/ProcessCommand.php | 1 + src/Reporting/DeprecatedRulesReporter.php | 15 ++++++++++++++ 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index ee05a0314ab..5c3025fc8d9 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -242,6 +242,11 @@ final class Option */ public const string DEPRECATED_PHP_SETS_METHODS = 'deprecated_php_sets_methods'; + /** + * @internal For reporting deprecated withAttributesSets() arguments + */ + public const string DEPRECATED_ATTRIBUTES_SETS_ARGS = 'deprecated_attributes_sets_args'; + /** * @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 bab164f6d86..cf520b64fbb 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -27,8 +27,6 @@ use Rector\Enum\Config\Defaults; use Rector\Exception\Configuration\InvalidConfigurationException; use Rector\Php\PhpVersionResolver\ComposerJsonPhpVersionResolver; -use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; -use Rector\Php80\ValueObject\AnnotationToAttribute; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\Contract\SetProviderInterface; use Rector\Set\Enum\SetGroup; @@ -462,6 +460,9 @@ public function withSets(array $sets): self /** * Upgrade your annotations to attributes + * + * @param bool $symfonyRoute Deprecated, included in $symfony + * @param bool $symfonyValidator Deprecated, included in $symfony */ public function withAttributesSets( bool $symfony = false, @@ -486,27 +487,13 @@ public function withAttributesSets( $this->sets[] = SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES; } - // dx for more granular upgrade + // both are part of $symfony set, no longer applied on their own if ($symfonyRoute) { - if ($symfony) { - throw new InvalidConfigurationException( - '$symfonyRoute is already included in $symfony. Use $symfony only' - ); - } - - $this->withConfiguredRule(AnnotationToAttributeRector::class, [ - new AnnotationToAttribute('Symfony\Component\Routing\Annotation\Route'), - ]); + SimpleParameterProvider::addParameter(Option::DEPRECATED_ATTRIBUTES_SETS_ARGS, 'symfonyRoute'); } if ($symfonyValidator) { - if ($symfony) { - throw new InvalidConfigurationException( - '$symfonyValidator is already included in $symfony. Use $symfony only' - ); - } - - $this->sets[] = SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES; + SimpleParameterProvider::addParameter(Option::DEPRECATED_ATTRIBUTES_SETS_ARGS, 'symfonyValidator'); } if ($doctrine || $all) { diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 53219616a8c..d285ddd1d92 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -186,6 +186,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->deprecatedRulesReporter->reportDeprecatedRectorUnsupportedMethods(); $this->deprecatedRulesReporter->reportDeprecatedCacheMetaExtensions(); $this->deprecatedRulesReporter->reportDeprecatedPhpSetsMethods(); + $this->deprecatedRulesReporter->reportDeprecatedAttributesSetsArgs(); $this->missConfigurationReporter->reportSkippedNeverRegisteredRules(); $this->missConfigurationReporter->reportUnusedSkips($processResult); diff --git a/src/Reporting/DeprecatedRulesReporter.php b/src/Reporting/DeprecatedRulesReporter.php index 2b9ff2601a9..3a05e6437c0 100644 --- a/src/Reporting/DeprecatedRulesReporter.php +++ b/src/Reporting/DeprecatedRulesReporter.php @@ -84,6 +84,21 @@ public function reportDeprecatedPhpSetsMethods(): void } } + public function reportDeprecatedAttributesSetsArgs(): void + { + /** @var string[] $deprecatedAttributesSetsArgs */ + $deprecatedAttributesSetsArgs = SimpleParameterProvider::provideArrayParameter( + Option::DEPRECATED_ATTRIBUTES_SETS_ARGS + ); + + foreach (array_unique($deprecatedAttributesSetsArgs) as $deprecatedAttributesSetsArg) { + $this->symfonyStyle->warning(sprintf( + 'The "->withAttributesSets(%s: true)" argument is deprecated and no longer applied. It is already included in the "symfony: true" argument, use it instead.', + $deprecatedAttributesSetsArg + )); + } + } + public function reportDeprecatedRectorUnsupportedMethods(): void { // to be added in related PR From 255acea433db5fc2a7c1ebc57376463102ae5373 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 7 Aug 2026 17:48:27 +0200 Subject: [PATCH 2/2] fixes --- tests/Config/RectorConfigTest.php | 12 +++--------- .../ConfigurableRectorImportConfigCallsMergeTest.php | 2 ++ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/Config/RectorConfigTest.php b/tests/Config/RectorConfigTest.php index ac0d3a8ca85..f26396d6288 100644 --- a/tests/Config/RectorConfigTest.php +++ b/tests/Config/RectorConfigTest.php @@ -4,7 +4,6 @@ namespace Rector\Tests\Config; -use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use Rector\Configuration\Option; use Rector\Configuration\Parameter\SimpleParameterProvider; use Rector\Renaming\Rector\MethodCall\RenameMethodRector; @@ -12,15 +11,10 @@ use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector; use Rector\Renaming\ValueObject\MethodCallRename; use Rector\Renaming\ValueObject\RenameProperty; -use Rector\Symfony\Set\TwigSetList; +use Rector\Symfony\Set\SymfonySetList; use Rector\Testing\PHPUnit\AbstractLazyTestCase; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector; -/** - * On macOS, this file order config cause this container read other tests' config. - * so, this #[RunTestsInSeparateProcesses] is needed. - */ -#[RunTestsInSeparateProcesses] final class RectorConfigTest extends AbstractLazyTestCase { public function test(): void @@ -28,8 +22,8 @@ public function test(): void $rectorConfig = $this->getContainer(); $rectorConfig->configure() - ->withSets([TwigSetList::TWIG_134]) - ->withRules([ReturnTypeFromReturnNewRector::class])($rectorConfig); + ->withSets([SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION]) + ->withRules([ReturnTypeFromReturnNewRector::class]); // only collect root withRules() $this->assertCount(1, SimpleParameterProvider::provideArrayParameter(Option::ROOT_STANDALONE_REGISTERED_RULES)); diff --git a/tests/DependencyInjection/ConfigurableRectorImportConfigCallsMergeTest.php b/tests/DependencyInjection/ConfigurableRectorImportConfigCallsMergeTest.php index 671b7f2ed04..71a5cec9fff 100644 --- a/tests/DependencyInjection/ConfigurableRectorImportConfigCallsMergeTest.php +++ b/tests/DependencyInjection/ConfigurableRectorImportConfigCallsMergeTest.php @@ -6,10 +6,12 @@ use Iterator; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use Rector\Configuration\RenamedClassesDataCollector; use Rector\Renaming\Rector\Name\RenameClassRector; use Rector\Testing\PHPUnit\AbstractLazyTestCase; +#[RunTestsInSeparateProcesses] final class ConfigurableRectorImportConfigCallsMergeTest extends AbstractLazyTestCase { /**