Merge pull request #1626 from SimonBroekaert/feat/add_only-covered_option

feat: add '--only-covered' option to '--coverage'
This commit is contained in:
nuno maduro
2026-04-10 12:53:17 +01:00
committed by GitHub
3 changed files with 25 additions and 3 deletions

View File

@ -74,7 +74,7 @@ final class Coverage
* Reports the code coverage report to the
* console and returns the result in float.
*/
public static function report(OutputInterface $output, bool $compact = false): float
public static function report(OutputInterface $output, bool $compact = false, bool $showOnlyCovered = false): float
{
if (! file_exists($reportPath = self::getPath())) {
if (self::usingXdebug()) {
@ -109,6 +109,10 @@ final class Coverage
$basename,
]);
if ($showOnlyCovered && $file->percentageOfExecutedLines()->asFloat() === 0.0) {
continue;
}
$percentage = $file->numberOfExecutableLines() === 0
? '100.0'
: number_format($file->percentageOfExecutedLines()->asFloat(), 1, '.', '');