Completed
Pull Request — master (#26)
by Pádraic
02:28
created

ignoreUseUses()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
/*
5
 * This file is part of the humbug/php-scoper package.
6
 *
7
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
8
 *                    Pádraic Brady <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Webmozart\PhpScoper\NodeVisitor;
15
16
use PhpParser\Node;
17
use PhpParser\Node\Name;
18
use PhpParser\Node\Stmt\GroupUse;
19
use PhpParser\NodeVisitorAbstract;
20
21
class GroupUseNamespaceScoperNodeVisitor extends NodeVisitorAbstract
22
{
23
    /**
24
     * @var string
25
     */
26
    private $prefix;
27
28
    /**
29
     * @param string $prefix
30
     */
31 16
    public function __construct(string $prefix)
32
    {
33 16
        $this->prefix = $prefix;
34 16
    }
35
36
    /**
37
     * @param Node[] $nodes
38
     */
39 14
    public function beforeTraverse(array $nodes)
40
    {
41 14
        foreach ($nodes as $node) {
42 14
            if ($node instanceof GroupUse) {
43 14
                $this->ignoreUseUses($node);
44
            }
45
        }
46 14
    }
47
48
    /**
49
     * @param Node $node
50
     */
51 14
    public function enterNode(Node $node)
52
    {
53 14
        if ($node instanceof GroupUse) {
54 3
            $node->prefix = Name::concat($this->prefix, $node->prefix);
55
        }
56 14
    }
57
58
    /**
59
     * @param GroupUse $node
60
     */
61 3
    private function ignoreUseUses(GroupUse $node)
62
    {
63 3
        foreach ($node->uses as $use) {
64 3
            $use->setAttribute('phpscoper_ignore', true);
65
        }
66 3
    }
67
}
68