Skip to content

Commit 965cea8

Browse files
committed
deprecate symfonyRoute and symfonyValidator args in withAttributesSets(), as covered by symfony arg
1 parent 3bbb183 commit 965cea8

4 files changed

Lines changed: 27 additions & 19 deletions

File tree

‎src/Configuration/Option.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ final class Option
242242
*/
243243
public const string DEPRECATED_PHP_SETS_METHODS = 'deprecated_php_sets_methods';
244244

245+
/**
246+
* @internal For reporting deprecated withAttributesSets() arguments
247+
*/
248+
public const string DEPRECATED_ATTRIBUTES_SETS_ARGS = 'deprecated_attributes_sets_args';
249+
245250
/**
246251
* @internal For collect skipped start with short open tag files to be reported
247252
*/

‎src/Configuration/RectorConfigBuilder.php‎

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
use Rector\Enum\Config\Defaults;
2828
use Rector\Exception\Configuration\InvalidConfigurationException;
2929
use Rector\Php\PhpVersionResolver\ComposerJsonPhpVersionResolver;
30-
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
31-
use Rector\Php80\ValueObject\AnnotationToAttribute;
3230
use Rector\PHPUnit\Set\PHPUnitSetList;
3331
use Rector\Set\Contract\SetProviderInterface;
3432
use Rector\Set\Enum\SetGroup;
@@ -462,6 +460,9 @@ public function withSets(array $sets): self
462460

463461
/**
464462
* Upgrade your annotations to attributes
463+
*
464+
* @param bool $symfonyRoute Deprecated, included in $symfony
465+
* @param bool $symfonyValidator Deprecated, included in $symfony
465466
*/
466467
public function withAttributesSets(
467468
bool $symfony = false,
@@ -486,27 +487,13 @@ public function withAttributesSets(
486487
$this->sets[] = SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES;
487488
}
488489

489-
// dx for more granular upgrade
490+
// both are part of $symfony set, no longer applied on their own
490491
if ($symfonyRoute) {
491-
if ($symfony) {
492-
throw new InvalidConfigurationException(
493-
'$symfonyRoute is already included in $symfony. Use $symfony only'
494-
);
495-
}
496-
497-
$this->withConfiguredRule(AnnotationToAttributeRector::class, [
498-
new AnnotationToAttribute('Symfony\Component\Routing\Annotation\Route'),
499-
]);
492+
SimpleParameterProvider::addParameter(Option::DEPRECATED_ATTRIBUTES_SETS_ARGS, 'symfonyRoute');
500493
}
501494

502495
if ($symfonyValidator) {
503-
if ($symfony) {
504-
throw new InvalidConfigurationException(
505-
'$symfonyValidator is already included in $symfony. Use $symfony only'
506-
);
507-
}
508-
509-
$this->sets[] = SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES;
496+
SimpleParameterProvider::addParameter(Option::DEPRECATED_ATTRIBUTES_SETS_ARGS, 'symfonyValidator');
510497
}
511498

512499
if ($doctrine || $all) {

‎src/Console/Command/ProcessCommand.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
186186
$this->deprecatedRulesReporter->reportDeprecatedRectorUnsupportedMethods();
187187
$this->deprecatedRulesReporter->reportDeprecatedCacheMetaExtensions();
188188
$this->deprecatedRulesReporter->reportDeprecatedPhpSetsMethods();
189+
$this->deprecatedRulesReporter->reportDeprecatedAttributesSetsArgs();
189190

190191
$this->missConfigurationReporter->reportSkippedNeverRegisteredRules();
191192
$this->missConfigurationReporter->reportUnusedSkips($processResult);

‎src/Reporting/DeprecatedRulesReporter.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ public function reportDeprecatedPhpSetsMethods(): void
8484
}
8585
}
8686

87+
public function reportDeprecatedAttributesSetsArgs(): void
88+
{
89+
/** @var string[] $deprecatedAttributesSetsArgs */
90+
$deprecatedAttributesSetsArgs = SimpleParameterProvider::provideArrayParameter(
91+
Option::DEPRECATED_ATTRIBUTES_SETS_ARGS
92+
);
93+
94+
foreach (array_unique($deprecatedAttributesSetsArgs) as $deprecatedAttributesSetsArg) {
95+
$this->symfonyStyle->warning(sprintf(
96+
'The "->withAttributesSets(%s: true)" argument is deprecated and no longer applied. It is already included in the "symfony: true" argument, use it instead.',
97+
$deprecatedAttributesSetsArg
98+
));
99+
}
100+
}
101+
87102
public function reportDeprecatedRectorUnsupportedMethods(): void
88103
{
89104
// to be added in related PR

0 commit comments

Comments
 (0)