Completed
Push — master ( a5b8f2...ff87ce )
by Théo
03:58 queued 01:55
created

FullyQualifiedNodeVisitor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper\NodeVisitor;
16
17
use PhpParser\Node;
18
use PhpParser\Node\Name;
19
use PhpParser\Node\Name\FullyQualified;
20
use PhpParser\NodeVisitorAbstract;
21
22
final class FullyQualifiedNodeVisitor extends NodeVisitorAbstract
23
{
24
    private $prefix;
25
26
    public function __construct(string $prefix)
27
    {
28
        $this->prefix = $prefix;
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function enterNode(Node $node)
35
    {
36
        if ($node instanceof FullyQualified
37
            && false === ($node->hasAttribute('phpscoper_ignore')
38
            && true === $node->getAttribute('phpscoper_ignore'))
39
        ) {
40
            return new Name('\\'.Name::concat($this->prefix, (string) $node));
41
        }
42
43
        return $node;
44
    }
45
}
46