localheinz/phpstan-rules
Custom PHPStan rules to enforce stricter coding standards in PHP projects. Includes ready-to-use rules.neon (auto-loaded via phpstan/extension-installer) with checks like no named arguments, class final enforcement, and more. Install via Composer as a dev dependency.
Install the package as a development dependency with composer require --dev ergebnis/phpstan-rules. Include its built-in rules.neon configuration in your main phpstan.neon (automatically handled if using phpstan/extension-installer). Start by running vendor/bin/phpstan analyze to see the new rules in action — they enforce strict, modern PHP idioms, so expect immediate feedback on patterns like missing declare(strict_types=1), non-final classes, or null default values. The simplest first win is enabling declareStrictTypesRule, which ensures every file opt-in to strict typing.
parameters.ergebnis.*.enabled: false to temporarily disable rules during migration (e.g., disable FinalRule while refactoring legacy codebases), then enable gradually.phpstan-rules on fresh repos to enforce idioms like NoNamedArgumentRule (avoiding brittle named args), NoEvalRule, and TestCaseWithSuffixRule for consistent test names.noExtends.classesAllowedToBeExtended to permit base entities from frameworks (e.g., Symfony’s AbstractController) while blocking arbitrary inheritance elsewhere.phpstan-rules check in CI with --error-format=github for actionable PR comments, using the -c flag to point to a dedicated phpstan-rules.neon that extends rules.neon but overrides exclusions as needed.phpstan/phpstan-strict-rules: Both define NoNullableReturnTypeDeclarationRule — ensure your config loads ergebnis/phpstan-rules after to prevent subtle override issues.FinalRule intentionally skips Doctrine entities annotated with @ORM\Entity — ensure your annotations are correct and up-to-date, otherwise false negatives may occur.noIssetRule pitfalls: This rule blocks isset() entirely — consider adding #phpstan-ignore-next-line# for performance-critical null checks on arrays where array_key_exists() is too expensive.FinalRule and NoExtendsRule with IDE features (e.g., PhpStorm’s "Make final" quick fix) to streamline refactoring.vendor/bin/phpstan analyse -c vendor/ergebnis/phpstan-rules/rules.neon to verify the ruleset is correctly loaded, especially if extension-installer fails silently.How can I help you explore Laravel packages today?