diff --git a/phpstan.neon b/phpstan.neon index 701ec1fe665..f5aec0053bc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -238,8 +238,6 @@ parameters: - rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php - rules/Removing/Rector/Class_/RemoveTraitUseRector.php - rules/Renaming/Rector/StaticCall/RenameStaticMethodRector.php - - rules/Transform/Rector/FuncCall/FuncCallToNewRector.php - - rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php - rules/Transform/Rector/String_/StringToClassConstantRector.php # lack of generic array in nikic/php-parser diff --git a/rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/Fixture/fixture.php.inc b/rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/Fixture/fixture.php.inc deleted file mode 100644 index 9ec58a72a71..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,27 +0,0 @@ - ------ - diff --git a/rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/FuncCallToNewRectorTest.php b/rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/FuncCallToNewRectorTest.php deleted file mode 100644 index 26417ef10e8..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/FuncCallToNewRectorTest.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/FuncCallToNewRector/config/configured_rule.php b/rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/config/configured_rule.php deleted file mode 100644 index 471893d4d2d..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/config/configured_rule.php +++ /dev/null @@ -1,13 +0,0 @@ -ruleWithConfiguration(FuncCallToNewRector::class, [ - 'collection' => 'Collection', - ]); -}; diff --git a/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php b/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php index 94d00173c97..2761be2cb3c 100644 --- a/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php +++ b/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php @@ -6,24 +6,18 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; -use PhpParser\Node\Expr\New_; -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 Webmozart\Assert\Assert; /** - * @see \Rector\Tests\Transform\Rector\FuncCall\FuncCallToNewRector\FuncCallToNewRectorTest + * @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 FuncCallToNewRector extends AbstractRector implements ConfigurableRectorInterface +final class FuncCallToNewRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface { - /** - * @var string[] - */ - private array $functionToNew = []; - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change configured function calls to new Instance', [ @@ -68,17 +62,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $funcName = $this->getName($node); - if ($funcName === null) { - return null; - } - - $new = $this->functionToNew[strtolower($funcName)] ?? null; - if ($new === null) { - return null; - } - - return new New_(new FullyQualified($new), $node->args); + 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 + )); } /** @@ -86,12 +73,5 @@ public function refactor(Node $node): ?Node */ public function configure(array $configuration): void { - Assert::allString($configuration); - - // keyed by lowercased function name (function names are case-insensitive) - $this->functionToNew = []; - foreach ($configuration as $function => $new) { - $this->functionToNew[strtolower($function)] = $new; - } } }