NikicParserClassReflector   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 67
ccs 24
cts 26
cp 0.9231
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getClasses() 0 3 1
A reflect() 0 25 4
A addFile() 0 5 1
A addDirectory() 0 5 1
A getFiles() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jerowork\FileClassReflector\NikicParser;
6
7
use Jerowork\FileClassReflector\ClassReflector;
8
use Jerowork\FileClassReflector\FileFinder\FileFinder;
9
use PhpParser\NodeTraverser;
10
use PhpParser\Parser;
11
use ReflectionClass;
12
13
final class NikicParserClassReflector implements ClassReflector
14
{
15
    /**
16
     * @var list<string>
0 ignored issues
show
Bug introduced by
The type Jerowork\FileClassReflector\NikicParser\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
     */
18
    private array $files = [];
19
20
    /**
21
     * @var list<ReflectionClass>
22
     */
23
    private array $classes = [];
24
25 3
    public function __construct(
26
        private readonly FileFinder $fileFinder,
27
        private readonly Parser $parser,
28
        private readonly NodeTraverser $nodeTraverser,
29 3
    ) {}
30
31 1
    public function addFile(string ...$files) : self
32
    {
33 1
        $this->files = [...$this->files, ...array_values($files)];
0 ignored issues
show
Documentation Bug introduced by
It seems like array($this->files, array_values($files)) of type array<integer,array> is incompatible with the declared type Jerowork\FileClassReflector\NikicParser\list of property $files.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
35 1
        return $this;
36
    }
37
38 2
    public function addDirectory(string ...$directories) : self
39
    {
40 2
        $this->files = [...$this->files, ...$this->fileFinder->getFiles(...$directories)];
0 ignored issues
show
Documentation Bug introduced by
It seems like array($this->files, $thi...getFiles($directories)) of type array<integer,array|string[]> is incompatible with the declared type Jerowork\FileClassReflector\NikicParser\list of property $files.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
42 2
        return $this;
43
    }
44
45 1
    public function reflect() : self
46
    {
47 1
        $this->nodeTraverser->addVisitor(
48 1
            $visitor = new FqcnNodeVisitor(),
49 1
        );
50
51 1
        foreach ($this->files as $file) {
52 1
            $ast = $this->parser->parse((string) file_get_contents($file));
53
54 1
            if ($ast === null) {
55
                continue;
56
            }
57
58 1
            $this->nodeTraverser->traverse($ast);
59
60 1
            $fqcn = $visitor->getFqcn();
61
62 1
            if ($fqcn === null) {
63
                continue;
64
            }
65
66 1
            $this->classes[] = new ReflectionClass($fqcn);
67
        }
68
69 1
        return $this;
70
    }
71
72 2
    public function getFiles() : array
73
    {
74 2
        return $this->files;
75
    }
76
77 1
    public function getClasses() : array
78
    {
79 1
        return $this->classes;
80
    }
81
}
82