Passed
Push — master ( fa352d...0eb7bd )
by BruceScrutinizer
02:09
created

GraphicsDevice::output()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace NamespaceProtector\OutputDevice;
4
5
use NamespaceProtector\Result\ResultProcessedFile;
6
use NamespaceProtector\Result\ResultProcessorInterface;
7
8
final class GraphicsDevice implements OutputDeviceInterface
9
{
10
11
    public function output(ResultProcessorInterface $value): void
12
    {
13
        $graph = new \Fhaculty\Graph\Graph();
14
        $graph->setAttribute('graphviz.name', 'G');
15
        $graph->setAttribute('graphviz.graph.rankdir', 'LR');
16
17
        foreach ($value->getProcessedResult() as $processedFileResult) {
18
            $this->plot($graph, $processedFileResult);
19
        }
20
21
        $graphviz = new \Graphp\GraphViz\GraphViz();
22
        $graphviz->display($graph);
23
    }
24
25
    public function plot(\Fhaculty\Graph\Graph $graph, ResultProcessedFile $processedFileResult): void
26
    {
27
        if (\count($processedFileResult->getConflicts()) > 0) {
28
            $blue = $graph->createVertex($this->getIdFromNamespace($processedFileResult->get()), true);
0 ignored issues
show
Bug introduced by
$this->getIdFromNamespac...essedFileResult->get()) of type string is incompatible with the type integer|null expected by parameter $id of Fhaculty\Graph\Graph::createVertex(). ( Ignorable by Annotation )

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

28
            $blue = $graph->createVertex(/** @scrutinizer ignore-type */ $this->getIdFromNamespace($processedFileResult->get()), true);
Loading history...
29
            $blue->setAttribute('graphviz.color', 'blue');
30
        }
31
32
        foreach ($processedFileResult->getConflicts() as $conflict) {
33
            $red = $graph->createVertex($this->getIdFromNamespace($conflict->get()), true);
34
            $red->setAttribute('graphviz.color', 'red');
35
36
            $edge = $blue->createEdgeTo($red);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $blue does not seem to be defined for all execution paths leading up to this point.
Loading history...
37
            $edge->setAttribute('graphviz.color', 'grey');
38
        }
39
    }
40
41
    public function getIdFromNamespace(string $nameSpace): string 
42
    {
43
        return $nameSpace;
44
    }
45
46
}
47