Completed
Push — master ( dcddf7...d2fb4d )
by Théo
05:16 queued 03:22
created

ScopeNamespaceStmtNodeVisitor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 4
loc 4
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\Stmt\Namespace_;
20
use PhpParser\NodeVisitorAbstract;
21
22
/**
23
 * Scopes the relevant namespaces.
24
 *
25
 * ```
26
 * namespace Foo;
27
 * ```
28
 *
29
 * =>
30
 *
31
 * ```
32
 * namespace Humbug\Foo;
33
 * ```
34
 */
35 View Code Duplication
final class ScopeNamespaceStmtNodeVisitor extends NodeVisitorAbstract
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
{
37
    private $prefix;
38
39
    public function __construct(string $prefix)
40
    {
41
        $this->prefix = $prefix;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function enterNode(Node $node): Node
48
    {
49
        if ($node instanceof Namespace_
50
            && null !== $node->name
51
            && $this->prefix !== $node->name->getFirst()
52
        ) {
53
            $node->name = Name::concat($this->prefix, $node->name);
54
        }
55
56
        return $node;
57
    }
58
}
59