NamespaceManipulator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getOriginalName() 0 7 2
A hasOriginalName() 0 3 1
A setOriginalName() 0 3 1
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\PhpParser\NodeVisitor\NamespaceStmt;
16
17
use PhpParser\Node\Name;
18
use PhpParser\Node\Stmt\Namespace_;
19
use PhpParser\NodeVisitorAbstract;
20
21
/**
22
 * @private
23
 */
24
final class NamespaceManipulator extends NodeVisitorAbstract
25
{
26
    private const ORIGINAL_NAME_ATTRIBUTE = 'originalName';
27
28
    public static function hasOriginalName(Namespace_ $namespace): bool
29
    {
30
        return $namespace->hasAttribute(self::ORIGINAL_NAME_ATTRIBUTE);
31
    }
32
33
    public static function getOriginalName(Namespace_ $namespace): ?Name
34
    {
35
        if (!self::hasOriginalName($namespace)) {
36
            return $namespace->name;
37
        }
38
39
        return $namespace->getAttribute(self::ORIGINAL_NAME_ATTRIBUTE);
40
    }
41
42
    public static function setOriginalName(Namespace_ $namespace, ?Name $originalName): void
43
    {
44
        $namespace->setAttribute(self::ORIGINAL_NAME_ATTRIBUTE, $originalName);
45
    }
46
47
    private function __construct()
48
    {
49
    }
50
}
51