Skip to content

Commit 3ca4e0a

Browse files
authored
[Configuration] Deprecate withPhp53Sets() ... withPhp74Sets(), suggest withPhpLevel() (#8253)
1 parent 210246f commit 3ca4e0a

5 files changed

Lines changed: 47 additions & 14 deletions

File tree

‎src/Configuration/Option.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ final class Option
237237
*/
238238
public const string CACHE_META_EXTENSIONS = 'cache_meta_extensions';
239239

240+
/**
241+
* @internal For reporting deprecated withPhp53Sets() ... withPhp74Sets() methods
242+
*/
243+
public const string DEPRECATED_PHP_SETS_METHODS = 'deprecated_php_sets_methods';
244+
240245
/**
241246
* @internal For collect skipped start with short open tag files to be reported
242247
*/

‎src/Configuration/RectorConfigBuilder.php‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -616,53 +616,58 @@ public function withPhpSets(
616616
return $this->addPhpLevelSets($pickedPhpVersions[0]);
617617
}
618618

619-
/**
620-
* Following methods are suitable for PHP 7.4 and lower, before named args
621-
* Let's keep them without warning, in case Rector is run on both PHP 7.4 and PHP 8.0 in CI
622-
*/
619+
#[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')]
623620
public function withPhp53Sets(): self
624621
{
625-
return $this->addPhpLevelSets(PhpVersion::PHP_53);
622+
return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);
626623
}
627624

625+
#[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')]
628626
public function withPhp54Sets(): self
629627
{
630-
return $this->addPhpLevelSets(PhpVersion::PHP_54);
628+
return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);
631629
}
632630

631+
#[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')]
633632
public function withPhp55Sets(): self
634633
{
635-
return $this->addPhpLevelSets(PhpVersion::PHP_55);
634+
return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);
636635
}
637636

637+
#[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')]
638638
public function withPhp56Sets(): self
639639
{
640-
return $this->addPhpLevelSets(PhpVersion::PHP_56);
640+
return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);
641641
}
642642

643+
#[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')]
643644
public function withPhp70Sets(): self
644645
{
645-
return $this->addPhpLevelSets(PhpVersion::PHP_70);
646+
return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);
646647
}
647648

649+
#[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')]
648650
public function withPhp71Sets(): self
649651
{
650-
return $this->addPhpLevelSets(PhpVersion::PHP_71);
652+
return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);
651653
}
652654

655+
#[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')]
653656
public function withPhp72Sets(): self
654657
{
655-
return $this->addPhpLevelSets(PhpVersion::PHP_72);
658+
return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);
656659
}
657660

661+
#[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')]
658662
public function withPhp73Sets(): self
659663
{
660-
return $this->addPhpLevelSets(PhpVersion::PHP_73);
664+
return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);
661665
}
662666

667+
#[Deprecated(message: 'Use "withPhpLevel()" instead, it raises PHP level one rule at a time.')]
663668
public function withPhp74Sets(): self
664669
{
665-
return $this->addPhpLevelSets(PhpVersion::PHP_74);
670+
return $this->reportDeprecatedPhpSetsMethod(__FUNCTION__);
666671
}
667672

668673
// there is no withPhp80Sets() and above,
@@ -1193,6 +1198,13 @@ private function addPhpLevelSets(int $phpVersion): self
11931198
return $this;
11941199
}
11951200

1201+
private function reportDeprecatedPhpSetsMethod(string $methodName): self
1202+
{
1203+
SimpleParameterProvider::addParameter(Option::DEPRECATED_PHP_SETS_METHODS, $methodName);
1204+
1205+
return $this;
1206+
}
1207+
11961208
/**
11971209
* @param array<class-string<RectorInterface>> $availableRules
11981210
*/

‎src/Console/Command/ProcessCommand.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
185185
$this->deprecatedRulesReporter->reportDeprecatedSkippedRules();
186186
$this->deprecatedRulesReporter->reportDeprecatedRectorUnsupportedMethods();
187187
$this->deprecatedRulesReporter->reportDeprecatedCacheMetaExtensions();
188+
$this->deprecatedRulesReporter->reportDeprecatedPhpSetsMethods();
188189

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

‎src/Console/Notifier.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function errorWithPhpSetsNotSuitableForPHP74AndLower(): void
3535
}
3636

3737
throw new InvalidConfigurationException(
38-
'The "->withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use more explicit "->withPhp53Sets()" ... "->withPhp74Sets()" in lower PHP versions instead.'
38+
'The "->withPhpSets()" method uses named arguments. Its suitable for PHP 8.0+. Use "->withPhpLevel()" in lower PHP versions instead.'
3939
);
4040
}
4141
}

‎src/Reporting/DeprecatedRulesReporter.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ public function reportDeprecatedCacheMetaExtensions(): void
6969
}
7070
}
7171

72+
public function reportDeprecatedPhpSetsMethods(): void
73+
{
74+
/** @var string[] $deprecatedPhpSetsMethods */
75+
$deprecatedPhpSetsMethods = SimpleParameterProvider::provideArrayParameter(
76+
Option::DEPRECATED_PHP_SETS_METHODS
77+
);
78+
79+
foreach (array_unique($deprecatedPhpSetsMethods) as $deprecatedPhpSetsMethod) {
80+
$this->symfonyStyle->warning(sprintf(
81+
'The "->%s()" method is deprecated and no longer applied. Use "->withPhpLevel()" instead, to raise PHP level one rule at a time.',
82+
$deprecatedPhpSetsMethod
83+
));
84+
}
85+
}
86+
7287
public function reportDeprecatedRectorUnsupportedMethods(): void
7388
{
7489
// to be added in related PR

0 commit comments

Comments
 (0)