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

GraphvizProcessor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A process() 0 5 1
A __construct() 0 8 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
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