|
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Stmt\Class_; |
9 | 9 | use PhpParser\Node\Stmt\Trait_; |
10 | | -use PhpParser\Node\Stmt\TraitUse; |
| 10 | +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; |
11 | 11 | use Rector\Contract\Rector\ConfigurableRectorInterface; |
| 12 | +use Rector\Exception\ShouldNotHappenException; |
12 | 13 | use Rector\Rector\AbstractRector; |
13 | 14 | use Rector\RuleDoc\CodeSample\ConfiguredCodeSample; |
14 | 15 | use Rector\RuleDoc\RuleDefinition; |
15 | | -use Webmozart\Assert\Assert; |
16 | 16 |
|
17 | 17 | /** |
18 | | - * @see \Rector\Tests\Removing\Rector\Class_\RemoveTraitUseRector\RemoveTraitUseRectorTest |
| 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 RemoveTraitUseRector extends AbstractRector implements ConfigurableRectorInterface |
| 20 | +final class RemoveTraitUseRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface |
21 | 21 | { |
22 | | - /** |
23 | | - * @var string[] |
24 | | - */ |
25 | | - private array $traitsToRemove = []; |
26 | | - |
27 | 22 | public function getRuleDefinition(): RuleDefinition |
28 | 23 | { |
29 | 24 | return new RuleDefinition('Remove specific traits from code', [ |
@@ -59,42 +54,16 @@ public function getNodeTypes(): array |
59 | 54 | */ |
60 | 55 | public function refactor(Node $node): ?Node |
61 | 56 | { |
62 | | - $hasChanged = false; |
63 | | - |
64 | | - foreach ($node->stmts as $key => $stmt) { |
65 | | - if (! $stmt instanceof TraitUse) { |
66 | | - continue; |
67 | | - } |
68 | | - |
69 | | - foreach ($stmt->traits as $traitKey => $trait) { |
70 | | - if (! $this->isNames($trait, $this->traitsToRemove)) { |
71 | | - continue; |
72 | | - } |
73 | | - |
74 | | - unset($stmt->traits[$traitKey]); |
75 | | - $hasChanged = true; |
76 | | - } |
77 | | - |
78 | | - // remove empty trait uses |
79 | | - if ($stmt->traits === []) { |
80 | | - unset($node->stmts[$key]); |
81 | | - } |
82 | | - } |
83 | | - |
84 | | - if ($hasChanged) { |
85 | | - return $node; |
86 | | - } |
87 | | - |
88 | | - return null; |
| 57 | + throw new ShouldNotHappenException(sprintf( |
| 58 | + '"%s" rule is deprecated, as too niche and part of no set; write a custom rule for the exact project case instead', |
| 59 | + self::class |
| 60 | + )); |
89 | 61 | } |
90 | 62 |
|
91 | 63 | /** |
92 | 64 | * @param mixed[] $configuration |
93 | 65 | */ |
94 | 66 | public function configure(array $configuration): void |
95 | 67 | { |
96 | | - Assert::allString($configuration); |
97 | | - |
98 | | - $this->traitsToRemove = $configuration; |
99 | 68 | } |
100 | 69 | } |
0 commit comments