1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the humbug/php-scoper package. |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2017 Théo FIDRY <[email protected]>, |
9
|
|
|
* Pádraic Brady <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Humbug\PhpScoper\PhpParser\NodeVisitor\Resolver; |
16
|
|
|
|
17
|
|
|
use Humbug\PhpScoper\PhpParser\Node\FullyQualifiedFactory; |
18
|
|
|
use Humbug\PhpScoper\PhpParser\Node\NamedIdentifier; |
19
|
|
|
use Humbug\PhpScoper\PhpParser\NodeVisitor\NamespaceStmt\NamespaceStmtCollection; |
20
|
|
|
use Humbug\PhpScoper\PhpParser\NodeVisitor\NameStmtPrefixer; |
21
|
|
|
use Humbug\PhpScoper\PhpParser\NodeVisitor\ParentNodeAppender; |
22
|
|
|
use Humbug\PhpScoper\PhpParser\NodeVisitor\UseStmt\UseStmtCollection; |
23
|
|
|
use PhpParser\Node; |
24
|
|
|
use PhpParser\Node\Expr\ConstFetch; |
25
|
|
|
use PhpParser\Node\Expr\FuncCall; |
26
|
|
|
use PhpParser\Node\Identifier; |
27
|
|
|
use PhpParser\Node\Name; |
28
|
|
|
use PhpParser\Node\Name\FullyQualified; |
29
|
|
|
use PhpParser\Node\Scalar\String_; |
30
|
|
|
use PhpParser\Node\Stmt\Use_; |
31
|
|
|
use PhpParser\NodeVisitor\NameResolver; |
32
|
|
|
use function count; |
33
|
|
|
use function in_array; |
34
|
|
|
use function ltrim; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Attempts to resolve the identifier node into a fully qualified node. Returns a valid |
38
|
|
|
* (non fully-qualified) name node on failure. |
39
|
|
|
* |
40
|
|
|
* @private |
41
|
|
|
*/ |
42
|
|
|
final class IdentifierResolver |
43
|
|
|
{ |
44
|
|
|
private NameResolver $nameResolver; |
45
|
|
|
|
46
|
|
|
public function __construct(NameResolver $nameResolver) |
47
|
|
|
{ |
48
|
|
|
$this->nameResolver = $nameResolver; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function resolveIdentifier(Identifier $identifier): Name |
52
|
|
|
{ |
53
|
|
|
$name = NamedIdentifier::create($identifier); |
54
|
|
|
|
55
|
|
|
return $this->nameResolver |
56
|
|
|
->getNameContext() |
57
|
|
|
->getResolvedClassName($name); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|