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\Score; |
11
|
|
|
|
12
|
|
|
use Hal\Application\Score\Factor\ReadabilityFactor; |
13
|
|
|
use Hal\Application\Score\Factor\BugPreventingFactor; |
14
|
|
|
use Hal\Application\Score\Factor\ComplexityFactor; |
15
|
|
|
use Hal\Application\Score\Factor\MaintainabilityFactor; |
16
|
|
|
use Hal\Application\Score\Factor\VolumeFactor; |
17
|
|
|
use Hal\Component\Bounds\BoundsInterface; |
18
|
|
|
use Hal\Component\Result\ResultCollection; |
19
|
|
|
use Hal\Component\Score\ScoringInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Calculate score |
23
|
|
|
* |
24
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
25
|
|
|
*/ |
26
|
|
|
class Scoring implements ScoringInterface{ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Maximal score |
30
|
|
|
*/ |
31
|
|
|
const MAX = 100; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Bounds |
35
|
|
|
* |
36
|
|
|
* @var BoundsInterface |
37
|
|
|
*/ |
38
|
|
|
private $bound; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Constructor |
42
|
|
|
* |
43
|
|
|
* @param BoundsInterface $bound |
44
|
|
|
*/ |
45
|
|
|
public function __construct(BoundsInterface $bound) |
46
|
|
|
{ |
47
|
|
|
$this->bound = $bound; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
*/ |
53
|
|
|
public function calculate(ResultCollection $collection, ResultCollection $groupedResults) { |
54
|
|
|
|
55
|
|
|
$calculator = new Calculator(); |
56
|
|
|
$bound = $this->bound->calculate($collection); |
57
|
|
|
|
58
|
|
|
// list of factors of quality |
59
|
|
|
$factors = array( |
60
|
|
|
new MaintainabilityFactor($calculator) |
61
|
|
|
, new ReadabilityFactor($calculator) |
62
|
|
|
, new ComplexityFactor($calculator) |
63
|
|
|
, new VolumeFactor($calculator) |
64
|
|
|
, new BugPreventingFactor($calculator) |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
// score |
68
|
|
|
$result = new Result; |
69
|
|
|
foreach($factors as $qualityFactor) { |
70
|
|
|
$score = $qualityFactor->calculate($collection, $groupedResults, $bound); |
71
|
|
|
$result->push($qualityFactor->getName(), $score); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $result; |
75
|
|
|
} |
76
|
|
|
} |