-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathMethodCallNameAnalyzer.php
More file actions
51 lines (40 loc) · 1.21 KB
/
MethodCallNameAnalyzer.php
File metadata and controls
51 lines (40 loc) · 1.21 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
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Rector\Php70\NodeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
final class MethodCallNameAnalyzer
{
public function isLocalMethodCallNamed(Expr $expr, string $desiredMethodName): bool
{
if (! $expr instanceof MethodCall) {
return false;
}
if (! $expr->var instanceof Variable) {
return false;
}
if ($expr->var->name !== 'this') {
return false;
}
if (! $expr->name instanceof Identifier) {
return false;
}
return $expr->name->toString() === $desiredMethodName;
}
public function isParentMethodCall(Class_ $class, Expr $expr): bool
{
if (! $class->extends instanceof Name) {
return false;
}
$parentClassName = $class->extends->toString();
if ($class->getMethod($parentClassName) instanceof ClassMethod) {
return false;
}
return $this->isLocalMethodCallNamed($expr, $parentClassName);
}
}