ParseInlineFqnNodeVisitor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 5
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jerowork\ClassDependenciesParser\PhpParser\NodeVisitor;
6
7
use Jerowork\ClassDependenciesParser\ClassDependencies;
8
use Jerowork\ClassDependenciesParser\PhpParser\NodeVisitor\InlineFqnParser\Decliner\InlineFqnDecliner;
9
use Jerowork\ClassDependenciesParser\PhpParser\NodeVisitor\InlineFqnParser\Processor\InlineFqnProcessor;
10
use PhpParser\Node;
11
use PhpParser\Node\Name;
12
use PhpParser\NodeVisitorAbstract;
13
14
final class ParseInlineFqnNodeVisitor extends NodeVisitorAbstract
15
{
16
    /**
17
     * @param iterable<InlineFqnDecliner> $decliners
18
     * @param iterable<InlineFqnProcessor> $processors
19
     */
20 4
    public function __construct(
21
        private readonly ClassDependencies $classDependencies,
22
        private readonly iterable $decliners,
23
        private readonly iterable $processors,
24
    ) {
25 4
    }
26
27 4
    public function enterNode(Node $node): int|Node|null
28
    {
29 4
        if (!$node instanceof Name) {
30 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...
31
        }
32
33
        /** @var Node $parent */
34 4
        $parent = $node->getAttribute('parent');
35
36 4
        foreach ($this->decliners as $decliner) {
37 4
            if ($decliner->shouldDecline($parent, $node, $this->classDependencies)) {
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
42 4
        foreach ($this->processors as $processor) {
43 4
            if (!$processor->shouldProcess($parent, $node, $this->classDependencies)) {
44 4
                continue;
45
            }
46
47 4
            $fqn = $processor->process($parent, $node, $this->classDependencies);
48
49 4
            if ($fqn !== null) {
50 4
                $this->classDependencies->addInlineFqn($fqn);
51
            }
52
53 4
            break;
54
        }
55
56 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...
57
    }
58
}
59