Completed
Push — master ( b54cbd...d09870 )
by Luis
18:59
created

Digraph   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toDotLanguage() 0 7 1
A elementsToDotLanguage() 0 7 1
A add() 0 3 1
A __construct() 0 3 1
A graphId() 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
8
namespace PhUml\Graphviz;
9
10
/**
11
 * It is a collection of nodes and edges that can be represented using DOT language
12
 *
13
 * @link https://en.wikipedia.org/wiki/DOT_(graph_description_language) See for more details about DOT language
14
 */
15
class Digraph implements HasDotRepresentation
16
{
17
    /** @var HasDotRepresentation[] */
18
    private $dotElements;
19
20
    public function __construct()
21
    {
22
        $this->dotElements = [];
23
    }
24 42
25
    /** @param HasDotRepresentation[] */
26
    public function add(array $definitions): void
27
    {
28 42
        $this->dotElements = array_merge($this->dotElements, $definitions);
29 42
    }
30 42
31 42
    public function toDotLanguage(): string
32
    {
33 30
        return "digraph \"{$this->graphId()}\" {
34
splines = true;
35 30
overlap = false;
36 24
mindist = 0.6;
37 24
{$this->elementsToDotLanguage()}}";
38 6
    }
39 24
40
    private function elementsToDotLanguage(): string
41
    {
42 30
        $dotFormat = array_map(function (HasDotRepresentation $element) {
43
            return $element->toDotLanguage();
44 24
        }, $this->dotElements);
45
46 24
        return implode('', $dotFormat);
47 24
    }
48
49 6
    private function graphId(): string
50
    {
51 6
        return sha1(mt_rand());
52 6
    }
53
}
54