Completed
Push — master ( 9d1ab7...13f027 )
by Luis
04:13 queued 02:19
created

GraphvizProcessor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A name() 0 3 1
A process() 0 11 4
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
8
namespace PhUml\Processors;
9
10
use PhUml\Code\ClassDefinition;
11
use PhUml\Code\InterfaceDefinition;
12
use PhUml\Code\Structure;
13
use PhUml\Graphviz\Builders\ClassGraphBuilder;
14
use PhUml\Graphviz\Builders\InterfaceGraphBuilder;
15
use PhUml\Graphviz\Builders\NodeLabelBuilder;
16
use PhUml\Graphviz\Digraph;
17
use PhUml\Templates\TemplateEngine;
18
19
/**
20
 * It creates a digraph from a `Structure` and returns it as a string in DOT format
21
 */
22
class GraphvizProcessor extends Processor
23
{
24
    /** @var ClassGraphBuilder */
25
    private $classBuilder;
26
27
    /** @var InterfaceGraphBuilder */
28
    private $interfaceBuilder;
29
30 57
    public function __construct(
31
        ClassGraphBuilder $classBuilder = null,
32
        InterfaceGraphBuilder $interfaceBuilder = null
33
    ) {
34 57
        $labelBuilder = new NodeLabelBuilder(new TemplateEngine());
35 57
        $this->classBuilder = $classBuilder ?? new ClassGraphBuilder($labelBuilder);
36 57
        $this->interfaceBuilder = $interfaceBuilder ?? new InterfaceGraphBuilder($labelBuilder);
37 57
    }
38
39 21
    public function name(): string
40
    {
41 21
        return 'Graphviz';
42
    }
43
44 42
    public function process(Structure $structure): string
45
    {
46 42
        $digraph = new Digraph();
47 42
        foreach ($structure->definitions() as $definition) {
48 39
            if ($definition instanceof ClassDefinition) {
49 39
                $digraph->add($this->classBuilder->extractFrom($definition, $structure));
50 3
            } elseif ($definition instanceof InterfaceDefinition) {
51 39
                $digraph->add($this->interfaceBuilder->extractFrom($definition));
52
            }
53
        }
54 42
        return $digraph->toDotLanguage();
55
    }
56
}
57