Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
38 changes: 25 additions & 13 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<class-string<RectorInterface>> $availableRules
*/
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}
}
15 changes: 15 additions & 0 deletions src/Reporting/DeprecatedRulesReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading