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

Digraph::fromCodeStructure()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 4
nop 1
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 4
rs 9.2
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
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