OriginalNameResolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
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;
16
17
use PhpParser\Node\Name;
18
19
// TODO: review those classes
20
final class OriginalNameResolver
21
{
22
    private const ORIGINAL_NAME_ATTRIBUTE = 'originalName';
23
24
    public static function hasOriginalName(Name $namespace): bool
25
    {
26
        return $namespace->hasAttribute(self::ORIGINAL_NAME_ATTRIBUTE);
27
    }
28
29
    public static function getOriginalName(Name $name): Name
30
    {
31
        if (!self::hasOriginalName($name)) {
32
            return $name;
33
        }
34
35
        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...
36
    }
37
38
    private function __construct()
39
    {
40
    }
41
}
42