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

Digraph   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
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
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