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).
thecodingmachine/phpstan-strict-rulesTo push forward the development of this package and the adoption of phpstan v2, this package has been forked, as the original repository seems semi-abandoned. Versioning starts from 2.0 and retains all the features of the original package. Namespace has not been changed.
Once the original project restarts, it is possible that this package would be abandoned. In case the original package is left abandoned for a longer time, this will be a hard fork, with different namespaces and so on...
This package contains a set of rules to be added to the wonderful PHPStan static analyzer.
Those rules come from TheCodingMachine best practices. They are more "strict" than the default PHPStan rules and some may be controversial. We use those at TheCodingMachine, have found them to help us in our daily work, and ask anyone working with us to follow them.
Throwable, an Exception or a RuntimeException, you must rethrow the exception.$_GET, $_POST, $_FILES, $_COOKIE, $_SESSION, $_REQUEST is forbidden.
You should instead use your framework's request/session object.index.php to initialize
PSR-7 request object)// Never use public properties
// Never use globals
We assume that PHPStan is already installed in your project.
To use this extension, require it in Composer:
composer require --dev thecodingmachine/phpstan-strict-rules
If you also install phpstan/extension-installer then you're all set!
If you don't want to use phpstan/extension-installer, include phpstan-strict-rules.neon in your project's PHPStan config:
includes:
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
How can I help you explore Laravel packages today?