Stars: 310
Forks: 18
Pull Requests: 600
Issues: 24
Watchers: 6
Last Updated: 2023-09-15 10:34:03
:eyeglasses: Provides additional rules for phpstan/phpstan.
License: MIT License
Languages: PHP, Makefile
Provides additional 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\Classes\FinalRuleErgebnis\PHPStan\Rules\Classes\NoExtendsRuleErgebnis\PHPStan\Rules\Classes\PHPUnit\Framework\TestCaseWithSuffixRuleErgebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRuleErgebnis\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\Expressions\NoCompactRuleErgebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRuleErgebnis\PHPStan\Rules\Expressions\NoEvalRuleErgebnis\PHPStan\Rules\Expressions\NoIssetRuleErgebnis\PHPStan\Rules\Files\DeclareStrictTypesRuleErgebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclarationErgebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\Methods\FinalInAbstractClassRuleErgebnis\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRuleErgebnis\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\Methods\NoParameterWithContainerTypeDeclarationRuleErgebnis\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRuleErgebnis\PHPStan\Rules\Methods\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\Methods\PrivateInFinalClassRuleErgebnis\PHPStan\Rules\Statements\NoSwitchRuleClasses\FinalRuleThis rule reports an error when a non-anonymous class is not final.
💡 This rule ignores classes that
@Entity, @ORM\Entity, or @ORM\Mapping\Entity annotationsDoctrine\ORM\Mapping\Entity attributeson the class level.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
final:
enabled: falseabstract classesBy default, this rule allows to declare abstract classes.
You can set the allowAbstractClasses parameter to false to disallow abstract classes.
parameters:
ergebnis:
final:
allowAbstractClasses: falseYou can set the classesNotRequiredToBeAbstractOrFinal parameter to a list of class names that you want to exclude from inspection.
parameters:
ergebnis:
final:
classesNotRequiredToBeAbstractOrFinal:
- Foo\Bar\NeitherAbstractNorFinal
- Bar\Baz\NeitherAbstractNorFinalClasses\NoExtendsRuleThis rule reports an error when a class extends another class.
By default, this rule allows the following classes to be extended:
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noExtends:
enabled: falseYou can set the classesAllowedToBeExtended parameter to a list of class names that you want to allow to be extended.
parameters:
ergebnis:
noExtends:
classesAllowedToBeExtended:
- Ergebnis\PHPStan\Rules\Test\Integration\AbstractTestCase
- Ergebnis\PHPStan\Rules\Test\Integration\AbstractTestCaseClasses\PHPUnit\Framework\TestCaseWithSuffixRuleThis rule reports an error when a concrete class is a sub-class of PHPUnit\Framework\TestCase but does not have a Test suffix.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
testCaseWithSuffix:
enabled: falseClosures\NoNullableReturnTypeDeclarationRuleThis rule reports an error when a closure uses a nullable return type declaration.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noNullableReturnTypeDeclaration:
enabled: falseClosures\NoParameterWithNullableTypeDeclarationRuleThis rule reports an error when a closure has a parameter with a nullable type declaration.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noParameterWithNullableTypeDeclaration:
enabled: falseClosures\NoParameterWithNullDefaultValueRuleThis rule reports an error when a closure has a parameter with null as default value.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noParameterWithNullDefaultValue:
enabled: falseExpressions\NoCompactRuleThis rule reports an error when the function compact() is used.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noCompact:
enabled: falseExpressions\NoEvalRuleThis rule reports an error when the language construct eval() is used.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noEval:
enabled: falseExpressions\NoErrorSuppressionRuleThis rule reports an error when @ is used to suppress errors.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noErrorSuppression:
enabled: falseExpressions\NoIssetRuleThis rule reports an error when the language construct isset() is used.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noIsset:
enabled: falseFiles\DeclareStrictTypesRuleThis rule reports an error when a non-empty file does not contain a declare(strict_types=1) declaration.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
declareStrictTypes:
enabled: falseFunctions\NoNullableReturnTypeDeclarationRuleThis rule reports an error when a function uses a nullable return type declaration.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noNullableReturnTypeDeclaration:
enabled: falseFunctions\NoParameterWithNullableTypeDeclarationRuleThis rule reports an error when a function has a parameter with a nullable type declaration.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noParameterWithNullableTypeDeclaration:
enabled: falseFunctions\NoParameterWithNullDefaultValueRuleThis rule reports an error when a function has a parameter with null as default value.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noParameterWithNullDefaultValue:
enabled: falseMethods\FinalInAbstractClassRuleThis rule reports an error when a concrete public or protected method in an abstract class is not final.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
finalInAbstractClass:
enabled: falseMethods\NoConstructorParameterWithDefaultValueRuleThis rule reports an error when a constructor declared in
has a default value.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noConstructorParameterWithDefaultValue:
enabled: falseMethods\NoNullableReturnTypeDeclarationRuleThis rule reports an error when a method declared in
uses a nullable return type declaration.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noNullableReturnTypeDeclaration:
enabled: falseMethods\NoParameterWithContainerTypeDeclarationRuleThis rule reports an error when a method has a type declaration for a known dependency injection container or service locator.
By default, this rule disallows the use of type declarations indicating an implementation of
is expected to be injected into a method.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noParameterWithContainerTypeDeclaration:
enabled: falseYou can set the interfacesImplementedByContainers parameter to a list of interface names of additional containers and service locators.
parameters:
ergebnis:
noParameterWithContainerTypeDeclaration:
interfacesImplementedByContainers:
- Fancy\DependencyInjection\ContainerInterface
- Other\ServiceLocatorInterfaceYou can set the methodsAllowedToUseContainerTypeDeclarations parameter to a list of method names that are allowed to use parameters with container type declarations.
parameters:
ergebnis:
noParameterWithContainerTypeDeclaration:
methodsAllowedToUseContainerTypeDeclarations:
- loadExtensionMethods\NoParameterWithNullableTypeDeclarationRuleThis rule reports an error when a method declared in
has a parameter with a nullable type declaration.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noParameterWithNullableTypeDeclaration:
enabled: falseMethods\NoParameterWithNullDefaultValueRuleThis rule reports an error when a method declared in
has a parameter with null as default value.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noParameterWithNullDefaultValue:
enabled: falseMethods\PrivateInFinalClassRuleThis rule reports an error when a method in a final class is protected but could be private.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
privateInFinalClass:
enabled: falseStatements\NoSwitchRuleThis rule reports an error when the statement switch() is used.
You can set the the enabled parameter to false to disable this rule.
parameters:
ergebnis:
noSwitch:
enabled: falsePlease have a look at CHANGELOG.md.
Please have a look at CONTRIBUTING.md.
Please have a look at CODE_OF_CONDUCT.md.
Please have a look at SECURITY.md.
This package is licensed using the MIT License.
Please have a look at LICENSE.md.
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 me on Twitter!