|
9 | 9 | use PhpParser\Node\Stmt\ClassConst; |
10 | 10 | use PhpParser\Node\Stmt\ClassLike; |
11 | 11 | use PhpParser\Node\Stmt\Property; |
12 | | -use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode; |
13 | | -use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; |
14 | | -use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; |
15 | | -use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; |
16 | | -use Rector\Comments\NodeDocBlock\DocBlockUpdater; |
| 12 | +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; |
17 | 13 | use Rector\Contract\Rector\ConfigurableRectorInterface; |
| 14 | +use Rector\Exception\ShouldNotHappenException; |
18 | 15 | use Rector\Rector\AbstractRector; |
19 | 16 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; |
20 | 17 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
21 | | -use Webmozart\Assert\Assert; |
22 | 18 |
|
23 | 19 | /** |
24 | | - * @see \Rector\Tests\DeadCode\Rector\ClassLike\RemoveAnnotationRector\RemoveAnnotationRectorTest |
| 20 | + * @deprecated This rule is deprecated, as removing an annotation by name is a coding standard concern, not an upgrade path. It is not part of any set and a coding standard tool handles it better. |
25 | 21 | */ |
26 | | -final class RemoveAnnotationRector extends AbstractRector implements ConfigurableRectorInterface |
| 22 | +final class RemoveAnnotationRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface |
27 | 23 | { |
28 | | - /** |
29 | | - * @var string[] |
30 | | - */ |
31 | | - private array $annotationsToRemove = []; |
32 | | - |
33 | | - public function __construct( |
34 | | - private readonly PhpDocTagRemover $phpDocTagRemover, |
35 | | - private readonly DocBlockUpdater $docBlockUpdater, |
36 | | - private readonly PhpDocInfoFactory $phpDocInfoFactory, |
37 | | - ) { |
38 | | - } |
39 | | - |
40 | 24 | public function getRuleDefinition(): RuleDefinition |
41 | 25 | { |
42 | 26 | return new RuleDefinition('Remove annotation by names', [ |
@@ -74,47 +58,16 @@ public function getNodeTypes(): array |
74 | 58 | */ |
75 | 59 | public function refactor(Node $node): ?Node |
76 | 60 | { |
77 | | - Assert::notEmpty($this->annotationsToRemove); |
78 | | - |
79 | | - $phpDocInfo = $this->phpDocInfoFactory->createFromNode($node); |
80 | | - if (! $phpDocInfo instanceof PhpDocInfo) { |
81 | | - return null; |
82 | | - } |
83 | | - |
84 | | - $hasChanged = false; |
85 | | - |
86 | | - foreach ($this->annotationsToRemove as $annotationToRemove) { |
87 | | - $namedHasChanged = $this->phpDocTagRemover->removeByName($phpDocInfo, $annotationToRemove); |
88 | | - if ($namedHasChanged) { |
89 | | - $hasChanged = true; |
90 | | - } |
91 | | - |
92 | | - if (! is_a($annotationToRemove, PhpDocTagValueNode::class, true)) { |
93 | | - continue; |
94 | | - } |
95 | | - |
96 | | - $typedHasChanged = $phpDocInfo->removeByType($annotationToRemove); |
97 | | - if ($typedHasChanged) { |
98 | | - $hasChanged = true; |
99 | | - } |
100 | | - } |
101 | | - |
102 | | - if ($hasChanged) { |
103 | | - $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node); |
104 | | - |
105 | | - return $node; |
106 | | - } |
107 | | - |
108 | | - return null; |
| 61 | + throw new ShouldNotHappenException(sprintf( |
| 62 | + '"%s" rule is deprecated, as removing an annotation by name is a coding standard concern, not an upgrade path; use a coding standard tool instead', |
| 63 | + self::class |
| 64 | + )); |
109 | 65 | } |
110 | 66 |
|
111 | 67 | /** |
112 | 68 | * @param mixed[] $configuration |
113 | 69 | */ |
114 | 70 | public function configure(array $configuration): void |
115 | 71 | { |
116 | | - Assert::allString($configuration); |
117 | | - |
118 | | - $this->annotationsToRemove = $configuration; |
119 | 72 | } |
120 | 73 | } |
0 commit comments