11<?php
22
3- $ inputFile = $ argv [1 ];
3+ $ inputFiles = explode ( ' , ' , $ argv [1 ]) ;
44$ outputFile = $ argv [2 ];
55$ coverageName = isset ($ argv [3 ]) ? $ argv [3 ] : 'coverage ' ;
66
7- if (! file_exists ( $ inputFile )) {
8- throw new InvalidArgumentException ( ' Invalid input file provided ' ) ;
9- }
7+ $ totalCoverage = 0 ;
8+ $ totalElements = 0 ;
9+ $ checkedElements = 0 ;
1010
11- try {
12- $ xml = new SimpleXMLElement (file_get_contents ($ inputFile ));
11+ foreach ($ inputFiles as $ inputFile ) {
12+ if (!file_exists ($ inputFile )) {
13+ throw new InvalidArgumentException ('Invalid input file provided: ' . $ inputFile );
14+ }
1315
14- $ metrics = $ xml ->xpath ('//metrics ' );
15- $ totalElements = 0 ;
16- $ checkedElements = 0 ;
16+ try {
17+ $ xml = new SimpleXMLElement (file_get_contents ($ inputFile ));
1718
18- foreach ($ metrics as $ metric ) {
19- $ totalElements += (int ) $ metric ['elements ' ];
20- $ checkedElements += (int ) $ metric ['coveredelements ' ];
21- }
19+ $ metrics = $ xml ->xpath ('//metrics ' );
2220
23- $ coverage = (int )(($ totalElements === 0 ) ? 0 : ($ checkedElements / $ totalElements ) * 100 );
21+ foreach ($ metrics as $ metric ) {
22+ $ totalElements += (int ) $ metric ['elements ' ];
23+ $ checkedElements += (int ) $ metric ['coveredelements ' ];
24+ }
2425
25- $ template = file_get_contents (__DIR__ . '/templates/badge.svg ' );
26+ $ coverage = round (($ totalElements === 0 ) ? 0 : ($ checkedElements / $ totalElements ) * 100 );
27+ $ totalCoverage += $ coverage ;
28+ } catch (Exception $ e ) {
29+ echo $ e ->getMessage ();
30+ }
31+ }
2632
27- $ template = str_replace ( ' {{ total }} ' , $ coverage, $ template );
33+ $ totalCoverage = $ totalCoverage / count ( $ inputFiles ); // Average coverage across all files
2834
29- $ template = str_replace ( ' {{ coverage }} ' , $ coverageName , $ template );
35+ $ template = file_get_contents ( __DIR__ . ' /templates/badge.svg ' );
3036
31- $ color = '#a4a61d ' ; // Default Gray
32- if ($ coverage < 40 ) {
33- $ color = '#e05d44 ' ; // Red
34- } elseif ($ coverage < 60 ) {
35- $ color = '#fe7d37 ' ; // Orange
36- } elseif ($ coverage < 75 ) {
37- $ color = '#dfb317 ' ; // Yellow
38- } elseif ($ coverage < 90 ) {
39- $ color = '#a4a61d ' ; // Yellow-Green
40- } elseif ($ coverage < 95 ) {
41- $ color = '#97CA00 ' ; // Green
42- } elseif ($ coverage <= 100 ) {
43- $ color = '#4c1 ' ; // Bright Green
44- }
37+ $ template = str_replace ('{{ total }} ' , $ totalCoverage , $ template );
4538
46- $ template = str_replace ('{{ total }} ' , $ coverage , $ template );
47- $ template = str_replace ('{{ color }} ' , $ color , $ template );
39+ $ template = str_replace ('{{ coverage }} ' , $ coverageName , $ template );
4840
49- file_put_contents ($ outputFile , $ template );
50- } catch (Exception $ e ) {
51- echo $ e ->getMessage ();
41+ $ color = '#a4a61d ' ; // Default Gray
42+ if ($ totalCoverage < 40 ) {
43+ $ color = '#e05d44 ' ; // Red
44+ } elseif ($ totalCoverage < 60 ) {
45+ $ color = '#fe7d37 ' ; // Orange
46+ } elseif ($ totalCoverage < 75 ) {
47+ $ color = '#dfb317 ' ; // Yellow
48+ } elseif ($ totalCoverage < 90 ) {
49+ $ color = '#a4a61d ' ; // Yellow-Green
50+ } elseif ($ totalCoverage < 95 ) {
51+ $ color = '#97CA00 ' ; // Green
52+ } elseif ($ totalCoverage <= 100 ) {
53+ $ color = '#4c1 ' ; // Bright Green
5254}
5355
56+ $ template = str_replace ('{{ total }} ' , $ totalCoverage , $ template );
57+ $ template = str_replace ('{{ color }} ' , $ color , $ template );
5458
59+ file_put_contents ($ outputFile , $ template );
0 commit comments