|
6 | 6 |
|
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Scalar\String_; |
| 9 | +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; |
9 | 10 | use Rector\Contract\Rector\ConfigurableRectorInterface; |
10 | | -use Rector\PhpParser\Node\Value\ValueResolver; |
| 11 | +use Rector\Exception\ShouldNotHappenException; |
11 | 12 | use Rector\Rector\AbstractRector; |
12 | 13 | use Rector\RuleDoc\CodeSample\ConfiguredCodeSample; |
13 | 14 | use Rector\RuleDoc\RuleDefinition; |
14 | 15 | use Rector\Transform\ValueObject\StringToClassConstant; |
15 | | -use Webmozart\Assert\Assert; |
16 | 16 |
|
17 | 17 | /** |
18 | | - * @see \Rector\Tests\Transform\Rector\String_\StringToClassConstantRector\StringToClassConstantRectorTest |
| 18 | + * @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 | 19 | */ |
20 | | -final class StringToClassConstantRector extends AbstractRector implements ConfigurableRectorInterface |
| 20 | +final class StringToClassConstantRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface |
21 | 21 | { |
22 | | - /** |
23 | | - * @var StringToClassConstant[] |
24 | | - */ |
25 | | - private array $stringsToClassConstants = []; |
26 | | - |
27 | | - public function __construct( |
28 | | - private readonly ValueResolver $valueResolver |
29 | | - ) { |
30 | | - } |
31 | | - |
32 | 22 | public function getRuleDefinition(): RuleDefinition |
33 | 23 | { |
34 | 24 | return new RuleDefinition('Change strings to specific constants', [ |
@@ -71,27 +61,16 @@ public function getNodeTypes(): array |
71 | 61 | */ |
72 | 62 | public function refactor(Node $node): ?Node |
73 | 63 | { |
74 | | - foreach ($this->stringsToClassConstants as $stringToClassConstant) { |
75 | | - if (! $this->valueResolver->isValue($node, $stringToClassConstant->getString())) { |
76 | | - continue; |
77 | | - } |
78 | | - |
79 | | - return $this->nodeFactory->createClassConstFetch( |
80 | | - $stringToClassConstant->getClass(), |
81 | | - $stringToClassConstant->getConstant() |
82 | | - ); |
83 | | - } |
84 | | - |
85 | | - return null; |
| 64 | + throw new ShouldNotHappenException(sprintf( |
| 65 | + '"%s" rule is deprecated, as too niche and part of no set; write a custom rule for the exact project case instead', |
| 66 | + self::class |
| 67 | + )); |
86 | 68 | } |
87 | 69 |
|
88 | 70 | /** |
89 | 71 | * @param mixed[] $configuration |
90 | 72 | */ |
91 | 73 | public function configure(array $configuration): void |
92 | 74 | { |
93 | | - Assert::allIsAOf($configuration, StringToClassConstant::class); |
94 | | - |
95 | | - $this->stringsToClassConstants = $configuration; |
96 | 75 | } |
97 | 76 | } |
0 commit comments