ergebnis/phpstan-rules
A set of extra PHPStan rules to enforce stricter, opinionated code standards in PHP projects. Install via Composer and include rules.neon (auto via phpstan/extension-installer) to catch issues like named arguments, class design, and more.
Install the package as a development dependency:
composer require --dev ergebnis/phpstan-rules
If you use phpstan/extension-installer, the rules are auto-loaded via rules.neon. Otherwise, include it manually in your phpstan.neon:
includes:
- vendor/ergebnis/phpstan-rules/rules.neon
Start using the rules — they’re opinionated but practical: enforce strict types, forbid eval, disallow nullable types, require final on classes, and more. Run vendor/bin/phpstan analyze to see immediate feedback.
rules.neon in the PHPStan config of new repositories to enforce consistent quality from day one.final: enabled: false) in phpstan.neon while migrating legacy code, then incrementally re-enable.testCaseWithSuffix and noExtends (allowing TestCase) to enforce naming and composition best practices in test suites.phpstan in a Git hook to block commits violating these rules — especially useful for declare(strict_types=1), noEval, and noErrorSuppression.classesAllowedToBeExtended, allowAbstractClasses) rather than disabling entire categories.noIsset can be aggressive: Using isset() for array-key checking (e.g., isset($arr['key'])) is common practice. Consider disabling noIsset or selectively ignoring specific uses via // @phpstan-ignore (though that’ll trigger noPhpstanIgnore if you have that enabled).declare(strict_types=1) enforcement: Applies to non-empty files only — omit the directive in files with only declare(strict_types=1); and docblocks, and PHPStan will let it slide.final class exceptions: Doctrine entities (via annotations or attributes) are exempted automatically — don’t manually override unless you're using a custom metadata driver.noParameterWithNullableTypeDeclaration and noNullableReturnTypeDeclaration help enforce non-nullable-first design but may cause noise in transitional codebases. Disable selectively or use union types (int|null → int) once nullable inputs are handled upstream.parameters.ergebnis.*, so avoid collisions with other PHPStan rules. Double-check indentation in phpstan.neon when disabling/adjusting — a common YAML pitfall.phpstan-ignore comments allowed: noPhpstanIgnore catches all @phpstan-ignore* docblocks. Use only in exceptional cases and ensure you document why in a PR comment, not in code — otherwise the tool itself penalizes its workaround.How can I help you explore Laravel packages today?