Completed
Push — master ( 9d1ab7...13f027 )
by Luis
04:13 queued 02:19
created

GraphvizProcessor::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Processors;
9
10
use PhUml\Code\ClassDefinition;
11
use PhUml\Code\InterfaceDefinition;
12
use PhUml\Code\Structure;
13
use PhUml\Graphviz\Builders\ClassGraphBuilder;
14
use PhUml\Graphviz\Builders\InterfaceGraphBuilder;
15
use PhUml\Graphviz\Builders\NodeLabelBuilder;
16
use PhUml\Graphviz\Digraph;
17
use PhUml\Templates\TemplateEngine;
18
19
/**
20
 * It creates a digraph from a `Structure` and returns it as a string in DOT format
21
 */
22
class GraphvizProcessor extends Processor
23
{
24
    /** @var ClassGraphBuilder */
25
    private $classBuilder;
26
27
    /** @var InterfaceGraphBuilder */
28
    private $interfaceBuilder;
29
30 57
    public function __construct(
31
        ClassGraphBuilder $classBuilder = null,
32
        InterfaceGraphBuilder $interfaceBuilder = null
33
    ) {
34 57
        $labelBuilder = new NodeLabelBuilder(new TemplateEngine());
35 57
        $this->classBuilder = $classBuilder ?? new ClassGraphBuilder($labelBuilder);
36 57
        $this->interfaceBuilder = $interfaceBuilder ?? new InterfaceGraphBuilder($labelBuilder);
37 57
    }
38
39 21
    public function name(): string
40
    {
41 21
        return 'Graphviz';
42
    }
43
44 42
    public function process(Structure $structure): string
45
    {
46 42
        $digraph = new Digraph();
47 42
        foreach ($structure->definitions() as $definition) {
48 39
            if ($definition instanceof ClassDefinition) {
49 39
                $digraph->add($this->classBuilder->extractFrom($definition, $structure));
50 3
            } elseif ($definition instanceof InterfaceDefinition) {
51 39
                $digraph->add($this->interfaceBuilder->extractFrom($definition));
52
            }
53
        }
54 42
        return $digraph->toDotLanguage();
55
    }
56
}
57