1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Jean-François Lépine <https://twitter.com/Halleck45> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Hal\Application\Formater\Chart; |
11
|
|
|
use Hal\Application\Formater\FormaterInterface; |
12
|
|
|
use Hal\Application\Rule\Validator; |
13
|
|
|
use Hal\Component\Bounds\BoundsInterface; |
14
|
|
|
use Hal\Component\Chart\Graphviz; |
15
|
|
|
use Hal\Component\Result\ResultCollection; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Bubbles generator |
20
|
|
|
* |
21
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
22
|
|
|
*/ |
23
|
|
|
class Bubbles implements FormaterInterface { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Bounds |
27
|
|
|
* |
28
|
|
|
* @var BoundsInterface |
29
|
|
|
*/ |
30
|
|
|
private $bound; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Validator |
34
|
|
|
* |
35
|
|
|
* @var Validator |
36
|
|
|
*/ |
37
|
|
|
private $validator; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Constructor |
41
|
|
|
* |
42
|
|
|
* @param Validator $validator |
43
|
|
|
* @param BoundsInterface $bound |
44
|
|
|
*/ |
45
|
|
|
public function __construct(Validator $validator, BoundsInterface $bound) |
46
|
|
|
{ |
47
|
|
|
$this->bound = $bound; |
48
|
|
|
$this->validator = $validator; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritdoc |
53
|
|
|
*/ |
54
|
|
|
public function terminate(ResultCollection $collection, ResultCollection $groupedResults){ |
55
|
|
|
|
56
|
|
|
$text = 'digraph G {' |
57
|
|
|
. PHP_EOL .'bgcolor=white;' |
58
|
|
|
. PHP_EOL .'node [shape=circle, color=lightblue2, style=filled];'; |
59
|
|
|
|
60
|
|
|
$width = 300; |
61
|
|
|
|
62
|
|
|
foreach($collection as $item) { |
63
|
|
|
|
64
|
|
|
// color |
65
|
|
|
$valid = $this->validator->validate('maintainabilityIndex', $item->getMaintainabilityIndex()->getMaintainabilityIndex()); |
66
|
|
|
switch($valid) { |
67
|
|
|
case Validator::CRITICAL: $color = 'red'; break; |
68
|
|
|
case Validator::GOOD: $color = 'chartreuse4'; break; |
69
|
|
|
case Validator::WARNING: $color = 'gold1'; break; |
70
|
|
|
default: $color = 'grey'; break; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// size |
74
|
|
|
$size = round($item->getMcCabe()->getCyclomaticComplexityNumber() * $width / 100); |
75
|
|
|
|
76
|
|
|
$text .= PHP_EOL. sprintf('"%1$s" [color=%2$s, tooltip="%3$s", width=%4$s, height=%4$s, label=""];' |
77
|
|
|
, $item->getName() |
78
|
|
|
, $color |
79
|
|
|
, $item->getName() |
80
|
|
|
, $size |
81
|
|
|
, $size |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$text .= PHP_EOL.'}'; |
86
|
|
|
|
87
|
|
|
$chart = new Graphviz(); |
88
|
|
|
return $chart->getImage($text); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritdoc |
93
|
|
|
*/ |
94
|
|
|
public function getName() { |
95
|
|
|
return 'Bubbles chart'; |
96
|
|
|
} |
97
|
|
|
} |