Skip to content

Commit eca2f01

Browse files
authored
fix: fixed iterator check (psalm level 1) (#163)
1 parent d2e7e2f commit eca2f01

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bin/coverage-checker.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@
1818
try {
1919
@$xml = new SimpleXMLElement((string) file_get_contents($inputFile));
2020
} catch (Exception) {
21-
throw new RuntimeException('Cannot parse XML of Clover file report');
21+
throw new RuntimeException('Cannot parse XML of Clover file report.');
2222
}
2323

24+
/** @var array<SimpleXMLElement> $metrics */
2425
$metrics = $xml->xpath('//metrics');
26+
if (count($metrics) === 0) {
27+
throw new RuntimeException('Cannot find coverage metrics.');
28+
}
29+
2530
$totalElements = 0;
2631
$checkedElements = 0;
27-
2832
foreach ($metrics as $metric) {
2933
$totalElements += (int) $metric['elements'];
3034
$checkedElements += (int) $metric['coveredelements'];
3135
}
3236

3337
$coverage = round(($checkedElements / $totalElements) * 100, 2);
34-
3538
if ($coverage < $percentage) {
3639
echo ' > Code coverage: '.$coverage.'%, which is below the accepted '.$percentage.'% ❌'.\PHP_EOL.\PHP_EOL;
3740
exit(1);

0 commit comments

Comments
 (0)