Test Failed
Push — graphviz-refactoring ( 3f1b14 )
by Luis
02:18
created

plDigraph   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
dl 0
loc 62
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A toDotLanguage() 0 7 1
A __construct() 0 7 1
A elementsToDotLanguage() 0 7 1
A graphId() 0 3 1
A fromCodeStructure() 0 7 4
A interfaceElementsFrom() 0 3 1
A classElementsFrom() 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
class plDigraph implements plHasDotRepresentation
9
{
10
    /** @var plHasDotRepresentation[] */
11
    private $dotElements;
12
13
    /** @var plInterfaceGraphElements */
14
    private $interfaceElements;
15
16
    /** @var plClassGraphElements */
17
    private $classElements;
18
19
    public function __construct(
20
        plInterfaceGraphElements $interfaceElements,
21
        plClassGraphElements $classElements
22
    ) {
23
        $this->dotElements = [];
24
        $this->interfaceElements = $interfaceElements;
25
        $this->classElements = $classElements;
26
    }
27
28
    public function fromCodeStructure(array $structure): void
29
    {
30
        foreach ($structure as $definition) {
31
            if ($definition instanceof plPhpClass) {
32
                $this->classElementsFrom($definition, $structure);
33
            } else if ($definition instanceof plPhpInterface) {
34
                $this->interfaceElementsFrom($definition);
35
            }
36
        }
37
    }
38
39
    private function classElementsFrom(plPhpClass $class, array $structure): void
40
    {
41
        $this->dotElements = array_merge($this->dotElements, $this->classElements->extractFrom($class, $structure));
42
    }
43
44
    private function interfaceElementsFrom(plPhpInterface $interface): void
45
    {
46
        $this->dotElements = array_merge($this->dotElements, $this->interfaceElements->extractFrom($interface));
47
    }
48
49
    public function toDotLanguage(): string
50
    {
51
        return "digraph \"{$this->graphId()}\" {
52
splines = true;
53
overlap = false;
54
mindist = 0.6;
55
{$this->elementsToDotLanguage()}}";
56
    }
57
58
    private function elementsToDotLanguage(): string
59
    {
60
        $dotFormat = array_map(function (plHasDotRepresentation $element) {
61
            return $element->toDotLanguage();
62
        }, $this->dotElements);
63
64
        return implode('', $dotFormat);
65
    }
66
67
    private function graphId(): string
68
    {
69
        return sha1(mt_rand());
0 ignored issues
show
Bug introduced by
The call to mt_rand() has too few arguments starting with min. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        return sha1(/** @scrutinizer ignore-call */ mt_rand());

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
70
    }
71
}
72