Passed
Push — master ( e86da3...7acf89 )
by BruceScrutinizer
09:02
created

GraphicsDevice::getIdFromNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

27
            $blue = $graph->createVertex(/** @scrutinizer ignore-type */ $processedFileResult->getFileName(), true);
Loading history...
28
            $blue->setAttribute('graphviz.color', 'blue');
29
        }
30
31
        foreach ($processedFileResult->getConflicts() as $conflict) {
32
            $red = $graph->createVertex($conflict->get(), true);
33
            $red->setAttribute('graphviz.color', 'red');
34
35
            $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...
36
            $edge->setAttribute('graphviz.color', 'grey');
37
        }
38
    }
39
40
}
41