|
5 | 5 | namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod; |
6 | 6 |
|
7 | 7 | use PhpParser\Node; |
8 | | -use PhpParser\Node\AttributeGroup; |
9 | 8 | use PhpParser\Node\Stmt\ClassMethod; |
10 | | -use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; |
11 | | -use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory; |
12 | | -use Rector\PHPUnit\Enum\PHPUnitAttribute; |
13 | | -use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; |
| 9 | +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; |
| 10 | +use Rector\Exception\ShouldNotHappenException; |
14 | 11 | use Rector\Rector\AbstractRector; |
15 | 12 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
16 | 13 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
17 | 14 |
|
18 | 15 | /** |
19 | | - * @see \Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector\ReplaceTestAnnotationWithPrefixedFunctionRectorTest |
| 16 | + * @deprecated This rule is deprecated as it is not a common upgrade path and it is not part of any set. Implement it as a custom rule instead. |
20 | 17 | */ |
21 | | -final class ReplaceTestFunctionPrefixWithAttributeRector extends AbstractRector |
| 18 | +final class ReplaceTestFunctionPrefixWithAttributeRector extends AbstractRector implements DeprecatedInterface |
22 | 19 | { |
23 | | - public function __construct( |
24 | | - private readonly TestsNodeAnalyzer $testsNodeAnalyzer, |
25 | | - private readonly PhpAttributeGroupFactory $phpAttributeGroupFactory, |
26 | | - private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer, |
27 | | - ) { |
28 | | - } |
29 | | - |
30 | 20 | public function getRuleDefinition(): RuleDefinition |
31 | 21 | { |
32 | 22 | return new RuleDefinition('Replace @test with prefixed function', [ |
@@ -68,36 +58,9 @@ public function getNodeTypes(): array |
68 | 58 | */ |
69 | 59 | public function refactor(Node $node): ?Node |
70 | 60 | { |
71 | | - if (! $this->testsNodeAnalyzer->isInTestClass($node)) { |
72 | | - return null; |
73 | | - } |
74 | | - |
75 | | - if (! str_starts_with($node->name->toString(), 'test')) { |
76 | | - return null; |
77 | | - } |
78 | | - |
79 | | - if ($this->phpAttributeAnalyzer->hasPhpAttributes($node, [PHPUnitAttribute::TEST])) { |
80 | | - return null; |
81 | | - } |
82 | | - |
83 | | - if ($node->name->toString() !== 'test' && $node->name->toString() !== 'test_') { |
84 | | - if (str_starts_with($node->name->toString(), 'test_')) { |
85 | | - $node->name->name = lcfirst(substr($node->name->name, 5)); |
86 | | - } elseif (str_starts_with($node->name->toString(), 'test')) { |
87 | | - $node->name->name = lcfirst(substr($node->name->name, 4)); |
88 | | - } |
89 | | - } |
90 | | - |
91 | | - $coversAttributeGroup = $this->createAttributeGroup(); |
92 | | - $node->attrGroups = array_merge($node->attrGroups, [$coversAttributeGroup]); |
93 | | - |
94 | | - return $node; |
95 | | - } |
96 | | - |
97 | | - private function createAttributeGroup(): AttributeGroup |
98 | | - { |
99 | | - $attributeClass = 'PHPUnit\\Framework\\Attributes\\Test'; |
100 | | - |
101 | | - return $this->phpAttributeGroupFactory->createFromClassWithItems($attributeClass, []); |
| 61 | + throw new ShouldNotHappenException(sprintf( |
| 62 | + '"%s" is deprecated and should not be used anymore. Remove it from your config files.', |
| 63 | + self::class, |
| 64 | + )); |
102 | 65 | } |
103 | 66 | } |
0 commit comments