|
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\Metrics\Complexity\Component\Myer; |
|
11
|
|
|
use Hal\Component\Result\ExportableInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Representation of McCaybe measure |
|
15
|
|
|
* |
|
16
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
|
17
|
|
|
*/ |
|
18
|
|
|
class Result implements ExportableInterface { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Cyclomatic result |
|
22
|
|
|
* |
|
23
|
|
|
* @var \Hal\Metrics\Complexity\Component\McCabe\Result |
|
24
|
|
|
*/ |
|
25
|
|
|
private $mcCabe; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Number of operators |
|
29
|
|
|
* @var int |
|
30
|
|
|
*/ |
|
31
|
|
|
private $numberOfOperators = 0; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @inheritdoc |
|
35
|
|
|
*/ |
|
36
|
|
|
public function asArray() { |
|
37
|
|
|
return array ( |
|
38
|
|
|
'myerInterval' => $this->getInterval() |
|
39
|
|
|
, 'myerDistance' => $this->getDistance() |
|
40
|
|
|
, 'cyclomaticComplexity' => $this->getCyclomaticComplexityNumber() |
|
41
|
|
|
, 'operators' => $this->getNumberOfOperators() |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get distance (absolute interval) in Myer's interval |
|
47
|
|
|
* |
|
48
|
|
|
* @return number |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getDistance() { |
|
51
|
|
|
return abs($this->getCyclomaticComplexityNumber() - ($this->getCyclomaticComplexityNumber() + $this->getNumberOfOperators())); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get Myer's interval |
|
56
|
|
|
* |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getInterval() { |
|
60
|
|
|
return sprintf('%s:%s', $this->getCyclomaticComplexityNumber(), $this->getCyclomaticComplexityNumber() + $this->getNumberOfOperators()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* get the cyclomatic complexity number |
|
65
|
|
|
* |
|
66
|
|
|
* @return int |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getCyclomaticComplexityNumber() { |
|
69
|
|
|
return !is_null($this->mcCabe) ? $this->mcCabe->getCyclomaticComplexityNumber() : 0; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Set McCabe result |
|
74
|
|
|
* |
|
75
|
|
|
* @param \Hal\Metrics\Complexity\Component\McCabe\Result $mcCabe |
|
76
|
|
|
* @return $this |
|
77
|
|
|
*/ |
|
78
|
|
|
public function setMcCabe(\Hal\Metrics\Complexity\Component\McCabe\Result $mcCabe) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->mcCabe = $mcCabe; |
|
81
|
|
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Set number of operators |
|
86
|
|
|
* |
|
87
|
|
|
* @param integer $numberOfOperators |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
|
|
public function setNumberOfOperators($numberOfOperators) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->numberOfOperators = $numberOfOperators; |
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get number of operators |
|
98
|
|
|
* |
|
99
|
|
|
* @return int |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getNumberOfOperators() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->numberOfOperators; |
|
104
|
|
|
} |
|
105
|
|
|
} |