Back to results for “Unit Testing with PHPUnit”
PHP › Static Analysis (PHPStan & Psalm)

What is a baseline file in PHPStan, and how does it help a team adopt static analysis on an existing project without needing to fix every single issue immediately?

Intermediate

Answer

A baseline file records every currently existing issue that static analysis finds in a codebase at a specific point in time, effectively telling the tool to ignore those specific already known issues going forward, while still reporting any brand new issue introduced afterward, which lets a team immediately start enforcing static analysis on all new code being written without first needing to pause everything and fix potentially hundreds of preexisting issues throughout an older, large codebase all at once.
vendor/bin/phpstan analyse --generate-baseline
Real-world example A team adopting PHPStan on a five year old codebase generates a baseline capturing the several hundred existing issues, then configures their continuous integration pipeline to fail only on any brand new issue introduced in future pull requests, letting them adopt the tool immediately without a massive one time cleanup effort.

Common follow-ups: How should a team periodically work down the size of an existing baseline file over time?;What happens to the baseline file when a genuinely fixed issue is later removed from the actual code?