ParseClassFqnNodeVisitor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
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 3
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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\ClassDependencies;
9
use PhpParser\Node;
10
use PhpParser\Node\Stmt\Class_;
11
use PhpParser\Node\Stmt\Enum_;
12
use PhpParser\Node\Stmt\Interface_;
13
use PhpParser\Node\Stmt\Namespace_;
14
use PhpParser\Node\Stmt\Trait_;
15
use PhpParser\NodeVisitorAbstract;
16
17
final class ParseClassFqnNodeVisitor extends NodeVisitorAbstract
18
{
19
    private ?string $namespace = null;
20
    private ?string $className = null;
21
22 4
    public function __construct(
23
        private readonly ClassDependencies $classDependencies,
24
    ) {
25 4
    }
26
27 4
    public function enterNode(Node $node): int|Node|null
28
    {
29 4
        if ($node instanceof Namespace_) {
30 4
            $this->namespace = (string) $node->name;
31
        }
32
33 4
        if ($node instanceof Class_ || $node instanceof Trait_ || $node instanceof Interface_ || $node instanceof Enum_) {
34 4
            $this->className = (string) $node->name;
35
        }
36
37 4
        if ($this->namespace !== null && $this->className !== null) {
38 4
            $this->classDependencies->setFqn(new Fqn(sprintf('%s\%s', $this->namespace, $this->className)));
39
        }
40
41 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...
42
    }
43
}
44