Completed
Push — symfony-console-application ( 3187e2...c3ee2a )
by Luis
10:39
created

GraphvizProcessor::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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 Twig_Environment as TemplateEngine;
16
use Twig_Loader_Filesystem as Filesystem;
17
18
class GraphvizProcessor extends Processor
19
{
20
    /** @var plGraphvizProcessorOptions */
21
    public $options;
22
23
    /** @var Digraph */
24
    private $digraph;
25
26
    public function __construct(bool $createAssociations, Digraph $digraph = null)
27
    {
28
        $this->options = new plGraphvizProcessorOptions();
29
        $labelBuilder = new NodeLabelBuilder(new TemplateEngine(
30
            new FileSystem(__DIR__ . '/../Graphviz/templates')
31
        ), new HtmlLabelStyle());
32
        $classElements = new ClassGraphElements($createAssociations, $labelBuilder);
33
        $interfaceElements = new InterfaceGraphElements($labelBuilder);
34
        $this->digraph = $digraph ?? new Digraph($interfaceElements, $classElements);
35
    }
36
37
    public function name(): string
38
    {
39
        return 'Graphviz';
40
    }
41
42
    public function getInputType(): string
43
    {
44
        return 'application/phuml-structure';
45
    }
46
47
    public function getOutputType(): string
48
    {
49
        return 'text/dot';
50
    }
51
52
    public function process($input)
53
    {
54
        $this->digraph->fromCodeStructure($input);
55
56
        return $this->digraph->toDotLanguage();
57
    }
58
}
59