|
5 | 5 | namespace Rector\PHPUnit\CodeQuality\Rector\Class_; |
6 | 6 |
|
7 | 7 | use PhpParser\Node; |
8 | | -use PhpParser\Node\Expr\StaticCall; |
9 | | -use PhpParser\Node\Identifier; |
10 | | -use PhpParser\Node\Name; |
11 | 8 | use PhpParser\Node\Stmt\Class_; |
12 | | -use PhpParser\Node\Stmt\ClassMethod; |
13 | | -use PhpParser\Node\Stmt\Expression; |
14 | | -use Rector\PhpParser\Node\BetterNodeFinder; |
15 | | -use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; |
| 9 | +use Rector\Exception\ShouldNotHappenException; |
16 | 10 | use Rector\Rector\AbstractRector; |
17 | | -use Rector\ValueObject\MethodName; |
18 | 11 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
19 | 12 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
20 | 13 |
|
21 | 14 | /** |
22 | | - * @see \Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\AddParentSetupCallOnSetupRector\AddParentSetupCallOnSetupRectorTest |
| 15 | + * @deprecated as parent setup call depends on the test. Sometimes its on purpose, sometimes not. Better handle manually |
23 | 16 | */ |
24 | 17 | final class AddParentSetupCallOnSetupRector extends AbstractRector |
25 | 18 | { |
26 | | - public function __construct( |
27 | | - private readonly TestsNodeAnalyzer $testsNodeAnalyzer, |
28 | | - private readonly BetterNodeFinder $betterNodeFinder, |
29 | | - ) { |
30 | | - } |
31 | | - |
32 | 19 | public function getRuleDefinition(): RuleDefinition |
33 | 20 | { |
34 | 21 | return new RuleDefinition( |
@@ -76,43 +63,8 @@ public function getNodeTypes(): array |
76 | 63 | */ |
77 | 64 | public function refactor(Node $node): ?Node |
78 | 65 | { |
79 | | - if (! $this->testsNodeAnalyzer->isInTestClass($node)) { |
80 | | - return null; |
81 | | - } |
82 | | - |
83 | | - $setUpMethod = $node->getMethod(MethodName::SET_UP); |
84 | | - if (! $setUpMethod instanceof ClassMethod) { |
85 | | - return null; |
86 | | - } |
87 | | - |
88 | | - if ($setUpMethod->isAbstract() || $setUpMethod->stmts === null) { |
89 | | - return null; |
90 | | - } |
91 | | - |
92 | | - $isSetupExists = (bool) $this->betterNodeFinder->findFirstInFunctionLikeScoped( |
93 | | - $setUpMethod, |
94 | | - function (Node $subNode): bool { |
95 | | - if (! $subNode instanceof StaticCall) { |
96 | | - return false; |
97 | | - } |
98 | | - |
99 | | - if (! $this->isName($subNode->class, 'parent')) { |
100 | | - return false; |
101 | | - } |
102 | | - |
103 | | - return $this->isName($subNode->name, 'setUp'); |
104 | | - } |
| 66 | + throw new ShouldNotHappenException( |
| 67 | + sprintf('Rule "%s" is deprecated. Better add parent::setUp() manually where needed.', self::class) |
105 | 68 | ); |
106 | | - |
107 | | - if ($isSetupExists) { |
108 | | - return null; |
109 | | - } |
110 | | - |
111 | | - $setUpMethod->stmts = [ |
112 | | - new Expression(new StaticCall(new Name('parent'), new Identifier('setUp'))), |
113 | | - ...$setUpMethod->stmts, |
114 | | - ]; |
115 | | - |
116 | | - return $node; |
117 | 69 | } |
118 | 70 | } |
0 commit comments