kcs/phpstan-strict-rules
Fork of thecodingmachine/phpstan-strict-rules to support PHPStan v2. Adds stricter best-practice rules beyond core PHPStan, especially around exception handling (avoid throwing base Exception, empty catches, proper rethrowing).
with() macros) or legacy model visibility.index.php or bootstrap/app.php (though root-scope exemptions mitigate this).__get()/__set() magic.phpstan/extension-installer or manual phpstan.neon configuration.--level) to avoid breaking changes.phpstan/laravel for framework-specific rules.--generate-baseline to baseline existing code and phase in rules incrementally.Route::input()) or legacy bootstrap code.throw new HttpResponseException).public properties) may require refactoring (e.g., converting Eloquent models to use protected properties).ForbiddenSuperglobalsRule or NoPublicPropertiesRule?app/Http/Controllers/ be exempt from superglobal checks?routes/web.php)? Options:
pint or PHP-CS-Fixer for unified formatting + static analysis?roave/security-advisories?node_modules, vendor).public properties are banned)?protected or a getter").phpstan/laravel: Combine with Laravel-specific rules for comprehensive coverage.phpstan/phpunit: Enforce testing best practices alongside code quality.phpstan/extension-installer: Zero-config integration via Composer.vimeo/psalm: If team prefers Psalm over PHPStan.request()->input()). Mitigate by:
app/Http/ from superglobal checks.phpstan.neon overrides:
rules:
TheCodingMachine\StrictRules\Rules\ForbiddenSuperglobalsRule:
excludeFiles: ['app/Http/**', 'routes/**']
throw new \App\Exceptions\Handler).protected instead of public).Preparation:
>=1.10.0 for PHPStan v2 support).phpstan.neon configurations.vendor/bin/phpstan analyse --generate-baseline
Pilot Phase:
composer require --dev kcs/phpstan-strict-rules
# phpstan.neon
includes:
- vendor/kcs/phpstan-strict-rules/phpstan-strict-rules.neon
level: max
rules:
TheCodingMachine\StrictRules\Rules\:
- "ExceptionSubtypingRule" # Enable first (low impact)
- "NoEmptyCatchRule" # Enable next
- "ForbiddenSuperglobalsRule" # Exclude paths: see below
- "DefaultCaseInSwitchRule" # Enable last
paths:
exclude:
- "app/Http/**" # Exempt facades
- "routes/**" # Exempt legacy superglobals
Gradual Rollout:
app/Http/, routes/).NoPublicPropertiesRule).# .github/workflows/phpstan.yml
jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: vendor/bin/phpstan analyse --level=max --error-format=github
Post-Rollout:
public properties are discouraged).How can I help you explore Laravel packages today?