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