This project provides a composer package with rules for phpstan/phpstan.
Run
composer require --dev ergebnis/phpstan-rulesAll 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:
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
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.
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.
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.
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.
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.
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.
This rule reports an error when a class extends another class.
π‘ Find out more in the rule documentation for Classes\NoExtendsRule.
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.
This rule reports an error when a closure uses a nullable return type declaration.
π‘ Find out more in the rule documentation for Closures\NoNullableReturnTypeDeclarationRule.
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.
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.
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.
This rule reports an error when a variable is assigned by reference.
π‘ Find out more in the rule documentation for Expressions\NoAssignByReferenceRule.
This rule reports an error when the function compact() is used.
π‘ Find out more in the rule documentation for Expressions\NoCompactRule.
This rule reports an error when @ is used to suppress errors.
π‘ Find out more in the rule documentation for Expressions\NoErrorSuppressionRule.
This rule reports an error when the language construct eval() is used.
π‘ Find out more in the rule documentation for Expressions\NoEvalRule.
This rule reports an error when the language construct isset() is used.
π‘ Find out more in the rule documentation for Expressions\NoIssetRule.
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.
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.
This rule reports an error when a function uses a nullable return type declaration.
π‘ Find out more in the rule documentation for Functions\NoNullableReturnTypeDeclarationRule.
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.
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.
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.
This rule reports an error when a function returns by reference.
π‘ Find out more in the rule documentation for Functions\NoReturnByReferenceRule.
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.
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.
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.
This rule reports an error when a method uses a nullable return type declaration.
π‘ Find out more in the rule documentation for Methods\NoNullableReturnTypeDeclarationRule.
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.
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.
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.
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.
This rule reports an error when a method returns by reference.
π‘ Find out more in the rule documentation for Methods\NoReturnByReferenceRule.
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.
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.
This rule reports an error when a property hook returns by reference.
π‘ Find out more in the rule documentation for PropertyHooks\NoReturnByReferenceRule.
This rule reports an error when the statement switch() is used.
π‘ Find out more in the rule documentation for Statements\NoSwitchRule.
You can disable all rules using the allRules configuration parameter:
parameters:
ergebnis:
allRules: falseIf 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: trueThe maintainers of this project record notable changes to this project in a changelog.
The maintainers of this project suggest following the contribution guide.
The maintainers of this project ask contributors to follow the code of conduct.
The maintainers of this project provide limited support.
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.
This project has a security policy.
This project uses the MIT license.
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).
Follow @localheinz and @ergebnis on X.