Getting started
To install PHPStan, you must use Composer.
The following command will install PHPStan and necessary extensions as development dependencies.
composer require --dev phpstan/phpstan \
phpstan/extension-installer \
mglaman/phpstan-drupal \
phpstan/phpstan-deprecation-rules
The mglaman/phpstan-drupal allows PHPStan to understand how to read code in a Drupal codebase and understand how its dynamic return types operate.
The phpstan/extension-installer package autoconfigures PHPStan to load the phpstan-drupal package and phpstan/phpstan-deprecation-rules. This is the package that enables reporting usages of deprecated code.
Next, you need to create a phpstan.neon
file. This specifies the analysis level and paths you want to scan. The following assumes you'd like to analyze custom modules in your Drupal site.
parameters:
level: 1
paths:
- web/modules/custom
You can then run PHPStan and begin analyzing your codebase!
php vendor/bin/phpstan.phar
If you run out of memory, try using a higher memory limit as documented https://phpstan.org/user-guide/command-line-usage#--memory-limit
php vendor/bin/phpstan.phar --memory-limit=256M
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion