|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP version 7.4 |
|
4
|
|
|
* |
|
5
|
|
|
* This source file is subject to the license that is bundled with this package in the file LICENSE. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace PhUml\Parser\Code; |
|
9
|
|
|
|
|
10
|
|
|
use PhpParser\Node\Stmt; |
|
|
|
|
|
|
11
|
|
|
use PhpParser\Parser; |
|
|
|
|
|
|
12
|
|
|
use PhpParser\ParserFactory; |
|
|
|
|
|
|
13
|
|
|
use PhUml\Code\Codebase; |
|
14
|
|
|
use PhUml\Parser\Code\Builders\ClassDefinitionBuilder; |
|
15
|
|
|
use PhUml\Parser\Code\Builders\InterfaceDefinitionBuilder; |
|
16
|
|
|
use PhUml\Parser\Code\Builders\TraitDefinitionBuilder; |
|
17
|
|
|
use PhUml\Parser\CodeFinder; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* It traverses the AST of all the files and interfaces found by the `CodeFinder` and builds a |
|
21
|
|
|
* `Codebase` object |
|
22
|
|
|
* |
|
23
|
|
|
* In order to create the collection of definitions it uses the following visitors |
|
24
|
|
|
* |
|
25
|
|
|
* - The `ClassVisitor` which builds `ClassDefinition`s |
|
26
|
|
|
* - The `InterfaceVisitor` which builds `InterfaceDefinition`s |
|
27
|
|
|
* - The `TraitVisitor` which builds `TraitDefinition`s |
|
28
|
|
|
*/ |
|
29
|
|
|
final class PhpCodeParser |
|
30
|
|
|
{ |
|
31
|
|
|
private Parser $parser; |
|
32
|
|
|
|
|
33
|
|
|
private PhpTraverser $traverser; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct( |
|
36
|
|
|
ClassDefinitionBuilder $classBuilder = null, |
|
37
|
|
|
InterfaceDefinitionBuilder $interfaceBuilder = null, |
|
38
|
|
|
TraitDefinitionBuilder $traitBuilder = null |
|
39
|
|
|
) { |
|
40
|
|
|
$this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); |
|
41
|
|
|
$this->traverser = new PhpTraverser( |
|
42
|
|
|
$classBuilder ?? new ClassDefinitionBuilder(), |
|
43
|
|
|
$interfaceBuilder ?? new InterfaceDefinitionBuilder(), |
|
44
|
|
|
$traitBuilder ?? new TraitDefinitionBuilder() |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function parse(CodeFinder $finder): Codebase |
|
49
|
|
|
{ |
|
50
|
|
|
foreach ($finder->files() as $code) { |
|
51
|
|
|
/** @var Stmt[] $nodes Since the parser is run in throw errors mode */ |
|
52
|
|
|
$nodes = $this->parser->parse($code); |
|
53
|
|
|
$this->traverser->traverse($nodes); |
|
54
|
|
|
} |
|
55
|
|
|
return $this->traverser->codebase(); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
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