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\Command\Job; |
11
|
|
|
|
12
|
|
|
use Hal\Component\Aggregator\Aggregator; |
13
|
|
|
use Hal\Component\Bounds\Bounds; |
14
|
|
|
use Hal\Component\Result\ResultAggregate; |
15
|
|
|
use Hal\Component\Result\ResultCollection; |
16
|
|
|
use Hal\Metrics\Mood\Abstractness\Abstractness; |
17
|
|
|
use Hal\Metrics\Mood\Instability\Instability; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
23
|
|
|
*/ |
24
|
|
|
class DoAggregatedAnalyze implements JobInterface |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Aggregator of results |
29
|
|
|
* |
30
|
|
|
* @var Aggregator |
31
|
|
|
*/ |
32
|
|
|
private $aggregator; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Output |
36
|
|
|
* |
37
|
|
|
* @var OutputInterface |
38
|
|
|
* |
39
|
|
|
*/ |
40
|
|
|
private $output; |
41
|
|
|
/** |
42
|
|
|
* Constructor |
43
|
|
|
* |
44
|
|
|
* @param OutputInterface $output |
45
|
|
|
* @param Aggregator $aggregator |
46
|
|
|
*/ |
47
|
|
|
public function __construct(OutputInterface $output, Aggregator $aggregator) |
48
|
|
|
{ |
49
|
|
|
$this->aggregator= $aggregator; |
50
|
|
|
$this->output = $output; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritdoc |
56
|
|
|
*/ |
57
|
|
|
public function execute(ResultCollection $collection, ResultCollection $aggregatedResults) { |
58
|
|
|
|
59
|
|
|
$this->output->write(str_pad("\x0DGrouping results by package/directory. This will take few minutes...", 80, "\x20")); |
60
|
|
|
|
61
|
|
|
// Aggregates results |
62
|
|
|
$groupedResults = $this->aggregator->aggregates($collection); |
63
|
|
|
|
64
|
|
|
// metrics tools |
65
|
|
|
$abstractness = new Abstractness(); |
66
|
|
|
$bounds = new Bounds(); |
67
|
|
|
$instability = new Instability(); |
68
|
|
|
|
69
|
|
|
foreach($groupedResults as $namespace => $results) { |
70
|
|
|
|
71
|
|
|
// we filter aggregates to conserve only direct results |
72
|
|
|
$childs = new ResultCollection(); |
73
|
|
|
foreach($results as $r) { |
74
|
|
|
if($namespace === dirname($r->getName())) { |
|
|
|
|
75
|
|
|
$childs->push($r); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
$resultAggregate = new ResultAggregate($namespace); |
79
|
|
|
$resultAggregate |
80
|
|
|
->setAbstractness($abstractness->calculate($results)) |
81
|
|
|
->setInstability($instability->calculate($results)) |
82
|
|
|
->setBounds($bounds->calculate($results)) |
83
|
|
|
->setChilds($childs) |
84
|
|
|
; |
85
|
|
|
|
86
|
|
|
$aggregatedResults->push($resultAggregate); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|