Test Failed
Pull Request — master (#38)
by Sergei
08:01 queued 05:42
created

ClassifierVisitor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A enterNode() 0 13 4
A getClassNames() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Classifier;
6
7
use PhpParser\Node;
8
use PhpParser\NodeVisitorAbstract;
9
10
/**
11
 * @internal Visitor for Classifier
12
 */
13
final class ClassifierVisitor extends NodeVisitorAbstract
14
{
15
    /**
16
     * @var array<class-string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string>.
Loading history...
17
     */
18
    private array $classNames = [];
19
20
    /**
21
     * @param \Closure(class-string): bool $shouldSkipClass
22
     */
23
    public function __construct(private \Closure $shouldSkipClass)
24
    {
25
    }
26
27
    public function enterNode(Node $node)
28
    {
29
        if ($node instanceof Node\Stmt\Class_) {
30
            /**
31
             * @psalm-var class-string|null $className
32
             */
33
            $className = $node->namespacedName?->toString();
34
            if ($className !== null && !($this->shouldSkipClass)($className)) {
35
                $this->classNames[] = $className;
36
            }
37
        }
38
39
        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...
40
    }
41
42
    /**
43
     * @return array<class-string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string>.
Loading history...
44
     */
45
    public function getClassNames(): array
46
    {
47
        return $this->classNames;
48
    }
49
}
50