|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Churn\Result; |
|
4
|
|
|
|
|
5
|
|
|
class ResultAccumulator |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var integer |
|
9
|
|
|
*/ |
|
10
|
|
|
private $maxCommits; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var integer |
|
14
|
|
|
*/ |
|
15
|
|
|
private $maxComplexity; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var integer |
|
19
|
|
|
*/ |
|
20
|
|
|
private $numberOfFiles; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var HighestScores |
|
24
|
|
|
*/ |
|
25
|
|
|
private $highestScores; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var float|null |
|
29
|
|
|
*/ |
|
30
|
|
|
private $minScore; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param int $maxSize The maximum number of files to display in the results table. |
|
34
|
|
|
* @param float|null $minScore The minimum score a file need to display in the results table. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(int $maxSize, ?float $minScore) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->maxCommits = 0; |
|
39
|
|
|
$this->maxComplexity = 0; |
|
40
|
|
|
$this->numberOfFiles = 0; |
|
41
|
|
|
$this->minScore = $minScore; |
|
42
|
|
|
$this->highestScores = new HighestScores($maxSize); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param Result $result The result for a file. |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
public function add(Result $result): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->numberOfFiles++; |
|
52
|
|
|
if ($result->getCommits() > $this->maxCommits) { |
|
53
|
|
|
$this->maxCommits = $result->getCommits(); |
|
54
|
|
|
} |
|
55
|
|
|
if ($result->getComplexity() > $this->maxComplexity) { |
|
56
|
|
|
$this->maxComplexity = $result->getComplexity(); |
|
57
|
|
|
} |
|
58
|
|
|
$this->highestScores->add($result); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Returns the maximum number of changes for a file. |
|
63
|
|
|
* @return integer |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getMaxCommits(): int |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->maxCommits; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the maximum complexity for a file. |
|
72
|
|
|
* @return integer |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getMaxComplexity(): int |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->maxComplexity; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Returns the number of files processed. |
|
81
|
|
|
* @return integer |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getNumberOfFiles(): int |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->numberOfFiles; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
public function toArray(): array |
|
92
|
|
|
{ |
|
93
|
|
|
$rows = []; |
|
94
|
|
|
foreach ($this->highestScores->toArray() as $result) { |
|
95
|
|
|
$score = $result->getScore($this->maxCommits, $this->maxComplexity); |
|
96
|
|
|
if ($this->minScore !== null && $score < $this->minScore) { |
|
97
|
|
|
break; |
|
98
|
|
|
} |
|
99
|
|
|
$rows[] = [ |
|
100
|
|
|
$result->getFile(), |
|
101
|
|
|
$result->getCommits(), |
|
102
|
|
|
$result->getComplexity(), |
|
103
|
|
|
$score, |
|
104
|
|
|
]; |
|
105
|
|
|
} |
|
106
|
|
|
return $rows; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|