Interested in mastering your PHP craft and getting the most out of PHPStan? Ondřej Mirtes (the creator of PHPStan) will hold a 3-hour interactive workshop as part of the online Dutch PHP Conference on June 25th 2020.
You'll learn how to install, configure, and run PHPStan, receive tips on how to write code so that PHPStan can be as powerful as possible, and you will also be able to write your own PHPStan rules once the workshop is over.Buy a ticket and secure your place! »
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