From 8568b5311bf1b7f564dad85ff885c6d8d43a1a46 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 16 Nov 2026 22:48:48 +0100 Subject: [PATCH 1/2] [CodingStyle] Remove php_sapi_name/pi to constant conversion from coding style set --- config/set/coding-style.php | 4 ---- src/Config/Level/CodingStyleLevel.php | 11 ----------- src/Configuration/RectorConfigBuilder.php | 4 ---- 3 files changed, 19 deletions(-) diff --git a/config/set/coding-style.php b/config/set/coding-style.php index f3e5b87c833..1a083473828 100644 --- a/config/set/coding-style.php +++ b/config/set/coding-style.php @@ -6,10 +6,6 @@ use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { - foreach (CodingStyleLevel::RULES_WITH_CONFIGURATION as $rectorClass => $configuration) { - $rectorConfig->ruleWithConfiguration($rectorClass, $configuration); - } - // the rule order matters, as its used in withCodingStyleLevel() method // place the safest rules first, follow by more complex ones $rectorConfig->rules(CodingStyleLevel::RULES); diff --git a/src/Config/Level/CodingStyleLevel.php b/src/Config/Level/CodingStyleLevel.php index c94c8a013f6..32e262da50a 100644 --- a/src/Config/Level/CodingStyleLevel.php +++ b/src/Config/Level/CodingStyleLevel.php @@ -26,7 +26,6 @@ use Rector\CodingStyle\Rector\Use_\SeparateMultiUseImportsRector; use Rector\Contract\Rector\RectorInterface; use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; -use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector; /** * Key 0 = level 0 @@ -70,14 +69,4 @@ final class CodingStyleLevel SplitGroupedClassConstantsRector::class, RemoveUselessAliasInUseStatementRector::class, ]; - - /** - * @var array, mixed[]> - */ - public const array RULES_WITH_CONFIGURATION = [ - FuncCallToConstFetchRector::class => [ - 'php_sapi_name' => 'PHP_SAPI', - 'pi' => 'M_PI', - ], - ]; } diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index 31e2a907b4d..e5f8dba9e88 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -1014,10 +1014,6 @@ public function withCodingStyleLevel(int $level): self { $this->addLevelRules('withCodingStyleLevel', $level, CodingStyleLevel::RULES, 'codingStyle', 'CODING_STYLE'); - foreach (CodingStyleLevel::RULES_WITH_CONFIGURATION as $rectorClass => $configuration) { - $this->rulesWithConfigurations[$rectorClass][] = $configuration; - } - return $this; } From f10e39aa07a85d821230a987482de42bfaaea157 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 16 Nov 2026 22:54:02 +0100 Subject: [PATCH 2/2] [Transform] Deprecate FuncCallToConstFetchRector as no longer used in any set --- .../Fixture/fixture.php.inc | 31 ----------------- .../FunctionCallToConstantRectorTest.php | 28 ---------------- .../config/configured_rule.php | 14 -------- .../FuncCall/FuncCallToConstFetchRector.php | 33 +++++-------------- 4 files changed, 8 insertions(+), 98 deletions(-) delete mode 100644 rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/Fixture/fixture.php.inc delete mode 100644 rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/FunctionCallToConstantRectorTest.php delete mode 100644 rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/config/configured_rule.php diff --git a/rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/Fixture/fixture.php.inc b/rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/Fixture/fixture.php.inc deleted file mode 100644 index d21ca5ddd97..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/FunctionCallToConstantRectorTest.php b/rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/FunctionCallToConstantRectorTest.php deleted file mode 100644 index 4ea7327537b..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/FunctionCallToConstantRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/config/configured_rule.php b/rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/config/configured_rule.php deleted file mode 100644 index 5eceafe1391..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToConstFetchRector/config/configured_rule.php +++ /dev/null @@ -1,14 +0,0 @@ -ruleWithConfiguration(FuncCallToConstFetchRector::class, [ - 'php_sapi_name' => 'PHP_SAPI', - 'pi' => 'M_PI', - ]); -}; diff --git a/rules/Transform/Rector/FuncCall/FuncCallToConstFetchRector.php b/rules/Transform/Rector/FuncCall/FuncCallToConstFetchRector.php index 58a470764ac..8de8ef73217 100644 --- a/rules/Transform/Rector/FuncCall/FuncCallToConstFetchRector.php +++ b/rules/Transform/Rector/FuncCall/FuncCallToConstFetchRector.php @@ -5,25 +5,19 @@ namespace Rector\Transform\Rector\FuncCall; use PhpParser\Node; -use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\FuncCall; -use PhpParser\Node\Name; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Rector\Contract\Rector\ConfigurableRectorInterface; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\ConfiguredCodeSample; use Rector\RuleDoc\RuleDefinition; -use Webmozart\Assert\Assert; /** - * @see \Rector\Tests\Transform\Rector\FuncCall\FuncCallToConstFetchRector\FunctionCallToConstantRectorTest + * @deprecated This rule is deprecated, as converted functions are valid and not deprecated. Write a custom rule for the exact project case instead. */ -final class FuncCallToConstFetchRector extends AbstractRector implements ConfigurableRectorInterface +final class FuncCallToConstFetchRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface { - /** - * @var string[] - */ - private array $functionsToConstants = []; - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Changes use of function calls to use constants', [ @@ -69,16 +63,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $functionName = $this->getName($node); - if (! is_string($functionName)) { - return null; - } - - if (! array_key_exists($functionName, $this->functionsToConstants)) { - return null; - } - - return new ConstFetch(new Name($this->functionsToConstants[$functionName])); + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as converted functions are valid and not deprecated; write a custom rule for the exact project case instead', + self::class + )); } /** @@ -86,10 +74,5 @@ public function refactor(Node $node): ?Node */ public function configure(array $configuration): void { - Assert::allString($configuration); - Assert::allString(array_keys($configuration)); - - /** @var array $configuration */ - $this->functionsToConstants = $configuration; } }