Skip to content

Commit

Permalink
Do not use private implementation detail of phpunit/php-code-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 22, 2022
1 parent 40fca2a commit c019dae
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/cli/PatchCoverageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use const PHP_EOL;
use function is_file;
use function printf;
use SebastianBergmann\CodeCoverage\Percentage;

final class PatchCoverageCommand extends Command
{
Expand Down Expand Up @@ -61,10 +60,10 @@ public function run(Arguments $arguments): int
'%d / %d changed executable lines covered (%s)' . PHP_EOL,
$patchCoverage['numChangedLinesThatWereExecuted'],
$patchCoverage['numChangedLinesThatAreExecutable'],
Percentage::fromFractionAndTotal(
$this->percentage(
$patchCoverage['numChangedLinesThatWereExecuted'],
$patchCoverage['numChangedLinesThatAreExecutable']
)->asFixedWidthString()
)
);

if (!empty($patchCoverage['changedLinesThatWereNotExecuted'])) {
Expand All @@ -85,4 +84,13 @@ public function run(Arguments $arguments): int

return 0;
}

private function percentage(float $fraction, float $total): string
{
if ($total > 0) {
return sprintf('%6.2F%%', ($fraction / $total) * 100);
}

return '';
}
}

0 comments on commit c019dae

Please sign in to comment.