|
6 | 6 |
|
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Expr\FuncCall; |
9 | | -use PhpParser\Node\Expr\New_; |
10 | | -use PhpParser\Node\Name\FullyQualified; |
| 9 | +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; |
11 | 10 | use Rector\Contract\Rector\ConfigurableRectorInterface; |
| 11 | +use Rector\Exception\ShouldNotHappenException; |
12 | 12 | use Rector\Rector\AbstractRector; |
13 | 13 | use Rector\RuleDoc\CodeSample\ConfiguredCodeSample; |
14 | 14 | use Rector\RuleDoc\RuleDefinition; |
15 | | -use Webmozart\Assert\Assert; |
16 | 15 |
|
17 | 16 | /** |
18 | | - * @see \Rector\Tests\Transform\Rector\FuncCall\FuncCallToNewRector\FuncCallToNewRectorTest |
| 17 | + * @deprecated This rule is deprecated, as too niche, never used and needs project context. Write a custom rule for the exact project case instead. |
19 | 18 | */ |
20 | | -final class FuncCallToNewRector extends AbstractRector implements ConfigurableRectorInterface |
| 19 | +final class FuncCallToNewRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface |
21 | 20 | { |
22 | | - /** |
23 | | - * @var string[] |
24 | | - */ |
25 | | - private array $functionToNew = []; |
26 | | - |
27 | 21 | public function getRuleDefinition(): RuleDefinition |
28 | 22 | { |
29 | 23 | return new RuleDefinition('Change configured function calls to new Instance', [ |
@@ -68,30 +62,16 @@ public function getNodeTypes(): array |
68 | 62 | */ |
69 | 63 | public function refactor(Node $node): ?Node |
70 | 64 | { |
71 | | - $funcName = $this->getName($node); |
72 | | - if ($funcName === null) { |
73 | | - return null; |
74 | | - } |
75 | | - |
76 | | - $new = $this->functionToNew[strtolower($funcName)] ?? null; |
77 | | - if ($new === null) { |
78 | | - return null; |
79 | | - } |
80 | | - |
81 | | - return new New_(new FullyQualified($new), $node->args); |
| 65 | + throw new ShouldNotHappenException(sprintf( |
| 66 | + '"%s" rule is deprecated, as too niche and part of no set; write a custom rule for the exact project case instead', |
| 67 | + self::class |
| 68 | + )); |
82 | 69 | } |
83 | 70 |
|
84 | 71 | /** |
85 | 72 | * @param mixed[] $configuration |
86 | 73 | */ |
87 | 74 | public function configure(array $configuration): void |
88 | 75 | { |
89 | | - Assert::allString($configuration); |
90 | | - |
91 | | - // keyed by lowercased function name (function names are case-insensitive) |
92 | | - $this->functionToNew = []; |
93 | | - foreach ($configuration as $function => $new) { |
94 | | - $this->functionToNew[strtolower($function)] = $new; |
95 | | - } |
96 | 76 | } |
97 | 77 | } |
0 commit comments