Unique feature of PHPStan is the ability to define and statically check “magic” behaviour of classes - accessing properties that are not defined in the class but are created in
__set and invoking methods using
PHPStan also allows writing custom rules for situations that aren’t objective bugs or other problems in the code, but allow people avoid tricky situations or enforce the way they want to write their code. These custom rules take advantage of the abstract syntax tree, advanced type inference engine, PHPDoc parser, and class reflection data.
Installing extensions #
Users can install various PHPStan extensions to enhance the capabilities of the static analyser. Many extensions already support phpstan/extension-installer Composer plugin, so in order to enable an extension, it’s sufficient to require it in your
composer require --dev phpstan/extension-installer && \
composer require --dev phpstan/phpstan-beberlei-assert
If you can’t or don’t want to use phpstan/extension-installer, include the extension’s configuration file manually in the
Why wouldn’t I want to always use phpstan/extension-installer?
It always enables all the functionality that an extension offers. If you for example want to use only some of the rules from phpstan-strict-rules, or if you only want to use
extension.neon (but not
rules.neon) from phpstan-doctrine, you can’t use the extension installer plugin and must include chosen files manually.
Official extensions #
Check out phpstan-strict-rules repository for extra strict and opinionated rules for PHPStan.
Check out as well phpstan-deprecation-rules for rules that detect usage of deprecated classes, methods, properties, constants and traits!
Framework-specific extensions #
- Symfony Framework
- Nette Framework
- Dibi - Database Abstraction Library
Unofficial extensions #
- Laminas (a.k.a. Zend Framework)
- Nextras ORM
3rd party rules #
- thecodingmachine / phpstan-strict-rules
- ergebnis / phpstan-rules
- pepakriz / phpstan-exception-rules
- Slamdunk / phpstan-extensions
- ekino / phpstan-banned-code
- taptima / phpstan-custom