Completed
Push — class-diagram-action ( 94e766 )
by Luis
10:24
created

GraphvizProcessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
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
    public function __construct(Digraph $digraph = null)
28
    {
29
        $this->options = new plGraphvizProcessorOptions();
30
        $labelBuilder = new NodeLabelBuilder(new TemplateEngine(
31
            new FileSystem(__DIR__ . '/../Graphviz/templates')
32
        ), new HtmlLabelStyle());
33
        $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
        $interfaceElements = new InterfaceGraphElements($labelBuilder);
35
        $this->digraph = $digraph ?? new Digraph($interfaceElements, $classElements);
36
    }
37
38
    public function name(): string
39
    {
40
        return 'Graphviz';
41
    }
42
43
    public function getInputType(): string
44
    {
45
        return 'application/phuml-structure';
46
    }
47
48
    public function getOutputType(): string
49
    {
50
        return 'text/dot';
51
    }
52
53
    public function process($input)
54
    {
55
        $this->digraph->fromCodeStructure($input);
56
57
        return $this->digraph->toDotLanguage();
58
    }
59
}
60