ParentBypass::enterNode()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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