Passed
Push — parser-refactoring ( e758c6...b54cbd )
by Luis
11:11
created

GraphvizProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 8
rs 9.4285
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
namespace PhUml\Processors;
8
9
use PhUml\Code\Structure;
10
use PhUml\Graphviz\ClassGraphElements;
11
use PhUml\Graphviz\Digraph;
12
use PhUml\Graphviz\HtmlLabelStyle;
13
use PhUml\Graphviz\InterfaceGraphElements;
14
use PhUml\Graphviz\NodeLabelBuilder;
15
use Twig_Environment as TemplateEngine;
16
use Twig_Loader_Filesystem as Filesystem;
17
18
class GraphvizProcessor extends Processor
19
{
20
    /** @var Digraph */
21
    private $digraph;
22
23
    public function __construct(bool $createAssociations, Digraph $digraph = null)
24
    {
25
        $labelBuilder = new NodeLabelBuilder(new TemplateEngine(
26
            new FileSystem(__DIR__ . '/../Graphviz/templates')
27
        ), new HtmlLabelStyle());
28
        $classElements = new ClassGraphElements($createAssociations, $labelBuilder);
29
        $interfaceElements = new InterfaceGraphElements($labelBuilder);
30
        $this->digraph = $digraph ?? new Digraph($interfaceElements, $classElements);
31
    }
32
33
    public function name(): string
34
    {
35
        return 'Graphviz';
36
    }
37
38
    public function process(Structure $structure): string
39
    {
40
        $this->digraph->fromCodeStructure($structure);
41
42
        return $this->digraph->toDotLanguage();
43
    }
44
}
45