Blog Spameri

My development blog about PHP, Nette Framework, ElasticSearch or occasional short tips.


Project maintained by Spamercz Hosted on GitHub Pages — Theme by mattgraham

Installation

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


Usage

Linux: 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.

  1. Run vendor\bin\phpstan.bat analyse app
  2. Wait for Phpstan to analyse files
  3. Count errors
  4. Fix them
  5. Safer application - Profit! :)

Analyse levels

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.


Custom config

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.

Back to index RSS

Posted: 08 Mar 2017