UseStmtCollector::enterNode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 3
cts 3
cp 1
crap 2
rs 10
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\UseStmt;
16
17
use Humbug\PhpScoper\PhpParser\NodeVisitor\NamespaceStmt\NamespaceStmtCollection;
18
use PhpParser\Node;
19
use PhpParser\Node\Stmt\Use_;
20
use PhpParser\NodeVisitorAbstract;
21
22
/**
23
 * Collects all the use statements. This allows us to resolve a class/constant/function call into a fully-qualified
24
 * call.
25
 *
26
 * @private
27
 */
28
final class UseStmtCollector extends NodeVisitorAbstract
29
{
30
    private NamespaceStmtCollection $namespaceStatements;
31
    private UseStmtCollection $useStatements;
32
33
    public function __construct(NamespaceStmtCollection $namespaceStatements, UseStmtCollection $useStatements)
34 549
    {
35
        $this->namespaceStatements = $namespaceStatements;
36 549
        $this->useStatements = $useStatements;
37 549
    }
38
39
    public function enterNode(Node $node): Node
40
    {
41
        if ($node instanceof Use_) {
42
            $namespaceName = $this->namespaceStatements->getCurrentNamespaceName();
43 548
44
            $this->useStatements->add($namespaceName, $node);
45 548
        }
46 264
47
        return $node;
48 264
    }
49
}
50