|
8 | 8 | use PhpParser\Node\Expr\MethodCall; |
9 | 9 | use PhpParser\Node\Expr\StaticCall; |
10 | 10 | use PhpParser\Node\Stmt\Class_; |
11 | | -use PHPStan\Reflection\ClassReflection; |
12 | | -use PHPStan\Type\ObjectType; |
| 11 | +use Rector\PHPUnit\CodeQuality\NodeAnalyser\AssertMethodAnalyzer; |
13 | 12 | use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; |
14 | 13 | use Rector\Rector\AbstractRector; |
15 | | -use Rector\Reflection\ReflectionResolver; |
16 | 14 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
17 | 15 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
18 | 16 |
|
19 | 17 | /** |
20 | | - * @see \Rector\PHPUnit\Tests\Rector\Class_\PreferPHPUnitSelfCallRector\PreferPHPUnitSelfCallRectorTest |
| 18 | + * @see \Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\PreferPHPUnitSelfCallRector\PreferPHPUnitSelfCallRectorTest |
21 | 19 | */ |
22 | 20 | final class PreferPHPUnitSelfCallRector extends AbstractRector |
23 | 21 | { |
24 | 22 | public function __construct( |
25 | 23 | private readonly TestsNodeAnalyzer $testsNodeAnalyzer, |
26 | | - private readonly ReflectionResolver $reflectionResolver, |
| 24 | + private readonly AssertMethodAnalyzer $assertMethodAnalyzer, |
27 | 25 | ) { |
28 | 26 | } |
29 | 27 |
|
@@ -81,39 +79,18 @@ public function refactor(Node $node): ?Node |
81 | 79 | return null; |
82 | 80 | } |
83 | 81 |
|
84 | | - $methodName = $this->getName($node->name); |
85 | | - if (! is_string($methodName)) { |
86 | | - return null; |
87 | | - } |
88 | | - |
89 | | - if (! str_starts_with($methodName, 'assert')) { |
90 | | - return null; |
91 | | - } |
92 | | - |
93 | | - if (! $this->isName($node->var, 'this')) { |
| 82 | + if ($node->isFirstClassCallable()) { |
94 | 83 | return null; |
95 | 84 | } |
96 | 85 |
|
97 | | - if (! $this->isObjectType($node->var, new ObjectType('PHPUnit\Framework\TestCase'))) { |
| 86 | + if (! $this->assertMethodAnalyzer->detectTestCaseCall($node)) { |
98 | 87 | return null; |
99 | 88 | } |
100 | 89 |
|
101 | | - $classReflection = $this->reflectionResolver->resolveClassReflection($node); |
102 | | - if ($classReflection instanceof ClassReflection && $classReflection->hasNativeMethod($methodName)) { |
103 | | - $method = $classReflection->getNativeMethod($methodName); |
104 | | - |
105 | | - if ($node->isFirstClassCallable()) { |
106 | | - return null; |
107 | | - } |
108 | | - |
109 | | - if ($method->isStatic()) { |
110 | | - $hasChanged = true; |
111 | | - |
112 | | - return $this->nodeFactory->createStaticCall('self', $methodName, $node->getArgs()); |
113 | | - } |
114 | | - } |
| 90 | + $methodName = $this->getName($node->name); |
115 | 91 |
|
116 | | - return null; |
| 92 | + $hasChanged = true; |
| 93 | + return $this->nodeFactory->createStaticCall('self', $methodName, $node->getArgs()); |
117 | 94 | }); |
118 | 95 |
|
119 | 96 | if ($hasChanged) { |
|
0 commit comments