InstanceOfReplacement::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
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\Instanceof_;
7
use PhpParser\Node\Name;
8
use PhpParser\NodeVisitorAbstract;
9
use Stratadox\PhpGenerics\Generator\Type\TypeArgument;
10
use Stratadox\PhpGenerics\Generator\Type\TypeMap;
11
12
final class InstanceOfReplacement extends NodeVisitorAbstract
13
{
14
    /** @var TypeMap|TypeArgument[] */
15
    private $typeMap;
16
17
    public function __construct(TypeMap $typeMap)
18
    {
19
        $this->typeMap = $typeMap;
20
    }
21
22
    public function leaveNode(Node $node)
23
    {
24
        if (!$node instanceof Instanceof_) {
25
            return null;
26
        }
27
        if (!$node->class instanceof Name) {
28
            return null;
29
        }
30
        if (!isset($this->typeMap[(string) $node->class])) {
31
            return null;
32
        }
33
        return $this->typeMap[(string) $node->class]->typeCheck($node->expr);
34
    }
35
}
36