|
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\Rule; |
|
11
|
|
|
use Hal\Component\Result\ExportableInterface; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Rules |
|
16
|
|
|
* |
|
17
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
|
18
|
|
|
*/ |
|
19
|
|
|
class RuleSet implements ExportableInterface { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Rules |
|
23
|
|
|
* for each rule: |
|
24
|
|
|
* 0 => CRITICAL limit |
|
25
|
|
|
* 1 => WARNING limit |
|
26
|
|
|
* 2 => GOOD limit |
|
27
|
|
|
* |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
private $rules; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Constructor |
|
34
|
|
|
* |
|
35
|
|
|
* @param array $rules |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(array $rules = array()) |
|
38
|
|
|
{ |
|
39
|
|
|
if(!$rules) { |
|
|
|
|
|
|
40
|
|
|
$rules = array( |
|
41
|
|
|
'cyclomaticComplexity' => array(10, 6, 2) |
|
42
|
|
|
, 'maintainabilityIndex' => array(0, 69, 85) |
|
43
|
|
|
, 'logicalLoc' => array(800, 400, 200) |
|
44
|
|
|
, 'volume' => array(1300, 1000, 300) |
|
45
|
|
|
, 'bugs' => array(0.35, 0.25, 0.15) |
|
46
|
|
|
, 'commentWeight' => array(36, 38, 41) |
|
47
|
|
|
, 'vocabulary' => array(51, 34, 27) |
|
48
|
|
|
, 'difficulty' => array(18, 15, 5.8) |
|
49
|
|
|
, 'instability' => array(1, .95, .45) |
|
50
|
|
|
, 'afferentCoupling' => array(20, 15, 9) |
|
51
|
|
|
, 'efferentCoupling' => array(15, 11, 7) |
|
52
|
|
|
, 'myerDistance' => array(10, 5, 2) |
|
53
|
|
|
, 'lcom' => array(3, 2, 1.5) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->rules = $rules; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @inheritdoc |
|
62
|
|
|
*/ |
|
63
|
|
|
public function asArray() { |
|
64
|
|
|
return $this->rules; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get rule for key |
|
69
|
|
|
* |
|
70
|
|
|
* @param $key |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getRule($key) { |
|
74
|
|
|
return isset($this->rules[$key]) ? $this->rules[$key] : null; |
|
75
|
|
|
} |
|
76
|
|
|
} |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.