InstanceOfReplacement   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A leaveNode() 0 12 4
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