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

UseNamespaceScoperNodeVisitor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 19
loc 19
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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