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

UseStmtCollector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A enterNode() 0 10 2
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