From 0fc1175b1099583bbbfae2d0f69b84658f72afce Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 22 Oct 2026 12:53:57 +0200 Subject: [PATCH] [Transform] Deprecate MethodCallToFuncCallRector as niche and context-dependent --- .../Fixture/some_class.php.inc | 31 ------------- .../MethodCallToFuncCallRectorTest.php | 28 ------------ .../Source/ParentControllerWithRender.php | 10 ----- .../config/configured_rule.php | 17 ------- .../MethodCall/MethodCallToFuncCallRector.php | 44 ++++--------------- .../ValueObject/MethodCallToFuncCall.php | 3 ++ 6 files changed, 11 insertions(+), 122 deletions(-) delete mode 100644 rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/Fixture/some_class.php.inc delete mode 100644 rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/MethodCallToFuncCallRectorTest.php delete mode 100644 rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/Source/ParentControllerWithRender.php delete mode 100644 rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/config/configured_rule.php diff --git a/rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/Fixture/some_class.php.inc b/rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/Fixture/some_class.php.inc deleted file mode 100644 index 5f0e47b06ab..00000000000 --- a/rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/Fixture/some_class.php.inc +++ /dev/null @@ -1,31 +0,0 @@ -render('some_template'); - } -} - -?> ------ - diff --git a/rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/MethodCallToFuncCallRectorTest.php b/rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/MethodCallToFuncCallRectorTest.php deleted file mode 100644 index 305ef5b28c6..00000000000 --- a/rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/MethodCallToFuncCallRectorTest.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/MethodCall/MethodCallToFuncCallRector/Source/ParentControllerWithRender.php b/rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/Source/ParentControllerWithRender.php deleted file mode 100644 index 31659e9d0af..00000000000 --- a/rules-tests/Transform/Rector/MethodCall/MethodCallToFuncCallRector/Source/ParentControllerWithRender.php +++ /dev/null @@ -1,10 +0,0 @@ -ruleWithConfiguration(MethodCallToFuncCallRector::class, [ - new MethodCallToFuncCall( - 'Rector\Tests\Transform\Rector\MethodCall\MethodCallToFuncCallRector\Source\ParentControllerWithRender', - 'render', - 'view' - ), - ]); -}; diff --git a/rules/Transform/Rector/MethodCall/MethodCallToFuncCallRector.php b/rules/Transform/Rector/MethodCall/MethodCallToFuncCallRector.php index 34d646a03f6..b1be6ca0071 100644 --- a/rules/Transform/Rector/MethodCall/MethodCallToFuncCallRector.php +++ b/rules/Transform/Rector/MethodCall/MethodCallToFuncCallRector.php @@ -5,28 +5,20 @@ namespace Rector\Transform\Rector\MethodCall; use PhpParser\Node; -use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; -use PhpParser\Node\Name\FullyQualified; -use PHPStan\Type\ObjectType; +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 Rector\Transform\ValueObject\MethodCallToFuncCall; -use Webmozart\Assert\Assert; /** - * @note used extensively https://github.com/search?q=MethodCallToFuncCallRector%3A%3Aclass&type=code - * @see \Rector\Tests\Transform\Rector\MethodCall\MethodCallToFuncCallRector\MethodCallToFuncCallRectorTest + * @deprecated This rule is deprecated, as changing a method call to a function call is niche and depends on project context. Write a custom rule for the exact project case instead. */ -final class MethodCallToFuncCallRector extends AbstractRector implements ConfigurableRectorInterface +final class MethodCallToFuncCallRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface { - /** - * @var array - */ - private array $methodCallsToFuncCallsByMethod = []; - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change method call to function call', [ @@ -70,24 +62,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if ($node->isFirstClassCallable()) { - return null; - } - - $methodName = $this->getName($node->name); - if ($methodName === null) { - return null; - } - - foreach ($this->methodCallsToFuncCallsByMethod[strtolower($methodName)] ?? [] as $methodCallToFuncCall) { - if (! $this->isObjectType($node->var, new ObjectType($methodCallToFuncCall->getObjectType()))) { - continue; - } - - return new FuncCall(new FullyQualified($methodCallToFuncCall->getFunctionName()), $node->getArgs()); - } - - return null; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as changing a method call to a function call is niche and depends on project context; write a custom rule for the exact project case instead', + self::class + )); } /** @@ -95,11 +73,5 @@ public function refactor(Node $node): ?Node */ public function configure(array $configuration): void { - Assert::allIsInstanceOf($configuration, MethodCallToFuncCall::class); - - $this->methodCallsToFuncCallsByMethod = []; - foreach ($configuration as $methodCallToFuncCall) { - $this->methodCallsToFuncCallsByMethod[strtolower($methodCallToFuncCall->getMethodName())][] = $methodCallToFuncCall; - } } } diff --git a/rules/Transform/ValueObject/MethodCallToFuncCall.php b/rules/Transform/ValueObject/MethodCallToFuncCall.php index 953a73869ef..eb1582cccef 100644 --- a/rules/Transform/ValueObject/MethodCallToFuncCall.php +++ b/rules/Transform/ValueObject/MethodCallToFuncCall.php @@ -4,6 +4,9 @@ namespace Rector\Transform\ValueObject; +/** + * @api used in deprecated MethodCallToFuncCallRector configs + */ final readonly class MethodCallToFuncCall { public function __construct(