NamespaceReplacement::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\PhpGenerics\Generator\Visitor;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Name;
7
use PhpParser\Node\Stmt\Namespace_;
8
use PhpParser\NodeVisitorAbstract;
9
10
final class NamespaceReplacement extends NodeVisitorAbstract
11
{
12
    /** @var string */
13
    private $namespace;
14
15
    public function __construct(string $namespace)
16
    {
17
        $this->namespace = $namespace;
18
    }
19
20
    public function enterNode(Node $node)
21
    {
22
        if (!$node instanceof Namespace_) {
23
            return null;
24
        }
25
        return new Namespace_(
26
            new Name($this->namespace),
27
            $node->stmts,
28
            $node->getAttributes()
29
        );
30
    }
31
}
32