-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathFuncCallNameResolver.php
More file actions
58 lines (48 loc) · 1.47 KB
/
FuncCallNameResolver.php
File metadata and controls
58 lines (48 loc) · 1.47 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
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace Rector\NodeNameResolver\NodeNameResolver;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
/**
* @implements NodeNameResolverInterface<FuncCall>
*/
final readonly class FuncCallNameResolver implements NodeNameResolverInterface
{
public function __construct(
private ReflectionProvider $reflectionProvider
) {
}
public function getNode(): string
{
return FuncCall::class;
}
/**
* If some function is namespaced, it will be used over global one.
* But only if it really exists.
*
* @param FuncCall $node
*/
public function resolve(Node $node, ?Scope $scope): ?string
{
if ($node->name instanceof Expr) {
return null;
}
$namespaceName = $node->name->getAttribute(AttributeKey::NAMESPACED_NAME);
if ($namespaceName instanceof FullyQualified) {
$functionFqnName = $namespaceName->toString();
if ($this->reflectionProvider->hasFunction($namespaceName, null)) {
return $functionFqnName;
}
}
if (is_string($namespaceName)) {
return $namespaceName;
}
return (string) $node->name;
}
}