My development blog about PHP, Nette Framework, ElasticSearch or occasional short tips.
Phpstan is tool for static code analysis in php. It tries to find bugs in your code before you test/run it.
Installation is really easy using composer by
composer require --dev phpstan/phpstan
vendor/bin/phpstan analyse app, Windows
vendor\bin\phpstan.bat analyse app make sure you
are using appropriate slashes.
First option is analyse that's clear, second is directory you want to analyse. In our case we are using Nette application whitch is usually placed in app folder. You can use multiple folder separated by spaces for one analyser run.
vendor\bin\phpstan.bat analyse app
Phpstan supports multiple levels of analysis with more rules higher analysis level.
vendor\bin\phpstan.bat -l 1 analyse app
Default run is level 0. Top level is 4. Preferably you run first level 0 fix errors, move to level 1 fix errors and repeat until level 4.
Want more specific ruleset? You can set it by .neon file
vendor\bin\phpstan.bat -c app/config/phpstan.neon analyse app
More in documentation.