slam/phpstan-extensions
PHPStan extensions with extra strict rules: unused variables, closure parameter typehints, enforce ::class notation, forbid goto, naming conventions, validate PHPUnit annotation FQCNs, and restrict access to globals/static properties in specific contexts.
UnusedVariableRule, StringToClassRule) and framework-agnostic (with Symfony/Yii-specific configs), allowing selective adoption. This avoids overhead in non-relevant contexts (e.g., Yii rules in a Symfony project).phpstan/extension-installer). Compatible with PHPStan 2.0+, which is widely adopted in modern Laravel projects.--dev) and zero runtime overhead (static analysis only). Config inclusion is explicit (phpstan.neon), avoiding silent behavior.Illuminate-specific checks).phpstan.neon, allowing gradual adoption.UnusedVariableRule or MissingClosureParameterTypehintRule may flag legitimate patterns (e.g., unused variables in compact() calls or dynamic closures). Requires tuning via phpstan.neon or rule exceptions.not-now-rules.neon (time/date restrictions) is not foolproof (per README) and may break valid use cases (e.g., legacy code).vendor/, but justified for static analysis.StringToClassRule) vs. optional (e.g., not-now-rules)?Illuminate\Container misuse, Eloquent static calls)?laravel-rules.neon) be proposed upstream?ClassNotationRule)?phpstan.neon)?AccessStaticPropertyWithinModelContextRule could conflict with Laravel’s Service Container patterns.ClassNotationRule, StringToClassRule) for initial adoption.slam-rules.neon to phpstan.neon and disable all rules initially.GotoRule, UnusedVariableRule) and fix violations.not-now-rules, MissingClosureParameterTypehintRule) with exceptions.php-cs-fixer) or CI pipelines (GitHub Actions/GitLab CI).AccessStaticPropertyWithinModelContextRule may flag Laravel’s app() helper if misconfigured.vendor/laravel/framework) from analysis.phpstan.neon without conflicts (rules are additive).includes:
- vendor/phpstan/phpstan/src/Rules/basic.neon
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
phpstan.neon before modifications.composer require --dev slam/phpstan-extensions
phpstan.neon:
includes:
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
includes:
- vendor/slam/phpstan-extensions/conf/symfony-rules.neon
phpstan.neon:
arguments:
level: 5
excludeFiles: ['tests/**', 'vendor/**']
rules:
SlamPhpStan\UnusedVariableRule: false # Disable if problematic
composer update).phpstan.neon if rules are added/removed without documentation.STATIC_ANALYSIS.md file.composer.json.SlamPhpStan\UnusedVariableRule).unused-variable).phpstan.neon).How can I help you explore Laravel packages today?