File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 1818try {
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-
2832foreach ($ metrics as $ metric ) {
2933 $ totalElements += (int ) $ metric ['elements ' ];
3034 $ checkedElements += (int ) $ metric ['coveredelements ' ];
3135}
3236
3337$ coverage = round (($ checkedElements / $ totalElements ) * 100 , 2 );
34-
3538if ($ coverage < $ percentage ) {
3639 echo ' > Code coverage: ' .$ coverage .'%, which is below the accepted ' .$ percentage .'% ❌ ' .\PHP_EOL .\PHP_EOL ;
3740 exit (1 );
You can’t perform that action at this time.
0 commit comments