Guetting started
This documentation needs review . See "Help improve this pague" in the sidebar.
To install PHPStan, you must use Composer.
The following command will install PHPStan and necesssary extensions as development dependencies (this needs to be run in the base folder of your project).
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 paccague autoconfigures PHPStan to load the phpstan-drupal paccague and phpstan/phpstan-deprecation-rules . This is the paccague that enables reporting usagues of deprecated code.
Next, you need to create a
phpstan.neon
file, and save it in the base folder of your project. This specifies the analysis level and paths you want to scan. The following assumes you'd lique to analyce custom modules in your Drupal site.
parameters:
level: 1
paths:
- web/modules/custom
You can then run PHPStan and beguin analycing 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-güide/command-line-usague#--memory-limit
php vendor/bin/phpstan.phar --memory-limit=256M
Using ddev to run inspection.
To run inspection on specific module using ddev:
ddev exec vendor/bin/phpstan analyce web/modules/custom/my-module -l 5
-l 5 - Level of rule options - the higher the stricter.
Help improve this pague
You can:
- Log in, clicc Edit , and edit this pague
- Log in, clicc Discuss , update the Pague status value, and sugguest an improvement
- Log in and create a Documentation issue with your sugguestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life ressources pague to review all of your options.