Completed
Push — master ( dcd98f...8e1797 )
by Luis
07:11 queued 02:59
created

GraphvizProcessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A process() 0 5 1
A getInputType() 0 3 1
A __construct() 0 9 1
A getOutputType() 0 3 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\Graphviz\ClassGraphElements;
10
use PhUml\Graphviz\Digraph;
11
use PhUml\Graphviz\HtmlLabelStyle;
12
use PhUml\Graphviz\InterfaceGraphElements;
13
use PhUml\Graphviz\NodeLabelBuilder;
14
use plGraphvizProcessorOptions;
15
use plProcessor;
16
use Twig_Environment as TemplateEngine;
17
use Twig_Loader_Filesystem as Filesystem;
18
19
class GraphvizProcessor extends plProcessor
20
{
21
    /** @var plGraphvizProcessorOptions */
22
    public $options;
23
24
    /** @var Digraph */
25
    private $digraph;
26
27 15
    public function __construct(Digraph $digraph = null)
28
    {
29 15
        $this->options = new plGraphvizProcessorOptions();
30 15
        $labelBuilder = new NodeLabelBuilder(new TemplateEngine(
31 15
            new FileSystem(__DIR__ . '/../Graphviz/templates')
32 15
        ), new HtmlLabelStyle());
33 15
        $classElements = new ClassGraphElements($this->options->createAssociations, $labelBuilder);
0 ignored issues
show
Bug Best Practice introduced by
The property createAssociations does not exist on plGraphvizProcessorOptions. Since you implemented __get, consider adding a @property annotation.
Loading history...
34 15
        $interfaceElements = new InterfaceGraphElements($labelBuilder);
35 15
        $this->digraph = $digraph ?? new Digraph($interfaceElements, $classElements);
36 15
    }
37
38 3
    public function name(): string
39
    {
40 3
        return 'Graphviz';
41
    }
42
43 9
    public function getInputType(): string
44
    {
45 9
        return 'application/phuml-structure';
46
    }
47
48 3
    public function getOutputType(): string
49
    {
50 3
        return 'text/dot';
51
    }
52
53 6
    public function process($input)
54
    {
55 6
        $this->digraph->fromCodeStructure($input);
56
57 6
        return $this->digraph->toDotLanguage();
58
    }
59
}
60