FqcnNodeVisitor::getFqcn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Enum_;
10
use PhpParser\Node\Stmt\Interface_;
11
use PhpParser\Node\Stmt\Namespace_;
12
use PhpParser\Node\Stmt\Trait_;
13
use PhpParser\NodeVisitorAbstract;
14
15
final class FqcnNodeVisitor extends NodeVisitorAbstract
16
{
17
    private ?string $namespace = null;
18
    private ?string $className = null;
19
20
    /**
21
     * @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...
22
     */
23
    private ?string $fqcn = null;
24
25 1
    public function enterNode(Node $node) : null|array|int|Node
26
    {
27 1
        if ($node instanceof Namespace_) {
28 1
            $this->namespace = (string) $node->name;
29
        }
30
31 1
        if ($node instanceof Class_ || $node instanceof Trait_ || $node instanceof Interface_ || $node instanceof Enum_) {
32 1
            $this->className = (string) $node->name;
33
34
            /** @var class-string $fqcn */
35 1
            $fqcn       = $this->className;
36 1
            $this->fqcn = $fqcn;
37
        }
38
39 1
        if ($this->namespace !== null && $this->className !== null) {
40
            /** @var class-string $fqcn */
41 1
            $fqcn = sprintf('%s\%s', $this->namespace, $this->className);
42
43 1
            $this->fqcn = $fqcn;
44
        }
45
46 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...
47
    }
48
49
    /**
50
     * @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...
51
     */
52 1
    public function getFqcn() : ?string
53
    {
54 1
        return $this->fqcn;
55
    }
56
}
57