|
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 FileFinder $fileFinder, |
|
27
|
|
|
private Parser $parser, |
|
28
|
|
|
private NodeTraverser $nodeTraverser, |
|
29
|
|
|
) { |
|
30
|
3 |
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function addFile(string ...$files) : self |
|
33
|
|
|
{ |
|
34
|
1 |
|
$this->files = [...$this->files, ...array_values($files)]; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
1 |
|
return $this; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
2 |
|
public function addDirectory(string ...$directories) : self |
|
40
|
|
|
{ |
|
41
|
2 |
|
$this->files = [...$this->files, ...$this->fileFinder->getFiles(...$directories)]; |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
2 |
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
public function reflect() : self |
|
47
|
|
|
{ |
|
48
|
1 |
|
$this->nodeTraverser->addVisitor( |
|
49
|
1 |
|
$visitor = new FqcnNodeVisitor(), |
|
50
|
1 |
|
); |
|
51
|
|
|
|
|
52
|
1 |
|
foreach ($this->files as $file) { |
|
53
|
1 |
|
$ast = $this->parser->parse((string) file_get_contents($file)); |
|
54
|
|
|
|
|
55
|
1 |
|
if ($ast === null) { |
|
56
|
|
|
continue; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
$this->nodeTraverser->traverse($ast); |
|
60
|
|
|
|
|
61
|
1 |
|
$fqcn = $visitor->getFqcn(); |
|
62
|
|
|
|
|
63
|
1 |
|
if ($fqcn === null) { |
|
64
|
|
|
continue; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
$this->classes[] = new ReflectionClass($fqcn); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
2 |
|
public function getFiles() : array |
|
74
|
|
|
{ |
|
75
|
2 |
|
return $this->files; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
public function getClasses() : array |
|
79
|
|
|
{ |
|
80
|
1 |
|
return $this->classes; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
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