ParseImportedFqnNodeVisitor   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 10
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A enterNode() 0 17 6
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jerowork\ClassDependenciesParser\PhpParser\NodeVisitor;
6
7
use Jerowork\ClassDependenciesParser\Fqn;
8
use Jerowork\ClassDependenciesParser\ImportedFqn;
9
use Jerowork\ClassDependenciesParser\ClassDependencies;
10
use PhpParser\Node;
11
use PhpParser\Node\Stmt\GroupUse;
12
use PhpParser\Node\Stmt\Use_;
13
use PhpParser\NodeVisitorAbstract;
14
15
final class ParseImportedFqnNodeVisitor extends NodeVisitorAbstract
16
{
17 4
    public function __construct(
18
        private readonly ClassDependencies $classDependencies,
19
    ) {
20 4
    }
21
22 4
    public function enterNode(Node $node): int|Node|null
23
    {
24 4
        if (!$node instanceof Use_ && !$node instanceof GroupUse) {
25 4
            return parent::enterNode($node);
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::enterNode($node) targeting PhpParser\NodeVisitorAbstract::enterNode() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
26
        }
27
28 4
        $prefix = $node instanceof GroupUse ? sprintf('%s\\', $node->prefix) : '';
29
30 4
        foreach ($node->uses as $use) {
31 4
            $this->classDependencies->addImportedFqn(new ImportedFqn(
32 4
                new Fqn($prefix . $use->name),
33 4
                true,
34 4
                $use->alias !== null ? (string) $use->alias : null,
35 4
            ));
36
        }
37
38 4
        return parent::enterNode($node);
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::enterNode($node) targeting PhpParser\NodeVisitorAbstract::enterNode() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
39
    }
40
}
41