Passed
Push — main ( bf003e...0239c9 )
by Jeroen
01:37
created

FqcnNodeVisitor::enterNode()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 8
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 18
ccs 9
cts 9
cp 1
crap 7
rs 8.8333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jerowork\FileClassReflector\NikicParser;
6
7
use PhpParser\Node;
8
use PhpParser\Node\Stmt\Class_;
9
use PhpParser\Node\Stmt\Interface_;
10
use PhpParser\Node\Stmt\Namespace_;
11
use PhpParser\Node\Stmt\Trait_;
12
use PhpParser\NodeVisitorAbstract;
13
14
final class FqcnNodeVisitor extends NodeVisitorAbstract
15
{
16
    private ?string $namespace  = null;
17
    private ?string $objectName = null;
18
19
    /**
20
     * @var null|class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment null|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in null|class-string.
Loading history...
21
     */
22
    private ?string $fqcn = null;
23
24 1
    public function enterNode(Node $node) : int|Node|null
25
    {
26 1
        if ($node instanceof Namespace_) {
27 1
            $this->namespace = (string) $node->name;
28
        }
29
30 1
        if ($node instanceof Class_ || $node instanceof Trait_ || $node instanceof Interface_) {
31 1
            $this->objectName = (string) $node->name;
32
        }
33
34 1
        if ($this->namespace !== null && $this->objectName !== null) {
35
            /** @var class-string $fqcn */
36 1
            $fqcn = sprintf('%s\%s', $this->namespace, $this->objectName);
37
38 1
            $this->fqcn = $fqcn;
39
        }
40
41 1
        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
    /**
45
     * @return null|class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment null|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in null|class-string.
Loading history...
46
     */
47 1
    public function getFqcn() : ?string
48
    {
49 1
        return $this->fqcn;
50
    }
51
}
52