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).
Exception throws, and missing switch-case defaults, this package helps prevent production bugs and security vulnerabilities early in the development cycle. This supports broader goals like SOC 2 compliance or zero bug bounties.$_GET, $_POST), reducing friction between custom code and framework conventions.--level configuration to avoid overwhelming the team.Adopt if:
Request, Session).--level=0, then ramp up to stricter levels).Look elsewhere if:
phpstan/phpstan-symfony.thecodingmachine/phpstan-strict-rules is revived and actively maintained (monitor forks).public properties in Eloquent models).*"This package is a low-cost, high-impact way to reduce bugs and security risks in our PHP/Laravel codebase. By adopting these stricter PHPStan rules—enforced automatically in our CI pipeline—we’ll catch critical issues like:
Exception throws).$_GET, $_POST—replaced with Laravel’s Request object).This aligns with our goals for [security compliance/zero bug bounties] while requiring minimal upfront effort. Think of it as ‘static analysis on autopilot’—no manual code reviews needed for these edge cases.
Key Outcomes:
Ask: Should we pilot this in [Project X] to measure impact before rolling out company-wide?"*
*"We’re proposing to add kcs/phpstan-strict-rules to our PHPStan setup to enforce TheCodingMachine’s battle-tested PHP best practices. This will catch:
Exception, empty catch blocks, or not wrapping exceptions.$_GET, $_POST, etc.—replaced with Laravel’s Request object.default cases in switches, public properties.How it works:
composer require --dev kcs/phpstan-strict-rules
phpstan.neon (or use phpstan/extension-installer for zero config).--level=0 to avoid overwhelming the team, then ramp up.Why now?
Trade-offs:
Next Steps:
vendor/bin/phpstan analyse --level=max).Example CI Integration:
# .github/workflows/phpstan.yml
jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: vendor/bin/phpstan analyse --level=5 --error-format=github
Questions for the Team:
NoPublicPropertiesRule for Eloquent)?pint, php-cs-fixer)?"*How can I help you explore Laravel packages today?