symplify/phpstan-rules
Extra PHPStan rules by Symplify to catch bugs, improve code quality, and enforce consistent conventions. Easy to install and configure, with a broad set of checks for Symfony/Laravel and modern PHP features to keep your codebase clean.
Begin by installing the package via Composer:
composer require --dev symplify/phpstan-rules
Then, enable the rules in your phpstan.neon file. Start with the rules section to selectively activate rules—e.g., for stricter object construction, null safety, or naming conventions:
includes:
- vendor/symplify/phpstan-rules/config/rules.neon
A first practical use case: catch cases where developers accidentally inject services via constructor and @inject annotations (a common anti-pattern in legacy Symfony code). Enable UninjectServiceAnnotationRule to auto-detect this. Run phpstan once—issues will surface quickly in Controllers or Services.
phpstan.neon configs (e.g., rules/best-practices.neon, rules/security.neon) to evolve rule adoption per team maturity.vendor/bin/phpstan to your pipeline. Fail builds if risky rules (e.g., NoMagicPullRule, NoDirectServiceAccessRule) are violated—prevents runtime bugs from leaking.level hints (e.g., maxLevel: 5) or use ignoreErrors to suppress legacy violations while catching new ones.nunomaduro/larastan)—this package complements framework-specific rules with broader PHP-level checks like NoSuperfluousExtendsRule or NoUnneededFqcnInPhpDocRule.phpstan.neon. Double-check includes and neon syntax (YAML is whitespace-sensitive).NoUnusedPrivateMethodRule) overlap with PHPStan’s core. Prioritize this package’s versions only if they offer stricter semantics—review rule ids in the config file.--memory-limit=2G and disable rarely needed rules (e.g., NoInlineDocCommentRule).AbstractSymplifyRule) in your own PHPStan extension—useful for project-specific constraints like App\Dto\* naming.config/rules.neon or source (src/Rules/) to understand semantics. Use --debug flag to trace which rule flagged an error.How can I help you explore Laravel packages today?