Completed
Push — master ( 74c262...0b4843 )
by Théo
03:38 queued 01:33
created

UseStmtCollector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
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\NodeVisitor\UseStmt;
16
17
use Humbug\PhpScoper\NodeVisitor\Collection\NamespaceStmtCollection;
18
use Humbug\PhpScoper\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
final class UseStmtCollector extends NodeVisitorAbstract
28
{
29
    private $namespaceStatements;
30
    private $useStatements;
31
32
    public function __construct(NamespaceStmtCollection $namespaceStatements, UseStmtCollection $useStatements)
33
    {
34
        $this->namespaceStatements = $namespaceStatements;
35
        $this->useStatements = $useStatements;
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function enterNode(Node $node): Node
42
    {
43
        if ($node instanceof Use_) {
44
            $namespaceName = $this->namespaceStatements->getCurrentNamespaceName();
45
46
            $this->useStatements->add($namespaceName, $node);
47
        }
48
49
        return $node;
50
    }
51
}
52