Skip to content

Skip coverage entries without executable lines - #94

Draft
janedbal wants to merge 1 commit into
masterfrom
jn-skip-files-without-executable-lines
Draft

janedbal wants to merge 1 commit into
masterfrom
jn-skip-files-without-executable-lines

Conversation

@janedbal

Copy link
Copy Markdown
Member

A .cov file lists every file in the coverage scope. A file without executable lines gets an empty line list:

Consts.php => []           // class with only constants
Iface.php  => []           // interface
Status.php => []           // enum without methods
Multi.php  => {"9":[],…,"21":[1]}

Clover and Cobertura inputs leave such files out, because the extractors skip entries without lines. With .cov input, the empty entries break check:

  • check --verbose throws DivisionByZeroError. It prints the coverage percentage of each file, and FileCoverage::getCoveragePercentage() divides by the number of executable lines. Without --verbose, nothing calls this method.
    Info: Checking files listed in coverage report
    ‼️  Internal error: DivisionByZeroError: Division by zero
     at src/Coverage/FileCoverage.php:30
    
  • An empty (0-byte) PHP file throws ValueError, also without --verbose. range(1, 0) returns two line numbers for zero lines, so array_combine() in CoverageGuard gets arrays of different sizes.

Now CoverageProvider skips entries without executable lines, for every input format. It skips them after the integrity checks, so a missing file is still reported. Such a file has nothing to cover, so no rule can report it. The "analysed N files" count is now the same for all formats: the same PHPUnit run gave 2 files for Clover and 5 files for .cov.

  • New test with an interface and an empty file in a .cov file, with and without --verbose. On master, it throws DivisionByZeroError and ValueError.
  • The test creates ProcessedCodeCoverageData, so tests/CoverageGuardTest.php joins the existing PHPStan ignore for internal php-code-coverage classes.

Co-Authored-By: Claude Code

A .cov file lists every file in the coverage scope. A file without
executable lines gets an empty line list. Examples are interfaces, enums
without methods, classes with only constants, and empty files. Clover
and Cobertura inputs leave such files out, because the extractors skip
entries without lines.

The empty entries broke the check command:
- check --verbose threw DivisionByZeroError. It prints the coverage
  percentage of each file, and FileCoverage::getCoveragePercentage()
  divides by the number of executable lines.
- An empty (0-byte) PHP file threw ValueError in CoverageGuard, also
  without --verbose. range(1, 0) returns two line numbers for zero
  lines, so array_combine() got arrays of different sizes.

CoverageProvider now skips entries without executable lines after the
integrity checks, for every input format. Such a file has nothing to
cover, so no rule can report it. The "analysed N files" count is now
the same for all formats.

Co-Authored-By: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant