diff --git a/rules-tests/Transform/Rector/MethodCall/MethodCallToStaticCallRector/Fixture/fixture.php.inc b/rules-tests/Transform/Rector/MethodCall/MethodCallToStaticCallRector/Fixture/fixture.php.inc deleted file mode 100644 index 63e4aa60a3b..00000000000 --- a/rules-tests/Transform/Rector/MethodCall/MethodCallToStaticCallRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,45 +0,0 @@ -anotherDependency = $anotherDependency; - } - - public function loadConfiguration() - { - return $this->anotherDependency->process('value'); - } -} - -?> ------ -anotherDependency = $anotherDependency; - } - - public function loadConfiguration() - { - return \StaticCaller::anotherMethod('value'); - } -} - -?> diff --git a/rules-tests/Transform/Rector/MethodCall/MethodCallToStaticCallRector/MethodCallToStaticCallRectorTest.php b/rules-tests/Transform/Rector/MethodCall/MethodCallToStaticCallRector/MethodCallToStaticCallRectorTest.php deleted file mode 100644 index 6226b10ff9f..00000000000 --- a/rules-tests/Transform/Rector/MethodCall/MethodCallToStaticCallRector/MethodCallToStaticCallRectorTest.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/MethodCallToStaticCallRector/Source/AnotherDependency.php b/rules-tests/Transform/Rector/MethodCall/MethodCallToStaticCallRector/Source/AnotherDependency.php deleted file mode 100644 index 98a99ad6c7c..00000000000 --- a/rules-tests/Transform/Rector/MethodCall/MethodCallToStaticCallRector/Source/AnotherDependency.php +++ /dev/null @@ -1,9 +0,0 @@ -ruleWithConfiguration(MethodCallToStaticCallRector::class, [ - new MethodCallToStaticCall(AnotherDependency::class, 'process', 'StaticCaller', 'anotherMethod'), - - ]); -}; diff --git a/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php b/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php index b13779acfec..1b7d1a5ebbc 100644 --- a/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php +++ b/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php @@ -6,23 +6,19 @@ use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; +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\MethodCallToStaticCall; -use Webmozart\Assert\Assert; /** - * @see \Rector\Tests\Transform\Rector\MethodCall\MethodCallToStaticCallRector\MethodCallToStaticCallRectorTest + * @deprecated This rule is deprecated, as turning a method call into a static call depends on project context and this generic rule is too niche. Write a custom rule for the exact project case instead. */ -final class MethodCallToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface +final class MethodCallToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface { - /** - * @var array - */ - private array $methodCallsToStaticCallsByOldMethod = []; - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change method call to desired static call', [ @@ -79,24 +75,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $methodName = $this->getName($node->name); - if ($methodName === null) { - return null; - } - - foreach ($this->methodCallsToStaticCallsByOldMethod[strtolower($methodName)] ?? [] as $methodCallToStaticCall) { - if (! $this->isObjectType($node->var, $methodCallToStaticCall->getOldObjectType())) { - continue; - } - - return $this->nodeFactory->createStaticCall( - $methodCallToStaticCall->getNewClass(), - $methodCallToStaticCall->getNewMethod(), - $node->args - ); - } - - return null; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as turning a method call into a static call depends on project context; write a custom rule for the exact project case instead', + self::class + )); } /** @@ -104,11 +86,5 @@ public function refactor(Node $node): ?Node */ public function configure(array $configuration): void { - Assert::allIsAOf($configuration, MethodCallToStaticCall::class); - - $this->methodCallsToStaticCallsByOldMethod = []; - foreach ($configuration as $methodCallToStaticCall) { - $this->methodCallsToStaticCallsByOldMethod[strtolower($methodCallToStaticCall->getOldMethod())][] = $methodCallToStaticCall; - } } } diff --git a/rules/Transform/ValueObject/MethodCallToStaticCall.php b/rules/Transform/ValueObject/MethodCallToStaticCall.php index d91ee08ab6e..7996fc5e173 100644 --- a/rules/Transform/ValueObject/MethodCallToStaticCall.php +++ b/rules/Transform/ValueObject/MethodCallToStaticCall.php @@ -7,6 +7,9 @@ use PHPStan\Type\ObjectType; use Rector\Validation\RectorAssert; +/** + * @api used in deprecated MethodCallToStaticCallRector configs + */ final readonly class MethodCallToStaticCall { public function __construct(