Provides additional rules for phpstan/phpstan
.
Run
$ composer require --dev ergebnis/phpstan-rules
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:
This package provides the following rules for use with phpstan/phpstan
:
Ergebnis\PHPStan\Rules\Classes\FinalRule
Ergebnis\PHPStan\Rules\Classes\NoExtendsRule
Ergebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule
Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRule
Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRule
Ergebnis\PHPStan\Rules\Expressions\NoCompactRule
Ergebnis\PHPStan\Rules\Expressions\NoEmptyRule
Ergebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRule
Ergebnis\PHPStan\Rules\Expressions\NoEvalRule
Ergebnis\PHPStan\Rules\Expressions\NoIssetRule
Ergebnis\PHPStan\Rules\Files\DeclareStrictTypesRule
Ergebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRule
Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclaration
Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule
Ergebnis\PHPStan\Rules\Methods\FinalInAbstractClassRule
Ergebnis\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRule
Ergebnis\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRule
Ergebnis\PHPStan\Rules\Methods\NoParameterWithContainerTypeDeclarationRule
Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRule
Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullDefaultValueRule
Ergebnis\PHPStan\Rules\Methods\PrivateInFinalClassRule
Ergebnis\PHPStan\Rules\Statements\NoSwitchRule
This rule reports an error when a non-anonymous class is not final
.
💡 Doctrine entities are currently ignored when they are annotated with @ORM\Entity
or @Entity
.
By default, this rule allows to declare abstract
classes. If you want to disallow declaring abstract
classes, you can set the allowAbstractClasses
parameter to false
:
parameters:
ergebnis:
allowAbstractClasses: false
If you want to exclude classes from being inspected by this rule, you can set the classesNotRequiredToBeAbstractOrFinal
parameter to a list of class names:
parameters:
ergebnis:
classesNotRequiredToBeAbstractOrFinal:
- Foo\Bar\NeitherAbstractNorFinal
- Bar\Baz\NeitherAbstractNorFinal
This rule reports an error when a class extends another class.
By default, this rule allows the following classes to be extended:
If you want to allow additional classes to be extended, you can set the classesAllowedToBeExtended
parameter to a list of class names:
parameters:
ergebnis:
classesAllowedToBeExtended:
- Ergebnis\PHPStan\Rules\Test\Integration\AbstractTestCase
- PHPStan\Testing\RuleTestCase
This rule reports an error when a closure uses a nullable return type declaration.
This rule reports an error when a closure has a parameter with a nullable type declaration.
This rule reports an error when a closure has a parameter with null
as default value.
This rule reports an error when the function compact()
is used.
This rule reports an error when the language construct empty()
is used.
This rule reports an error when the language construct eval()
is used.
This rule reports an error when @
is used to suppress errors.
This rule reports an error when the language construct isset()
is used.
This rule reports an error when a non-empty file does not contain a declare(strict_types=1)
declaration.
This rule reports an error when a function uses a nullable return type declaration.
This rule reports an error when a function has a parameter with a nullable type declaration.
This rule reports an error when a function has a parameter with null
as default value.
This rule reports an error when a concrete public
or protected
method in an abstract
class is not final
.
This rule reports an error when a constructor declared in
- an anonymous class
- a class
has a default value.
This rule reports an error when a method declared in
- an anonymous class
- a class
- an interface
uses a nullable return type declaration.
This 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.
If you want to configure the list of interfaces implemented by dependency injection containers and service locators yourself, you can set the interfacesImplementedByContainers
parameter to a list of interface names:
parameters:
ergebnis:
interfacesImplementedByContainers:
- Fancy\DependencyInjection\ContainerInterface
- Other\ServiceLocatorInterface
This rule reports an error when a method declared in
- an anonymous class
- a class
- an interface
has a parameter with a nullable type declaration.
This rule reports an error when a method declared in
- an anonymous class
- a class
- an interface
has a parameter with null
as default value.
This rule reports an error when a method in a final
class is protected
but could be private
.
This rule reports an error when the statement switch()
is used.
Please have a look at CHANGELOG.md
.
Please have a look at CONTRIBUTING.md
.
Please have a look at CODE_OF_CONDUCT.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).