PHPStan’s Baseline Feature Lets You Hold New Code to a Higher Standard

  1. Upgrade to a new and more capable version of PHPStan might represent a substantial amount of work —you need to fix all the new errors to keep the same level of analysis.
  2. Developers are missing out on real bugs when they’re running one of the lower levels.
  3. Introducing new advanced custom rules also comes with the need to fix all the violations before the ability to use them.

What’s The Baseline?

vendor/bin/phpstan analyse --level 7 \
--configuration phpstan.neon \
src/ tests/ --generate-baseline
message: "#^Only numeric types are allowed in pre\\-decrement, bool\\|float\\|int\\|string\\|null given\\.$#"
count: 1
path: src/Analyser/Scope.php
message: "#^Anonymous function has an unused use \\$container\\.$#"
count: 2
path: src/Command/CommandHelper.php
- phpstan-baseline.neon
# your usual configuration options
# your custom extensions

The Use-Cases

Upgrade to new versions of PHPStan immediately

Run higher rule level even if there are errors

Introduce custom rules and hold new code to a higher standard

What’s next?

If you’re a PHP developer, give PHPStan a shot. If you’re interested in various insights about software development, follow me on Twitter.

Author of PHPStan, static analysis tool for finding bugs in code without running it.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Filecoin+ Day with Filswan

Microsoft Engage 21' Experience


Meeting the Mother of the Girl My Son Killed

Second Coding Blog Post

Creating a simple contact form using MySql and PHP in WAMP

Is a Lossy Platform Holding You Back?

How To: Solving the ‘Missing Number’ Question

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ondřej Mirtes

Ondřej Mirtes

Author of PHPStan, static analysis tool for finding bugs in code without running it.

More from Medium

‘pcre2.h’ file not found error when trying to install pcov extension on Laravel Valet

How to make a “Copy to clipboard” in Scriptcase

Tests are important and here’s WHY!

How did we reduce Memcached memory usage in PHP at Wingie — Enuygun