ImportDetection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A enterNode() 0 7 3
A tag() 0 3 1
A imports() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\PhpGenerics\Dissector\Visitor;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Stmt\Use_;
7
use PhpParser\Node\Stmt\UseUse;
8
use PhpParser\NodeVisitorAbstract;
9
10
final class ImportDetection extends NodeVisitorAbstract
11
{
12
    /** @var string[] */
13
    private $imports = [];
14
15
    public function enterNode(Node $node)
16
    {
17
        if (!$node instanceof Use_) {
18
            return;
19
        }
20
        foreach ($node->uses as $use) {
21
            $this->imports[$this->tag($use)] = (string) $use->name;
22
        }
23
    }
24
25
    public function imports(): array
26
    {
27
        return $this->imports;
28
    }
29
30
    private function tag(UseUse $use): string
31
    {
32
        return (string) ($use->alias ?? $use->name->getLast());
33
    }
34
}
35