ergebnis / phpstan-rules
Provides rules for phpstan/phpstan.
Package info
github.com/ergebnis/phpstan-rules
Type:phpstan-extension
pkg:composer/ergebnis/phpstan-rules
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0
- composer-runtime-api: ^2.0.0
- ext-mbstring: *
- phpstan/phpstan: ^2.1.35
Requires (Dev)
- codeception/codeception: ^4.0.0 || ^5.0.0
- doctrine/orm: ^2.20.0 || ^3.3.0
- ergebnis/composer-normalize: ^2.54.0
- ergebnis/license: ^2.8.0
- ergebnis/php-cs-fixer-config: ^6.64.1
- ergebnis/phpunit-slow-test-detector: ^2.26.0
- ergebnis/rector-rules: ^1.18.5
- fakerphp/faker: ^1.24.1
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan-deprecation-rules: ^2.0.5
- phpstan/phpstan-phpunit: ^2.1.1
- phpstan/phpstan-strict-rules: ^2.1.0
- phpunit/phpunit: ^9.6.33
- psr/container: ^2.0.2
- rector/rector: ^2.7.0
- symfony/finder: ^5.4.45
- symfony/process: ^5.4.51
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main / 2.16.x-dev
- 2.16.0
- 2.15.0
- 2.14.2
- 2.14.1
- 2.14.0
- 2.13.1
- 2.13.0
- 2.12.0
- 2.11.0
- 2.10.5
- 2.10.4
- 2.10.3
- 2.10.2
- 2.10.1
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 1.0.0
- 0.15.3
- 0.15.2
- 0.15.1
- 0.15.0
- 0.14.4
- 0.14.3
- 0.14.2
- 0.14.1
- 0.14.0
- 0.13.0
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.1
- 0.9.0
- 0.8.1
- 0.8.0
- 0.7.1
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- dev-enhancement/allow-requiring-doctrine-entities-to-be-final
- dev-fix/final-in-abstract-class-rule
- dev-fix/carbon
- dev-fix/add-missing-changelog-entries
- dev-fix/require-documentation-status-check
- dev-fix/align-descriptions-of-rules-for-methods
- dev-enhancement/add-code-samples-to-rule-definitions
- dev-enhancement/add-rationale-to-rule-definitions-and-show-it
- dev-enhancement/no-parameter-with-nullable-type-declaration-rule
- dev-feature/property-hooks
- dev-enhancement/generate-rule-documentation-from-rule-definitions
- dev-fix/no-return-by-reference-rule
- dev-enhancement/no-parameter-passed-by-reference-rule
- dev-enhancement/no-parameter-with-null-default-value-rule
- dev-enhancement/implement-rules-for-arrow-functions
- dev-feature/no-access-to-static-member
This package is auto-updated.
Last update: 2026-10-28 23:55:27 UTC
README
This project provides a composer package with rules for phpstan/phpstan.
Installation
Run
composer require --dev ergebnis/phpstan-rules
Usage
All of the rules provided (and used) by this library are included in rules.neon.
When you are using phpstan/extension-installer, rules.neon will be automatically included.
Otherwise you need to include rules.neon in your phpstan.neon:
includes: - vendor/ergebnis/phpstan-rules/rules.neon
π‘ You probably want to use these rules on top of the rules provided by:
Rules
This package provides the following rules for use with phpstan/phpstan:
Ergebnis\PHPStan\Rules\ArrowFunctions\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\ArrowFunctions\NoParameterPassedByReferenceRuleErgebnis\PHPStan\Rules\ArrowFunctions\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\ArrowFunctions\NoParameterWithNullableTypeDeclarationRuleErgebnis\PHPStan\Rules\CallLikes\NoNamedArgumentRuleErgebnis\PHPStan\Rules\Classes\FinalRuleErgebnis\PHPStan\Rules\Classes\NoExtendsRuleErgebnis\PHPStan\Rules\Classes\PHPUnit\Framework\TestCaseWithSuffixRuleErgebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\Closures\NoParameterPassedByReferenceRuleErgebnis\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRuleErgebnis\PHPStan\Rules\Expressions\NoAssignByReferenceRuleErgebnis\PHPStan\Rules\Expressions\NoCompactRuleErgebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRuleErgebnis\PHPStan\Rules\Expressions\NoEvalRuleErgebnis\PHPStan\Rules\Expressions\NoIssetRuleErgebnis\PHPStan\Rules\Files\DeclareStrictTypesRuleErgebnis\PHPStan\Rules\Files\NoPhpstanIgnoreRuleErgebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\Functions\NoParameterPassedByReferenceRuleErgebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclarationRuleErgebnis\PHPStan\Rules\Functions\NoReturnByReferenceRuleErgebnis\PHPStan\Rules\Methods\FinalInAbstractClassRuleErgebnis\PHPStan\Rules\Methods\InvokeParentHookMethodRuleErgebnis\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRuleErgebnis\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\Methods\NoParameterPassedByReferenceRuleErgebnis\PHPStan\Rules\Methods\NoParameterWithContainerTypeDeclarationRuleErgebnis\PHPStan\Rules\Methods\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRuleErgebnis\PHPStan\Rules\Methods\NoReturnByReferenceRuleErgebnis\PHPStan\Rules\Methods\PrivateInFinalClassRuleErgebnis\PHPStan\Rules\PropertyHooks\NoParameterWithNullableTypeDeclarationRuleErgebnis\PHPStan\Rules\PropertyHooks\NoReturnByReferenceRuleErgebnis\PHPStan\Rules\Statements\NoSwitchRule
ArrowFunctions
ArrowFunctions\NoNullableReturnTypeDeclarationRule
This rule reports an error when an arrow function uses a nullable return type declaration.
π‘ Find out more in the rule documentation for ArrowFunctions\NoNullableReturnTypeDeclarationRule.
ArrowFunctions\NoParameterPassedByReferenceRule
This rule reports an error when an arrow function has a parameter that is passed by reference.
π‘ Find out more in the rule documentation for ArrowFunctions\NoParameterPassedByReferenceRule.
ArrowFunctions\NoParameterWithNullDefaultValueRule
This rule reports an error when an arrow function has a parameter with null as default value.
π‘ Find out more in the rule documentation for ArrowFunctions\NoParameterWithNullDefaultValueRule.
ArrowFunctions\NoParameterWithNullableTypeDeclarationRule
This rule reports an error when an arrow function has a parameter with a nullable type declaration.
π‘ Find out more in the rule documentation for ArrowFunctions\NoParameterWithNullableTypeDeclarationRule.
CallLikes
CallLikes\NoNamedArgumentRule
This rule reports an error when an anonymous function, a function, or a method is invoked using a named argument.
π‘ Find out more in the rule documentation for CallLikes\NoNamedArgumentRule.
Classes
Classes\FinalRule
This rule reports an error when a non-anonymous class is not final.
π‘ By default, this rule ignores classes that
- use
@Entity,@ORM\Entity, or@ORM\Mapping\Entityannotations - use
Doctrine\ORM\Mapping\Entityattributes
on the class level.
π‘ Find out more in the rule documentation for Classes\FinalRule.
Classes\NoExtendsRule
This rule reports an error when a class extends another class.
π‘ Find out more in the rule documentation for Classes\NoExtendsRule.
Classes\PHPUnit\Framework\TestCaseWithSuffixRule
This rule reports an error when a concrete class is a sub-class of PHPUnit\Framework\TestCase but does not have a Test suffix.
π‘ Find out more in the rule documentation for Classes\PHPUnit\Framework\TestCaseWithSuffixRule.
Closures
Closures\NoNullableReturnTypeDeclarationRule
This rule reports an error when a closure uses a nullable return type declaration.
π‘ Find out more in the rule documentation for Closures\NoNullableReturnTypeDeclarationRule.
Closures\NoParameterPassedByReferenceRule
This rule reports an error when a closure has a parameter that is passed by reference.
π‘ Find out more in the rule documentation for Closures\NoParameterPassedByReferenceRule.
Closures\NoParameterWithNullDefaultValueRule
This rule reports an error when a closure has a parameter with null as default value.
π‘ Find out more in the rule documentation for Closures\NoParameterWithNullDefaultValueRule.
Closures\NoParameterWithNullableTypeDeclarationRule
This rule reports an error when a closure has a parameter with a nullable type declaration.
π‘ Find out more in the rule documentation for Closures\NoParameterWithNullableTypeDeclarationRule.
Expressions
Expressions\NoAssignByReferenceRule
This rule reports an error when a variable is assigned by reference.
π‘ Find out more in the rule documentation for Expressions\NoAssignByReferenceRule.
Expressions\NoCompactRule
This rule reports an error when the function compact() is used.
π‘ Find out more in the rule documentation for Expressions\NoCompactRule.
Expressions\NoErrorSuppressionRule
This rule reports an error when @ is used to suppress errors.
π‘ Find out more in the rule documentation for Expressions\NoErrorSuppressionRule.
Expressions\NoEvalRule
This rule reports an error when the language construct eval() is used.
π‘ Find out more in the rule documentation for Expressions\NoEvalRule.
Expressions\NoIssetRule
This rule reports an error when the language construct isset() is used.
π‘ Find out more in the rule documentation for Expressions\NoIssetRule.
Files
Files\DeclareStrictTypesRule
This rule reports an error when a non-empty file does not contain a declare(strict_types=1) declaration.
π‘ Find out more in the rule documentation for Files\DeclareStrictTypesRule.
Files\NoPhpstanIgnoreRule
This rule reports an error when a @phpstan-ignore, @phpstan-ignore-line, or @phpstan-ignore-next-line tag is used to ignore errors reported by phpstan/phpstan.
π‘ Find out more in the rule documentation for Files\NoPhpstanIgnoreRule.
Functions
Functions\NoNullableReturnTypeDeclarationRule
This rule reports an error when a function uses a nullable return type declaration.
π‘ Find out more in the rule documentation for Functions\NoNullableReturnTypeDeclarationRule.
Functions\NoParameterPassedByReferenceRule
This rule reports an error when a function has a parameter that is passed by reference.
π‘ Find out more in the rule documentation for Functions\NoParameterPassedByReferenceRule.
Functions\NoParameterWithNullDefaultValueRule
This rule reports an error when a function has a parameter with null as default value.
π‘ Find out more in the rule documentation for Functions\NoParameterWithNullDefaultValueRule.
Functions\NoParameterWithNullableTypeDeclarationRule
This rule reports an error when a function has a parameter with a nullable type declaration.
π‘ Find out more in the rule documentation for Functions\NoParameterWithNullableTypeDeclarationRule.
Functions\NoReturnByReferenceRule
This rule reports an error when a function returns by reference.
π‘ Find out more in the rule documentation for Functions\NoReturnByReferenceRule.
Methods
Methods\FinalInAbstractClassRule
This rule reports an error when a concrete public or protected method in an abstract class is not final.
π‘ By default, this rule ignores Doctrine entities.
π‘ Find out more in the rule documentation for Methods\FinalInAbstractClassRule.
Methods\InvokeParentHookMethodRule
This rule reports an error when a hook method that overrides a hook method in a parent class does not invoke the overridden hook method in the expected order.
π‘ Find out more in the rule documentation for Methods\InvokeParentHookMethodRule.
Methods\NoConstructorParameterWithDefaultValueRule
This rule reports an error when a constructor has a parameter with a default value.
π‘ Find out more in the rule documentation for Methods\NoConstructorParameterWithDefaultValueRule.
Methods\NoNullableReturnTypeDeclarationRule
This rule reports an error when a method uses a nullable return type declaration.
π‘ Find out more in the rule documentation for Methods\NoNullableReturnTypeDeclarationRule.
Methods\NoParameterPassedByReferenceRule
This rule reports an error when a method has a parameter that is passed by reference.
π‘ Find out more in the rule documentation for Methods\NoParameterPassedByReferenceRule.
Methods\NoParameterWithContainerTypeDeclarationRule
This rule reports an error when a method has a type declaration for a known dependency injection container or service locator.
π‘ Find out more in the rule documentation for Methods\NoParameterWithContainerTypeDeclarationRule.
Methods\NoParameterWithNullDefaultValueRule
This rule reports an error when a method has a parameter with null as default value.
π‘ Find out more in the rule documentation for Methods\NoParameterWithNullDefaultValueRule.
Methods\NoParameterWithNullableTypeDeclarationRule
This rule reports an error when a method has a parameter with a nullable type declaration.
π‘ Find out more in the rule documentation for Methods\NoParameterWithNullableTypeDeclarationRule.
Methods\NoReturnByReferenceRule
This rule reports an error when a method returns by reference.
π‘ Find out more in the rule documentation for Methods\NoReturnByReferenceRule.
Methods\PrivateInFinalClassRule
This rule reports an error when a method in a final class is protected but could be private.
π‘ Find out more in the rule documentation for Methods\PrivateInFinalClassRule.
PropertyHooks
PropertyHooks\NoParameterWithNullableTypeDeclarationRule
This rule reports an error when a property hook has a parameter with a nullable type declaration.
π‘ Find out more in the rule documentation for PropertyHooks\NoParameterWithNullableTypeDeclarationRule.
PropertyHooks\NoReturnByReferenceRule
This rule reports an error when a property hook returns by reference.
π‘ Find out more in the rule documentation for PropertyHooks\NoReturnByReferenceRule.
Statements
Statements\NoSwitchRule
This rule reports an error when the statement switch() is used.
π‘ Find out more in the rule documentation for Statements\NoSwitchRule.
Disabling all rules
You can disable all rules using the allRules configuration parameter:
parameters: ergebnis: allRules: false
Enabling rules one-by-one
If you have disabled all rules using the allRules configuration parameter, you can re-enable individual rules with their corresponding configuration parameters:
parameters: ergebnis: allRules: false privateInFinalClass: enabled: true
Changelog
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this project provide limited support.
PHP Version Support Policy
This project currently supports the following PHP versions:
- PHP 7.4 (has reached its end of life on November 28, 2022)
- PHP 8.0 (has reached its end of life on November 26, 2023)
- PHP 8.1 (has reached its end of life on December 31, 2025)
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5
The maintainers of this project add support for a PHP version following its initial release and may drop support for a PHP version when it has reached its end of life.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Credits
The method FinalRule::isWhitelistedClass() is inspired by the work on FinalClassFixer and FinalInternalClassFixer, contributed by Dariusz RumiΕski, Filippo Tessarotto, and Spacepossum for friendsofphp/php-cs-fixer (originally licensed under MIT).
Social
Follow @localheinz and @ergebnis on X.