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

GraphvizProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 9
ccs 8
cts 8
cp 1
crap 1
rs 9.6666
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\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