Conditions | 7 |
Paths | 24 |
Total Lines | 33 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | public function run() |
||
21 | { |
||
22 | $inputFile = isset($this->args[0]) ? $this->args[0] : "clover.xml"; |
||
23 | $targetCoverage = (int)(isset($argv[1]) ? $argv[1] : 1); |
||
|
|||
24 | $percentage = min(100, max(0, $targetCoverage)); |
||
25 | |||
26 | if (!file_exists($inputFile)) { |
||
27 | throw new InvalidArgumentException('Invalid input file provided'); |
||
28 | } |
||
29 | |||
30 | if (!$percentage) { |
||
31 | throw new InvalidArgumentException('An integer checked percentage must be given as second parameter'); |
||
32 | } |
||
33 | |||
34 | $xml = new SimpleXMLElement(file_get_contents($inputFile)); |
||
35 | $metrics = $xml->xpath('//metrics'); |
||
36 | $totalElements = 0; |
||
37 | $checkedElements = 0; |
||
38 | |||
39 | foreach ($metrics as $metric) { |
||
40 | $totalElements += (int)$metric['elements']; |
||
41 | $checkedElements += (int)$metric['coveredelements']; |
||
42 | } |
||
43 | |||
44 | $coverage = ($checkedElements / $totalElements) * 100; |
||
45 | |||
46 | if ($coverage < $percentage) { |
||
47 | echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL; |
||
48 | exit(1); |
||
49 | } |
||
50 | |||
51 | echo 'Code coverage is ' . round($coverage, 2) . '% - OK!' . PHP_EOL; |
||
52 | } |
||
53 | } |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.