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\Structural\CardAndAgresti; |
11
|
|
|
use Hal\Component\OOP\Extractor\ClassMap; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Estimates System complexity for the given file |
16
|
|
|
* |
17
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
18
|
|
|
*/ |
19
|
|
|
class FileSystemComplexity { |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Hal\Component\OOP\Extractor\ClassMap |
24
|
|
|
*/ |
25
|
|
|
private $classMap; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor |
29
|
|
|
* |
30
|
|
|
* @param ClassMap $classMap |
31
|
|
|
*/ |
32
|
|
|
public function __construct(ClassMap $classMap) |
33
|
|
|
{ |
34
|
|
|
$this->classMap = $classMap; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Calculates system complexity |
40
|
|
|
* |
41
|
|
|
* @param string $filename |
42
|
|
|
* @return Result |
43
|
|
|
*/ |
44
|
|
|
public function calculate($filename) |
45
|
|
|
{ |
46
|
|
|
$rOOP = $this->classMap->getClassesIn($filename); |
47
|
|
|
$result = new Result($filename); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$len = 0; |
50
|
|
|
$sy = $dc = $sc = array(); |
51
|
|
|
$calculator = new SystemComplexity(); |
52
|
|
|
foreach($rOOP->getClasses() as $class) { |
53
|
|
|
$r = $calculator->calculate($class); |
54
|
|
|
|
55
|
|
|
$len += sizeof($class->getMethods(), COUNT_NORMAL); |
56
|
|
|
$sy[] = $r->getTotalSystemComplexity(); |
57
|
|
|
$dc[] = $r->getTotalDataComplexity(); |
58
|
|
|
$sc[] = $r->getTotalStructuralComplexity(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if($len > 0 &&sizeof($dc, COUNT_NORMAL) > 0) { |
62
|
|
|
$result |
63
|
|
|
->setRelativeStructuralComplexity(round(array_sum($sc) / $len, 2)) |
64
|
|
|
->setRelativeDataComplexity(round(array_sum($dc) / $len, 2)) |
65
|
|
|
->setRelativeSystemComplexity(round(array_sum($sy) / $len, 2)) |
66
|
|
|
->setTotalStructuralComplexity(array_sum($sc)) |
67
|
|
|
->setTotalDataComplexity(array_sum($dc)) |
68
|
|
|
->setTotalSystemComplexity(array_sum($dc) + array_sum($sc)) |
69
|
|
|
; |
70
|
|
|
} |
71
|
|
|
return $result; |
72
|
|
|
} |
73
|
|
|
}; |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.