Skip to content

Commit 8d6d472

Browse files
authored
[depre] Deprecate AddParentSetupCallOnSetupRector as not generic to be automated, fill manually where needed (#565)
1 parent e3f0297 commit 8d6d472

File tree

6 files changed

+4
-164
lines changed

6 files changed

+4
-164
lines changed

rules-tests/CodeQuality/Rector/Class_/AddParentSetupCallOnSetupRector/AddParentSetupCallOnSetupRectorTest.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/Class_/AddParentSetupCallOnSetupRector/Fixture/missing_setup.php.inc

Lines changed: 0 additions & 30 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/Class_/AddParentSetupCallOnSetupRector/Fixture/missing_setup_with_other_stmt.php.inc

Lines changed: 0 additions & 30 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/Class_/AddParentSetupCallOnSetupRector/Fixture/skip_setup_exists.php.inc

Lines changed: 0 additions & 14 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/Class_/AddParentSetupCallOnSetupRector/config/configured_rule.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

rules/CodeQuality/Rector/Class_/AddParentSetupCallOnSetupRector.php

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,17 @@
55
namespace Rector\PHPUnit\CodeQuality\Rector\Class_;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\Expr\StaticCall;
9-
use PhpParser\Node\Identifier;
10-
use PhpParser\Node\Name;
118
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;
1610
use Rector\Rector\AbstractRector;
17-
use Rector\ValueObject\MethodName;
1811
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1912
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2013

2114
/**
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
2316
*/
2417
final class AddParentSetupCallOnSetupRector extends AbstractRector
2518
{
26-
public function __construct(
27-
private readonly TestsNodeAnalyzer $testsNodeAnalyzer,
28-
private readonly BetterNodeFinder $betterNodeFinder,
29-
) {
30-
}
31-
3219
public function getRuleDefinition(): RuleDefinition
3320
{
3421
return new RuleDefinition(
@@ -76,43 +63,8 @@ public function getNodeTypes(): array
7663
*/
7764
public function refactor(Node $node): ?Node
7865
{
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)
10568
);
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;
11769
}
11870
}

0 commit comments

Comments
 (0)