|
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); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
37
|
|
|
$edge->setAttribute('graphviz.color', 'grey'); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getIdFromNamespace(string $nameSpace): string |
|
42
|
|
|
{ |
|
43
|
|
|
return $nameSpace; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|