Passed
Push — cleanup ( 1df3c6 )
by Luis
14:39
created

Digraph::elementsToDotLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 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
class Digraph implements HasDotRepresentation
11
{
12
    /** @var HasDotRepresentation[] */
13
    private $dotElements;
14
15
    public function __construct()
16
    {
17
        $this->dotElements = [];
18
    }
19
20
    /** @param HasDotRepresentation[] */
21
    public function add(array $definitions): void
22
    {
23
        $this->dotElements = array_merge($this->dotElements, $definitions);
24
    }
25
26
    public function toDotLanguage(): string
27
    {
28
        return "digraph \"{$this->graphId()}\" {
29
splines = true;
30
overlap = false;
31
mindist = 0.6;
32
{$this->elementsToDotLanguage()}}";
33
    }
34
35
    private function elementsToDotLanguage(): string
36
    {
37
        $dotFormat = array_map(function (HasDotRepresentation $element) {
38
            return $element->toDotLanguage();
39
        }, $this->dotElements);
40
41
        return implode('', $dotFormat);
42
    }
43
44
    private function graphId(): string
45
    {
46
        return sha1(mt_rand());
47
    }
48
}
49