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> |
|
|
|
|
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)]; |
|
|
|
|
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)]; |
|
|
|
|
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
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths