Passed
Push — master ( d3a94c...76e109 )
by Valentin
05:50
created

UpdateNamespace   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A leaveNode() 0 12 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Cycle\ORM\Promise\Visitor;
5
6
use PhpParser\Node;
7
use PhpParser\NodeVisitorAbstract;
8
9
class UpdateNamespace extends NodeVisitorAbstract
10
{
11
    /** @var string|null */
12
    private $namespace;
13
14
    public function __construct(?string $namespace)
15
    {
16
        $this->namespace = $namespace;
17
    }
18
19
    public function leaveNode(Node $node)
20
    {
21
        if ($node instanceof Node\Stmt\Namespace_) {
22
            if (empty($this->namespace)) {
23
                return $node->stmts;
24
            } else {
25
                $node->name->parts = explode('\\', $this->namespace);
26
            }
27
        }
28
29
        return null;
30
    }
31
}