Conditions | 3 |
Paths | 3 |
Total Lines | 17 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 3 |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | 3 | public function run(string $coverageFilePath, int $minPercent): string |
|
22 | { |
||
23 | 3 | if (!file_exists($coverageFilePath)) { |
|
24 | 1 | throw new InvalidArgumentException('Invalid path file: '.$coverageFilePath); |
|
25 | } |
||
26 | |||
27 | 2 | $metrics = (new SimpleXMLElement(file_get_contents($coverageFilePath)))->xpath('//metrics'); |
|
28 | 2 | [$totalElements, $checkedElements] = $this->getTotals($metrics); |
|
29 | 2 | $coveragePercent = $this->getPercent($checkedElements, $totalElements); |
|
30 | |||
31 | 2 | if ($coveragePercent < $minPercent) { |
|
32 | 1 | throw new ErrorException( |
|
33 | 1 | sprintf('Code coverage is %d percent, accepted is %d percent', $coveragePercent, $minPercent) |
|
34 | ); |
||
35 | } |
||
36 | |||
37 | 1 | return $coveragePercent; |
|
38 | } |
||
66 |