diff --git a/rules-tests/Transform/Rector/StaticCall/StaticCallToNewRector/Fixture/some_class.php.inc b/rules-tests/Transform/Rector/StaticCall/StaticCallToNewRector/Fixture/some_class.php.inc deleted file mode 100644 index 6096090f591..00000000000 --- a/rules-tests/Transform/Rector/StaticCall/StaticCallToNewRector/Fixture/some_class.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - 'bar'], Response::HTTP_OK); - } -} - -?> ------ - 'bar'], Response::HTTP_OK); - } -} - -?> diff --git a/rules-tests/Transform/Rector/StaticCall/StaticCallToNewRector/Source/SomeJsonResponse.php b/rules-tests/Transform/Rector/StaticCall/StaticCallToNewRector/Source/SomeJsonResponse.php deleted file mode 100644 index a0570a50a73..00000000000 --- a/rules-tests/Transform/Rector/StaticCall/StaticCallToNewRector/Source/SomeJsonResponse.php +++ /dev/null @@ -1,10 +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/StaticCall/StaticCallToNewRector/config/configured_rule.php b/rules-tests/Transform/Rector/StaticCall/StaticCallToNewRector/config/configured_rule.php deleted file mode 100644 index 18bc72b4754..00000000000 --- a/rules-tests/Transform/Rector/StaticCall/StaticCallToNewRector/config/configured_rule.php +++ /dev/null @@ -1,13 +0,0 @@ -ruleWithConfiguration(StaticCallToNewRector::class, [new StaticCallToNew(SomeJsonResponse::class, 'create')]); -}; diff --git a/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php b/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php index e4ac0190472..997c0c7c3a2 100644 --- a/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php +++ b/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php @@ -5,26 +5,20 @@ namespace Rector\Transform\Rector\StaticCall; use PhpParser\Node; -use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\StaticCall; -use PhpParser\Node\Name\FullyQualified; +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\StaticCallToNew; -use Webmozart\Assert\Assert; /** - * @see \Rector\Tests\Transform\Rector\StaticCall\StaticCallToNewRector\StaticCallToNewRectorTest + * @deprecated This rule is deprecated, as only used for 1 case now covered by dedicated ResponseCreateToNewRector in rector-symfony. Write a custom rule for the exact project case instead. */ -final class StaticCallToNewRector extends AbstractRector implements ConfigurableRectorInterface +final class StaticCallToNewRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface { - /** - * @var array - */ - private array $staticCallsToNewsByMethod = []; - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change static call to new instance', [ @@ -67,25 +61,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $methodName = $this->getName($node->name); - if ($methodName === null) { - return null; - } - - $class = $this->getName($node->class); - if ($class === null) { - return null; - } - - foreach ($this->staticCallsToNewsByMethod[strtolower($methodName)] ?? [] as $staticCallToNew) { - if (! $this->isName($node->class, $staticCallToNew->getClass())) { - continue; - } - - return new New_(new FullyQualified($class), $node->args); - } - - return null; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as only used for 1 case now covered by a dedicated rule; write a custom rule for the exact project case instead', + self::class + )); } /** @@ -93,11 +72,5 @@ public function refactor(Node $node): ?Node */ public function configure(array $configuration): void { - Assert::allIsAOf($configuration, StaticCallToNew::class); - - $this->staticCallsToNewsByMethod = []; - foreach ($configuration as $staticCallToNew) { - $this->staticCallsToNewsByMethod[strtolower($staticCallToNew->getMethod())][] = $staticCallToNew; - } } } diff --git a/rules/Transform/ValueObject/StaticCallToNew.php b/rules/Transform/ValueObject/StaticCallToNew.php index c3129b674f2..087b552dce3 100644 --- a/rules/Transform/ValueObject/StaticCallToNew.php +++ b/rules/Transform/ValueObject/StaticCallToNew.php @@ -6,6 +6,9 @@ use Rector\Validation\RectorAssert; +/** + * @api used in deprecated StaticCallToNewRector configs + */ final readonly class StaticCallToNew { public function __construct(