PHPStan - markhowellsmead/helpers GitHub Wiki
As used in a WordPress Theme.
phpstan analyse . --memory-limit=2048M
or e.g. for those projects:
phpstan analyse ./src --memory-limit=2048M
Recommend running PHPCBF over the folder when all of the bugs have been fixed.
Composer dependencies
These are currently installed as global Composer dependencies on the development machine, so they do not need to be added to individual projects any more. Previous projects in which the dependencies are defined at a project level will continue to work, although this approach should be deprecated.
{
"require-dev": {
"phpstan/phpstan": "^2.1",
"szepeviktor/phpstan-wordpress": "^2.0",
"phpstan/extension-installer": "^1.4",
"php-stubs/wordpress-stubs": "^6.8",
"php-stubs/wp-cli-stubs": "^2.12"
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"phpstan": "phpstan analyse --memory-limit=2048M"
}
}
phpstan.neon
This configuration belongs in the project folder, so that the phpVersion can be defined specifically for the project. Running phpstan analyse . --memory-limit=2048M should automatically use the global Composer dependencies, unless the dependencies have formerly been installed directly in the project.
The former command composer run phpstan only works when using local and not global Composer dependencies.
Only add the definitions for scanFiles where the dependencies are not global, but in the local project.
parameters:
phpVersion: 80324
level: 5
excludePaths:
- vendor/*
- node_modules/*
scanDirectories:
- ./
- ./vendor
- ../../plugins/
- ../../themes/
- ./dist/vendor # only if in the current project
scanFiles:
- %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php
- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-stubs.php
- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php
- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-i18n-stubs.php
- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-tools-stubs.php