tomasvotruba/type-coverage
CLI tool for measuring PHP type coverage. Scans your codebase and reports how much is covered by native types and PHPDoc (params, returns, properties), helping you spot missing types, raise strictness, and improve static analysis readiness.
Install via Composer: composer require --dev tomasvotruba/type-coverage. Run vendor/bin/type-coverage on your project root to get an immediate report. The CLI output shows total type coverage % and breaks it down by type of element (parameter, return, property), highlighting specific files with gaps. Start by scanning a single subdirectory (e.g., src/Service) to isolate a small scope—ideal for pilot adoption. Check the generated JSON report (--output-format=json) to integrate with dashboards or CI dashboards.
--min-te coverage 70% to fail builds only if coverage drops below 70%, while running without enforcement during initial phase to gather data. Gradually raise the threshold (75% → 80% → …) as teams improve.composer.json scripts ("type-coverage": "type-coverage --min-coverage 85%") and call it in CI before static analysis steps. Failures are human-readable and point to exact file/line.--path src/Domain to focus only on business-critical layers, ignoring tests or generated code (e.g., --exclude-path tests).--format=csv output to a log file or DB to track coverage trends per release. Combine with git log --oneline to tie coverage changes to PRs.type-coverage --min-coverage 90% --changed-since=HEAD~1 to enforce type coverage only for diff—ideal for legacy repos where full baseline would be overwhelming.type-coverage.neon: While CLI flags work, define thresholds and exclusions in a config file to avoid repetition:
parameters:
minCoverage: 85
paths: [src]
excludePaths: [tests, src/Generated]
focusOn: [parameter, return]
--sort=least-covered to surface worst offenders first. Tackle one file at a time—fixing type coverage is more sustainable than bulk fixes.parameter/return rules (parameters: true → parameters: false in PHPStan config) to prevent duplicate warnings.? on return types), so combine with phpstan/phpstan or shipmonk/composer-change-detector for full type safety.How can I help you explore Laravel packages today?