Passed
Push — cleanup ( 1df3c6...d09870 )
by Luis
12:15
created

ClassVisitor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A leaveNode() 0 4 2
A __construct() 0 4 1
1
<?php
2
/**
3
 * PHP version 7.1
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\Raw\Visitors;
9
10
use PhpParser\Node;
11
use PhpParser\Node\Stmt\Class_;
12
use PhpParser\NodeVisitorAbstract;
13
use PhUml\Parser\Raw\Builders\ClassBuilder;
14
use PhUml\Parser\Raw\RawDefinitions;
15
16
/**
17
 * It extracts the `RawDefinition` of a class and adds it to the collection of `RawDefinitions`
18
 */
19
class ClassVisitor extends NodeVisitorAbstract
20
{
21
    /** @var RawDefinitions */
22
    private $definitions;
23
24
    /** @var ClassBuilder */
25
    private $builder;
26
27
    public function __construct(RawDefinitions $definitions, ClassBuilder $builder = null)
28
    {
29
        $this->definitions = $definitions;
30
        $this->builder = $builder ?? new ClassBuilder();
31
    }
32
33
    public function leaveNode(Node $node)
34
    {
35
        if ($node instanceof Class_) {
36
            $this->definitions->add($this->builder->build($node));
37
        }
38
    }
39
}
40