Provides additional rules for phpstan/phpstan
.
Run
$ composer require --dev localheinz/phpstan-rules
All of the rules provided (and used) by this library are included in rules.neon
. The easiest way to use these rules in your project is to include rules.neon
in your phpstan.neon
:
includes:
- vendor/localheinz/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
:
Localheinz\PHPStan\Rules\Classes\FinalRule
Localheinz\PHPStan\Rules\Classes\NoExtendsRule
Localheinz\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule
Localheinz\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRule
Localheinz\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRule
Localheinz\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRule
Localheinz\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule
Localheinz\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclaration
Localheinz\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRule
Localheinz\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRule
Localheinz\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRule
Localheinz\PHPStan\Rules\Methods\NoParameterWithNullDefaultValueRule
This rule reports an error when a non-anonymous class is not final
.
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:
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:
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:
classesAllowedToBeExtended:
- Localheinz\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 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 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 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.
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.