Passed
Push — master ( 2a3624...3abe14 )
by Théo
03:10
created

UseNamespaceScoperNodeVisitor::enterNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 6
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Humbug\PhpScoper\NodeVisitor;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Name;
7
use PhpParser\Node\Stmt\GroupUse;
8
use PhpParser\Node\Stmt\UseUse;
9
use PhpParser\NodeVisitorAbstract;
10
11
final class UseNamespaceScoperNodeVisitor extends NodeVisitorAbstract
12
{
13
    /**
14
     * @var string
15
     */
16
    private $prefix;
17
18
    public function __construct($prefix)
19
    {
20
        $this->prefix = $prefix;
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function enterNode(Node $node)
27
    {
28
        if ($node instanceof UseUse
29
            && $node->hasAttribute('parent') && false === ($node->getAttribute('parent') instanceof  GroupUse)
30
            && $this->prefix !== $node->name->getFirst()
31
        ) {
32
            $node->name = Name::concat($this->prefix, $node->name);
33
        }
34
35
        return $node;
36
    }
37
}
38