- Published on
Integrating PHPStan in PhpStorm / PHPStan Pro
- Authors
- Name
- Susanne Moog
PHPStan is a powerful static analyzer that helps prevent bugs and improve maintainability. Since PhpStorm 2020.3 EAP, there’s first‑class support for PHPStan in the IDE.
Install PHPStan
ddev composer require --dev phpstan/phpstan phpstan/extension-installer
# For TYPO3 projects you may also add
# ddev composer require --dev ssch/typo3-rector phpstan/phpstan-phpunit
Create phpstan.neon
in your project root:
parameters:
level: max
paths:
- src
- tests
tmpDir: var/phpstan
checkGenericClassInNonGenericObjectType: true
reportUnmatchedIgnoredErrors: true
includes:
# add framework extensions/stubs here if needed
# - vendor/phpstan/phpstan-phpunit/extension.neon
# - vendor/phpstan/phpstan-phpunit/rules.neon
Generate a baseline initially (optional):
vendor/bin/phpstan analyse -c phpstan.neon --generate-baseline
Add to phpstan.neon
:
includes:
- phpstan-baseline.neon
Run PHPStan
ddev composer phpstan
# or directly
ddev exec vendor/bin/phpstan analyse -c phpstan.neon
Add a Composer script for convenience:
{
"scripts": {
"phpstan": "phpstan analyse -c phpstan.neon --memory-limit=-1"
}
}
PhpStorm integration
- Settings → PHP → Quality Tools → PHPStan
- Choose the Remote Interpreter you use for DDEV/Docker (same as for PHPUnit)
- Set the configuration file to
phpstan.neon
- Use “Run inspection by name…” to run PHPStan or configure it in Inspections
Tips
- Keep the baseline small and chip away over time
- Add framework stubs/extensions to improve analysis quality
- Use
--memory-limit=-1
locally if needed; set a tighter limit in CI - Combine with Rector for incremental refactoring