diff --git a/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/Fixture/fixture.php.inc b/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/Fixture/fixture.php.inc deleted file mode 100644 index 84639951104..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,27 +0,0 @@ - ------ - diff --git a/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/Fixture/fixture2.php.inc b/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/Fixture/fixture2.php.inc deleted file mode 100644 index 76d09099f52..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/Fixture/fixture2.php.inc +++ /dev/null @@ -1,27 +0,0 @@ - ------ - diff --git a/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/FuncCallToStaticCallRectorTest.php b/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/FuncCallToStaticCallRectorTest.php deleted file mode 100644 index 6ae8d93f41f..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/FuncCallToStaticCallRectorTest.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/FuncCallToStaticCallRector/config/configured_rule.php b/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/config/configured_rule.php deleted file mode 100644 index ac257a7ce71..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToStaticCallRector/config/configured_rule.php +++ /dev/null @@ -1,15 +0,0 @@ -ruleWithConfiguration(FuncCallToStaticCallRector::class, [ - new FuncCallToStaticCall('view', 'SomeStaticClass', 'render'), - new FuncCallToStaticCall('SomeNamespaced\view', 'AnotherStaticClass', 'render'), - ]); -}; diff --git a/rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php b/rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php index 7816d60a9cd..71c089a7d90 100644 --- a/rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php +++ b/rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php @@ -6,23 +6,19 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; +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\FuncCallToStaticCall; -use Webmozart\Assert\Assert; /** - * @see \Rector\Tests\Transform\Rector\FuncCall\FuncCallToStaticCallRector\FuncCallToStaticCallRectorTest + * @deprecated This rule is deprecated, as too niche, never used and needs project context. Write a custom rule for the exact project case instead. */ -final class FuncCallToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface +final class FuncCallToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface { - /** - * @var array - */ - private array $funcCallsToStaticCallsByOldFunc = []; - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Turn defined function call to static method call', [ @@ -47,20 +43,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $funcName = $this->getName($node); - if ($funcName === null) { - return null; - } - - foreach ($this->funcCallsToStaticCallsByOldFunc[strtolower($funcName)] ?? [] as $funcCallToStaticCall) { - return $this->nodeFactory->createStaticCall( - $funcCallToStaticCall->getNewClassName(), - $funcCallToStaticCall->getNewMethodName(), - $node->args - ); - } - - return null; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as too niche and part of no set; write a custom rule for the exact project case instead', + self::class + )); } /** @@ -68,12 +54,5 @@ public function refactor(Node $node): ?Node */ public function configure(array $configuration): void { - Assert::allIsAOf($configuration, FuncCallToStaticCall::class); - - // bucket by lowercased old function name (function names are case-insensitive) - $this->funcCallsToStaticCallsByOldFunc = []; - foreach ($configuration as $funcCallToStaticCall) { - $this->funcCallsToStaticCallsByOldFunc[strtolower($funcCallToStaticCall->getOldFuncName())][] = $funcCallToStaticCall; - } } } diff --git a/rules/Transform/ValueObject/FuncCallToStaticCall.php b/rules/Transform/ValueObject/FuncCallToStaticCall.php index 4be740252a2..a203517e4dc 100644 --- a/rules/Transform/ValueObject/FuncCallToStaticCall.php +++ b/rules/Transform/ValueObject/FuncCallToStaticCall.php @@ -6,6 +6,9 @@ use Rector\Validation\RectorAssert; +/** + * @api used in deprecated FuncCallToStaticCallRector configs + */ final readonly class FuncCallToStaticCall { public function __construct(