|
1
|
|
|
<?php |
|
2
|
|
|
namespace Hal\Report\Cli; |
|
3
|
|
|
|
|
4
|
|
|
use Hal\Application\Config\Config; |
|
5
|
|
|
use Hal\Component\Output\Output; |
|
6
|
|
|
use Hal\Metric\Consolidated; |
|
7
|
|
|
use Hal\Metric\Metrics; |
|
8
|
|
|
|
|
9
|
|
|
class Reporter |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var Config |
|
14
|
|
|
*/ |
|
15
|
|
|
private $config; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var OutputInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
private $output; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Reporter constructor. |
|
24
|
|
|
* @param Config $config |
|
25
|
|
|
* @param OutputInterface $output |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(Config $config, Output $output) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->config = $config; |
|
30
|
|
|
$this->output = $output; |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
public function generate(Metrics $metrics) |
|
35
|
|
|
{ |
|
36
|
|
|
if ($this->config->has('quiet')) { |
|
37
|
|
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// grouping results |
|
41
|
|
|
$consolidated = new Consolidated($metrics); |
|
42
|
|
|
$sum = $consolidated->getSum(); |
|
43
|
|
|
$avg = $consolidated->getAvg(); |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$methodsByClass = $locByClass = $locByMethod = 0; |
|
47
|
|
|
if ($sum->nbClasses > 0) { |
|
48
|
|
|
$methodsByClass = round($sum->nbMethods / $sum->nbClasses, 2); |
|
49
|
|
|
$locByClass = round($sum->lloc / $sum->nbClasses); |
|
50
|
|
|
} |
|
51
|
|
|
if ($sum->nbMethods > 0) { |
|
52
|
|
|
$locByMethod = round($sum->lloc / $sum->nbMethods); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$out = <<<EOT |
|
56
|
|
|
LOC |
|
57
|
|
|
Lines of code {$sum->loc} |
|
58
|
|
|
Logical lines of code {$sum->lloc} |
|
59
|
|
|
Comment lines of code {$sum->cloc} |
|
60
|
|
|
Average volume {$avg->volume} |
|
61
|
|
|
Average comment weight {$avg->commentWeight} |
|
62
|
|
|
Average intelligent content {$avg->commentWeight} |
|
63
|
|
|
Logical lines of code by class {$locByClass} |
|
64
|
|
|
Logical lines of code by method {$locByMethod} |
|
65
|
|
|
|
|
66
|
|
|
Object oriented programming |
|
67
|
|
|
Classes {$sum->nbClasses} |
|
68
|
|
|
Interface {$sum->nbInterfaces} |
|
69
|
|
|
Methods {$sum->nbMethods} |
|
70
|
|
|
Methods by class {$methodsByClass} |
|
71
|
|
|
Lack of cohesion of methods {$avg->lcom} |
|
72
|
|
|
|
|
73
|
|
|
Coupling |
|
74
|
|
|
Average afferent coupling {$avg->afferentCoupling} |
|
75
|
|
|
Average efferent coupling {$avg->efferentCoupling} |
|
76
|
|
|
Average instability {$avg->instability} |
|
77
|
|
|
Depth of Inheritance Tree {$metrics->get('tree')->get('depthOfInheritanceTree')} |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
Complexity |
|
80
|
|
|
Average Cyclomatic complexity by class {$avg->ccn} |
|
81
|
|
|
Average Relative system complexity {$avg->relativeSystemComplexity} |
|
82
|
|
|
Average Difficulty {$avg->difficulty} |
|
83
|
|
|
|
|
84
|
|
|
Bugs |
|
85
|
|
|
Average bugs by class {$avg->bugs} |
|
86
|
|
|
Average defects by class (Kan) {$avg->kanDefect} |
|
87
|
|
|
|
|
88
|
|
|
Violations |
|
89
|
|
|
Critical {$sum->violations->critical} |
|
90
|
|
|
Error {$sum->violations->error} |
|
91
|
|
|
Warning {$sum->violations->warning} |
|
92
|
|
|
Information {$sum->violations->information} |
|
93
|
|
|
|
|
94
|
|
|
EOT; |
|
95
|
|
|
|
|
96
|
|
|
// git |
|
97
|
|
|
if ($this->config->has('git')) { |
|
98
|
|
|
$commits = []; |
|
99
|
|
|
foreach ($consolidated->getFiles() as $name => $file) { |
|
100
|
|
|
$commits[$name] = $file['gitChanges']; |
|
101
|
|
|
} |
|
102
|
|
|
arsort($commits); |
|
103
|
|
|
$commits = array_slice($commits, 0, 10); |
|
104
|
|
|
|
|
105
|
|
|
$out .= "\nTop 10 committed files"; |
|
106
|
|
|
foreach ($commits as $file => $nb) { |
|
107
|
|
|
$out .= sprintf("\n %d %s", $nb, $file); |
|
108
|
|
|
} |
|
109
|
|
|
if (0 === sizeof($commits)) { |
|
110
|
|
|
$out .= "\n NA"; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
// Junit |
|
115
|
|
|
if ($this->config->has('junit')) { |
|
116
|
|
|
$out .= <<<EOT |
|
117
|
|
|
|
|
118
|
|
|
Unit testing |
|
119
|
|
|
Number of unit tests {$metrics->get('unitTesting')->get('nbTests')} |
|
|
|
|
|
|
120
|
|
|
Classes called by tests {$metrics->get('unitTesting')->get('nbCoveredClasses')} |
|
|
|
|
|
|
121
|
|
|
Classes called by tests (percent) {$metrics->get('unitTesting')->get('percentCoveredClasses')} % |
|
|
|
|
|
|
122
|
|
|
EOT; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
$out .= "\n\n"; |
|
126
|
|
|
$this->output->write($out); |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..