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

UseNamespaceScoperNodeVisitor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

2 Methods

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