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

UseNamespaceScoperNodeVisitor::enterNode()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 6
nc 2
nop 1
dl 0
loc 11
ccs 0
cts 6
cp 0
crap 30
rs 8.8571
c 0
b 0
f 0
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