symplify/phpstan-extensions
Extra PHPStan rules and extensions from Symplify to improve static analysis of PHP projects. Adds better type inference and framework-aware checks, helping catch bugs earlier and keep codebases consistent with minimal configuration.
Start by installing the package via Composer:
composer require --dev symplify/phpstan-extensions
Then, enable it in your phpstan.neon config:
includes:
- vendor/symplify/phpstan-extensions/config/extension.neon
Your first practical use case: use the ignore format to suppress specific errors cleanly—e.g., for known false positives—using the ignoreErrors syntax with structured paths and messages, instead of raw regex. Example:
ignoreErrors:
-
message: "#^Call to an undefined method App\\\\Entity\\\\User::getNonExistent\\(\\)\\.$#"
path: src/Service/EmailService.php
Symfony\SplFileInfo extension: Use Phpstan\SplFileInfo as a type hint instead of SplFileInfo. PHPStan now understands methods like getRelativePathname() and getFilenameWithoutExtension() without false positives.ignore error suppression: For symfony/console commands with dynamic options or services, use structured ignoreErrors with files or paths to avoid broad #^.*$# suppression.config/packages/test/phpstan.php and extend via phpstan.neon to enable stricter checks in test contexts.symplify/phpstan-extensions/rules directory to include or extend custom rules by registering them in your phpstan.neon under parameters > symplify.ignore format requires exact message substring match—do not use message regex unless necessary; prefer parameter/path filtering.Symfony\SplFileInfo must be imported explicitly—PHPStan won’t auto-resolve the alias unless the class exists in autoloader or you define it in stubFiles.ParameterRule, ClassReflection helpers) require you to use them via extension config.ignoreErrors, maxMatches defaults to 1; override in the error block to allow multiple occurrences.--debug to see which extension classes are loaded; useful when config updates don’t take effect.How can I help you explore Laravel packages today?