Passed
Pull Request — master (#510)
by Théo
04:10
created

OriginalNameResolver::setOriginalName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Humbug\PhpScoper\PhpParser\NodeVisitor;
6
7
use PhpParser\Node\Name;
8
9
// TODO: review those classes
10
final class OriginalNameResolver
11
{
12
    private const ORIGINAL_NAME_ATTRIBUTE = 'originalName';
13
14
    public static function hasOriginalName(Name $namespace): bool
15
    {
16
        return $namespace->hasAttribute(self::ORIGINAL_NAME_ATTRIBUTE);
17
    }
18
19
    public static function getOriginalName(Name $name): Name
20
    {
21
        if (!self::hasOriginalName($name)) {
22
            return $name;
23
        }
24
25
        return $name->getAttribute(self::ORIGINAL_NAME_ATTRIBUTE);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $name->getAttribu...RIGINAL_NAME_ATTRIBUTE) could return the type null which is incompatible with the type-hinted return PhpParser\Node\Name. Consider adding an additional type-check to rule them out.
Loading history...
26
    }
27
28
    private function __construct()
29
    {
30
    }
31
}
32