Extension Library
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 __get
and __set
and invoking methods using __call
.
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.
Learn more about writing custom extensions »
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.json
:
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 includes
section:
includes:
- vendor/phpstan/phpstan-beberlei-assert/extension.neon
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 #
- Doctrine
- PHPUnit
- Symfony Framework
- beberlei/assert
- webmozart/assert
- Mockery
- azjezz/psl
- Nette Framework
- Dibi - Database Abstraction Library
Unofficial extensions #
- Laravel (Larastan and Bladestan)
- Drupal
- WordPress
- Laminas
- Phony
- Prophecy
- marc-mabe/php-enum
- myclabs/php-enum
- Yii2
- TYPO3
- Nextras ORM
- Sonata
- Magento
- CakePHP
- Safe PHP
- psr/log
3rd party rules #
- thecodingmachine / phpstan-strict-rules
- spaze / phpstan-disallowed-calls
- ergebnis / phpstan-rules
- Slamdunk / phpstan-extensions
- ekino / phpstan-banned-code
- voku / phpstan-rules
- shipmonk / phpstan-rules
- shipmonk / dead-code-detector
- shipmonk / phpstan-baseline-per-identifier
- jiripudil / phpstan-sealed-classes
- sidz / phpstan-rules
- staabm / phpstan-todo-by
- staabm / phpstan-dba
- roave / no-floaters
- PHP Language Extensions