Skip to content

Coverage ​

Facade: Unusualify\Modularous\Facades\Coverage
Accessor: coverage.service
Underlying: Unusualify\Modularous\Services\CoverageService

Parses PHPUnit Clover XML coverage reports and provides analysis, filtering, and export utilities. See CoverageService for implementation details.

Methods ​

Configuration (Fluent) ​

MethodSignatureDescription
setCloverPath(string $path): CoverageServiceSet the path to the Clover XML file
filterByFiles(array $files): CoverageServiceLimit analysis to specific files
setCoverageThreshold(float $threshold): CoverageServiceSet the minimum coverage percentage
skipMagicMethods(bool $skip = true): CoverageServiceExclude __* methods from analysis
skipPrivateMethods(bool $skip = true): CoverageServiceExclude private methods
skipProtectedMethods(bool $skip = true): CoverageServiceExclude protected methods

Analysis ​

MethodSignatureDescription
analyze(): arrayFull coverage analysis of all files
analyzeFile(string $filePath): arrayAnalysis for a single file
getMethodCoverage(string $filePath, string $methodName): array|nullCoverage data for a specific method
uncovered(array $files = []): arrayReturns methods with 0% coverage
partial(float $threshold = 50.0, array $files = []): arrayReturns methods below $threshold%
stats(?array $files = null): arrayReturns aggregate coverage statistics
git(string $baseBranch = 'main'): arrayReturns coverage for files changed vs $baseBranch
checkPR(string $baseBranch = 'main', bool $throwOnFailure = false): boolCI check — returns false (or throws) if coverage drops

Export ​

MethodSignatureDescription
json(?array $files = null, bool $prettyPrint = true): stringReturns coverage as JSON
markdown(?array $files = null): stringReturns coverage as a Markdown table
html(?array $files = null): stringReturns coverage as an HTML report
save(string $outputPath, ?array $files = null, string $format = 'json'): boolSaves the report to a file

Error Handling ​

MethodSignatureDescription
getErrors(): arrayReturns any parse errors encountered
hasErrors(): boolWhether any errors occurred

Usage ​

php
use Unusualify\Modularous\Facades\Coverage;

$report = Coverage::setCloverPath(storage_path('coverage.xml'))
    ->skipMagicMethods()
    ->setCoverageThreshold(80.0)
    ->analyze();

// In CI
if (!Coverage::checkPR('main', throwOnFailure: true)) {
    exit(1);
}