Provides a Larastan config for stickee projects.
Larastan is a PHPStan wrapper for Laravel.
It is ran by using the phpstan
command and so will be referred to as PHPStan from now on.
composer require --dev stickee/larastan-config
cp vendor/stickee/larastan-config/dist/phpstan.dist.neon phpstan.dist.neon
You must commit the phpstan.dist.neon
config file.
See the upgrade guide on PHPStan for a Rector rule that should be run before using this config.
vendor/bin/phpstan analyse -c phpstan.dist.neon
You should always analyse the whole project.
You may override any of the settings by editing the phpstan.dist.neon
file.
The options are available at https://phpstan.org/config-reference.
It would be a pain to add PHPStan to your project and have to fix all the existing errors before you can start using it. For this reason you can generate a "baseline" with this command:
vendor/bin/phpstan analyse -c phpstan.dist.neon --generate-baseline
and commit the new phpstan-baseline.neon
file.
This means PHPStan will ignore any errors in this file so you can use PHPStan to check for errors in any new code you add.
If you get any free time you can refer to this file for code that should be fixed and regenerate the baseline (with the same command) afterwards.
An example GitHub actions workflow is included at /dist/.github/workflows/phpstan.yaml
.
It will run PHPStan against a PR as a "check" and output any errors it finds against the commit that failed.
The action first checks if any PHP files have been changed and if it needs to run at all. This is because PHPStan must analyse all of the application code at once and therefore takes a bit of time, so it's good to skip it if we can.
The action refers to a CI config at /dist/.github/workflows/phpstan.ci.neon
(that you can copy into the root of your project) which includes the original config and also ignores unmatched ignored errors to keep the check clean of these errors.
The following are some of the easily fixable problems you may run into using PHPStan and Larastan:
There is a guide on the PHPStan blog that contains suggestions for fixing this.