Hidden Gems of PHP Packages: Static Analysis Results Baseliner

Have you used PHPStan, Psalm or Easy Coding Standard on a very old project and got 10 000+ errors?
Do you wish to skip fixing these 10 000 errors and check new code only?

Yes and yes? You'll love SARB.

I found this package by random clicking on meetups on Friends of PHP and reading program of the meetup. One of them was Dave with his SARB - Static Analysis Results Baseliner tool. What an interesting name. In the Czech, I read SRAB, which means coward... what does such tool do?

What Does SARB Help You With?

"SARB is used to create a baseline of these results. As work on the project progresses SARB can take the latest static analysis results, removes those issues in the baseline and report the issues raised since the baseline. SARB does this, in conjunction with it, by tracking lines of code between commits."

Such a simple idea with huge application in practice - amazing! What does it mean? Let me show you on a project:

No stress with the legacy you didn't even write, but full focus on the present moment.

How can You use it?

  1. Install it
composer require dave-liddament/sarb --dev
  1. Create a baseline file
# for psalm
vendor/bin/psalm --report reports/psalm-result.json
vendor/bin/sarb create-baseline reports/psalm-result.json reports/sarb_baseline.json psalm-json

# for phpstan
vendor/bin/phpstan analyse --error-format json > reports/phpstan-result.json
vendor/bin/sarb create-baseline reports/phpstan-result.json reports/sarb_baseline.json phpstan-json
  1. Commit the code

  2. Rerun the static analysis on the latest code

# for psalm
vendor/bin/psalm --report reports/psalm-result.json

# for phpstan
vendor/bin/phpstan analyse --error-format json > reports/phpstan-result.json
  1. Use SARB to remove baseline results
# psalm
vendor/bin/sarb remove-baseline-results reports/psalm-result.json reports/sarb_baseline.json reports/issues_since_baseline.json

# phpstan
vendor/bin/sarb remove-baseline-results reports/phpstan-result.json reports/sarb_baseline.json reports/issues_since_baseline.json

That's it!

You can use this also on EasyCodingStandard:

vendor/bin/easy-coding-standard check src --output-format reports/ecs-result.json
vendor/bin/sarb remove-baseline-results reports/ecs-result.json reports/sarb_baseline.json reports/issues_since_baseline.json

The sky is the limit :)


Read more about the tool in Introduction post and in README of the project on Github.

Great job David!


Happy coding!


Found a typo? Fix it to join team of 73 people that improve content here

❤️️ Do you find value in topics what I write about?
Support my writing by throwing a couple bucks at my Patreon