Passed
Push — master ( f58add...4aa999 )
by Luis
54s queued 13s
created

PhpTraverser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 10
ccs 0
cts 0
cp 0
crap 2
rs 10
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;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\Stmt 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...
11
use PhpParser\NodeTraverser;
0 ignored issues
show
Bug introduced by
The type PhpParser\NodeTraverser 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...
12
use PhUml\Code\Codebase;
13
use PhUml\Parser\Code\Builders\ClassDefinitionBuilder;
14
use PhUml\Parser\Code\Builders\InterfaceDefinitionBuilder;
15
use PhUml\Parser\Code\Builders\TraitDefinitionBuilder;
16
use PhUml\Parser\Code\Visitors\ClassVisitor;
17
use PhUml\Parser\Code\Visitors\InterfaceVisitor;
18
use PhUml\Parser\Code\Visitors\TraitVisitor;
19
20
final class PhpTraverser
21
{
22
    protected Codebase $codebase;
23
24
    protected NodeTraverser $traverser;
25
26
    public function __construct(
27
        ClassDefinitionBuilder $classBuilder,
28
        InterfaceDefinitionBuilder $interfaceBuilder,
29
        TraitDefinitionBuilder $traitBuilder
30
    ) {
31
        $this->codebase = new Codebase();
32
        $this->traverser = new NodeTraverser();
33
        $this->traverser->addVisitor(new ClassVisitor($classBuilder, $this->codebase));
34
        $this->traverser->addVisitor(new InterfaceVisitor($interfaceBuilder, $this->codebase));
35
        $this->traverser->addVisitor(new TraitVisitor($traitBuilder, $this->codebase));
36 108
    }
37
38 108
    /**
39 108
     * It will create a `Definition` from the given nodes.
40
     * It will add the `Definition` to the `Codebase`
41 111
     *
42
     * @param Stmt[] $nodes
43 111
     * @see PhpCodeParser::parse()
44
     */
45
    public function traverse(array $nodes): void
46
    {
47
        $this->traverser->traverse($nodes);
48
    }
49
50
    public function codebase(): Codebase
51
    {
52
        return $this->codebase;
53
    }
54
}
55