-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathParentCallDetector.php
More file actions
46 lines (35 loc) · 1.08 KB
/
ParentCallDetector.php
File metadata and controls
46 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace Rector\PHPUnit\CodeQuality\NodeAnalyser;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use Rector\NodeNameResolver\NodeNameResolver;
final readonly class ParentCallDetector
{
public function __construct(
private NodeNameResolver $nodeNameResolver
) {
}
public function hasParentCall(ClassMethod $classMethod): bool
{
$methodName = $classMethod->name->toString();
foreach ((array) $classMethod->stmts as $stmt) {
if (! $stmt instanceof Expression) {
continue;
}
if (! $stmt->expr instanceof StaticCall) {
continue;
}
$staticCall = $stmt->expr;
if (! $this->nodeNameResolver->isName($staticCall->class, 'parent')) {
continue;
}
if (! $this->nodeNameResolver->isName($staticCall->name, $methodName)) {
continue;
}
return true;
}
return false;
}
}