Passed
Push — master ( 62af2e...d65fca )
by Théo
07:27 queued 04:04
created

UseStmtCollector::enterNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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