PHPackages                             localheinz/phpstan-rules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. localheinz/phpstan-rules

Abandoned → [ergebnis/phpstan-rules](/?search=ergebnis%2Fphpstan-rules)Phpstan-extension[Testing &amp; Quality](/categories/testing)

localheinz/phpstan-rules
========================

Provides rules for phpstan/phpstan.

2.13.1(3mo ago)443146.9k↑175%22[6 issues](https://github.com/ergebnis/phpstan-rules/issues)[3 PRs](https://github.com/ergebnis/phpstan-rules/pulls)6MITPHPPHP ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

Since Nov 13Pushed 1mo ago6 watchersCompare

[ Source](https://github.com/ergebnis/phpstan-rules)[ Packagist](https://packagist.org/packages/localheinz/phpstan-rules)[ Docs](https://github.com/ergebnis/phpstan-rules)[ RSS](/packages/localheinz-phpstan-rules/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (59)Used By (6)

phpstan-rules
=============

[](#phpstan-rules)

[![Integrate](https://github.com/ergebnis/phpstan-rules/workflows/Integrate/badge.svg)](https://github.com/ergebnis/phpstan-rules/actions)[![Merge](https://github.com/ergebnis/phpstan-rules/workflows/Merge/badge.svg)](https://github.com/ergebnis/phpstan-rules/actions)[![Release](https://github.com/ergebnis/phpstan-rules/workflows/Release/badge.svg)](https://github.com/ergebnis/phpstan-rules/actions)[![Renew](https://github.com/ergebnis/phpstan-rules/workflows/Renew/badge.svg)](https://github.com/ergebnis/phpstan-rules/actions)

[![Code Coverage](https://camo.githubusercontent.com/d3d5b430673b63612736b699c722a3338fda803b9f14c28d02b541a7d5bc3f75/68747470733a2f2f636f6465636f762e696f2f67682f65726765626e69732f7068707374616e2d72756c65732f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/ergebnis/phpstan-rules)

[![Latest Stable Version](https://camo.githubusercontent.com/5475689de4ed1f81ef69ef7cd16b47bfcae073495cf24ff387932aadfe9a8045/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f7068707374616e2d72756c65732f762f737461626c65)](https://packagist.org/packages/ergebnis/phpstan-rules)[![Total Downloads](https://camo.githubusercontent.com/353629c9312163f2c0a1bf7dc229e2894780e8b6ea7d853b6dac606b5a47382b/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f7068707374616e2d72756c65732f646f776e6c6f616473)](https://packagist.org/packages/ergebnis/phpstan-rules)[![Monthly Downloads](https://camo.githubusercontent.com/352f6f36a85a16d892c8fce832abb28d31997b3c97750df9cecbcacd6142d895/687474703a2f2f706f7365722e707567782e6f72672f65726765626e69732f7068707374616e2d72756c65732f642f6d6f6e74686c79)](https://packagist.org/packages/ergebnis/phpstan-rules)

This project provides a [`composer`](https://getcomposer.org) package with rules for [`phpstan/phpstan`](https://github.com/phpstan/phpstan).

Installation
------------

[](#installation)

Run

```
composer require --dev ergebnis/phpstan-rules
```

Usage
-----

[](#usage)

All of the [rules](https://github.com/ergebnis/phpstan-rules#rules) provided (and used) by this library are included in [`rules.neon`](rules.neon).

When you are using [`phpstan/extension-installer`](https://github.com/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:

- [`phpstan/phpstan`](https://github.com/phpstan/phpstan)
- [`phpstan/phpstan-deprecation-rules`](https://github.com/phpstan/phpstan-deprecation-rules)
- [`phpstan/phpstan-strict-rules`](https://github.com/phpstan/phpstan-strict-rules)

Rules
-----

[](#rules)

This package provides the following rules for use with [`phpstan/phpstan`](https://github.com/phpstan/phpstan):

- [`Ergebnis\PHPStan\Rules\CallLikes\NoNamedArgumentRule`](https://github.com/ergebnis/phpstan-rules#calllikesnonamedargumentrule)
- [`Ergebnis\PHPStan\Rules\Classes\FinalRule`](https://github.com/ergebnis/phpstan-rules#classesfinalrule)
- [`Ergebnis\PHPStan\Rules\Classes\NoExtendsRule`](https://github.com/ergebnis/phpstan-rules#classesnoextendsrule)
- [`Ergebnis\PHPStan\Rules\Classes\PHPUnit\Framework\TestCaseWithSuffixRule`](https://github.com/ergebnis/phpstan-rules#classesphpunitframeworktestcasewithsuffixrule)
- [`Ergebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule`](https://github.com/ergebnis/phpstan-rules#closuresnonullablereturntypedeclarationrule)
- [`Ergebnis\PHPStan\Rules\Closures\NoParameterPassedByReferenceRule`](https://github.com/ergebnis/phpstan-rules#closuresnoparameterpassedbyreferencerule)
- [`Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRule`](https://github.com/ergebnis/phpstan-rules#closuresnoparameterwithnullabletypedeclarationrule)
- [`Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRule`](https://github.com/ergebnis/phpstan-rules#closuresnoparameterwithnulldefaultvaluerule)
- [`Ergebnis\PHPStan\Rules\Expressions\NoAssignByReferenceRule`](https://github.com/ergebnis/phpstan-rules#expressionsnoassignbyreferencerule)
- [`Ergebnis\PHPStan\Rules\Expressions\NoCompactRule`](https://github.com/ergebnis/phpstan-rules#expressionsnocompactrule)
- [`Ergebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRule`](https://github.com/ergebnis/phpstan-rules#expressionsnoerrorsuppressionrule)
- [`Ergebnis\PHPStan\Rules\Expressions\NoEvalRule`](https://github.com/ergebnis/phpstan-rules#expressionsnoevalrule)
- [`Ergebnis\PHPStan\Rules\Expressions\NoIssetRule`](https://github.com/ergebnis/phpstan-rules#expressionsnoissetrule)
- [`Ergebnis\PHPStan\Rules\Files\DeclareStrictTypesRule`](https://github.com/ergebnis/phpstan-rules#filesdeclarestricttypesrule)
- [`Ergebnis\PHPStan\Rules\Files\NoPhpstanIgnoreRule`](https://github.com/ergebnis/phpstan-rules#filesnophpstanignorerule)
- [`Ergebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRule`](https://github.com/ergebnis/phpstan-rules#functionsnonullablereturntypedeclarationrule)
- [`Ergebnis\PHPStan\Rules\Functions\NoParameterPassedByReferenceRule`](https://github.com/ergebnis/phpstan-rules#functionsnoparameterpassedbyreferencerule)
- [`Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclarationRule`](https://github.com/ergebnis/phpstan-rules#functionsnoparameterwithnullabletypedeclarationrule)
- [`Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule`](https://github.com/ergebnis/phpstan-rules#functionsnoparameterwithnulldefaultvaluerule)
- [`Ergebnis\PHPStan\Rules\Functions\NoReturnByReferenceRule`](https://github.com/ergebnis/phpstan-rules#functionsnoreturnbyreferencerule)
- [`Ergebnis\PHPStan\Rules\Methods\FinalInAbstractClassRule`](https://github.com/ergebnis/phpstan-rules#methodsfinalinabstractclassrule)
- [`Ergebnis\PHPStan\Rules\Methods\InvokeParentHookMethodRule`](https://github.com/ergebnis/phpstan-rules#methodsinvokeparenthookmethodrule)
- [`Ergebnis\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRule`](https://github.com/ergebnis/phpstan-rules#methodsnoconstructorparameterwithdefaultvaluerule)
- [`Ergebnis\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRule`](https://github.com/ergebnis/phpstan-rules#methodsnonullablereturntypedeclarationrule)
- [`Ergebnis\PHPStan\Rules\Methods\NoParameterPassedByReferenceRule`](https://github.com/ergebnis/phpstan-rules#methodsnoparameterpassedbyreferencerule)
- [`Ergebnis\PHPStan\Rules\Methods\NoParameterWithContainerTypeDeclarationRule`](https://github.com/ergebnis/phpstan-rules#methodsnoparameterwithcontainertypedeclarationrule)
- [`Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRule`](https://github.com/ergebnis/phpstan-rules#methodsnoparameterwithnullabletypedeclarationrule)
- [`Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullDefaultValueRule`](https://github.com/ergebnis/phpstan-rules#methodsnoparameterwithnulldefaultvaluerule)
- [`Ergebnis\PHPStan\Rules\Methods\NoReturnByReferenceRule`](https://github.com/ergebnis/phpstan-rules#methodsnoreturnbyreferencerule)
- [`Ergebnis\PHPStan\Rules\Methods\PrivateInFinalClassRule`](https://github.com/ergebnis/phpstan-rules#methodsprivateinfinalclassrule)
- [`Ergebnis\PHPStan\Rules\Statements\NoSwitchRule`](https://github.com/ergebnis/phpstan-rules#statementsnoswitchrule)

### CallLikes

[](#calllikes)

#### `CallLikes\NoNamedArgumentRule`

[](#calllikesnonamedargumentrule)

This rule reports an error when an anonymous function, a function, or a method is invoked using a [named argument](https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments).

##### Disabling the rule

[](#disabling-the-rule)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noNamedArgument:
			enabled: false
```

### Classes

[](#classes)

#### `Classes\FinalRule`

[](#classesfinalrule)

This rule reports an error when a non-anonymous class is not `final`.

💡 This rule ignores classes that

- use `@Entity`, `@ORM\Entity`, or `@ORM\Mapping\Entity` annotations
- use `Doctrine\ORM\Mapping\Entity` attributes

on the class level.

##### Disabling the rule

[](#disabling-the-rule-1)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		final:
			enabled: false
```

##### Disallowing `abstract` classes

[](#disallowing-abstract-classes)

By default, this rule allows to declare `abstract` classes.

You can set the `allowAbstractClasses` parameter to `false` to disallow abstract classes.

```
parameters:
	ergebnis:
		final:
			allowAbstractClasses: false
```

##### Excluding classes from inspection

[](#excluding-classes-from-inspection)

You 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\NeitherAbstractNorFinal
```

#### `Classes\NoExtendsRule`

[](#classesnoextendsrule)

This rule reports an error when a class extends another class.

##### Defaults

[](#defaults)

By default, this rule allows the following classes to be extended:

- [`PHPUnit\Framework\TestCase`](https://github.com/sebastianbergmann/phpunit/blob/6.0.0/src/Framework/TestCase.php)

##### Disabling the rule

[](#disabling-the-rule-2)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noExtends:
			enabled: false
```

##### Allowing classes to be extended

[](#allowing-classes-to-be-extended)

You 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\AbstractTestCase
```

#### `Classes\PHPUnit\Framework\TestCaseWithSuffixRule`

[](#classesphpunitframeworktestcasewithsuffixrule)

This rule reports an error when a concrete class is a sub-class of `PHPUnit\Framework\TestCase` but does not have a `Test` suffix.

##### Disabling the rule

[](#disabling-the-rule-3)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		testCaseWithSuffix:
			enabled: false
```

### Closures

[](#closures)

#### `Closures\NoNullableReturnTypeDeclarationRule`

[](#closuresnonullablereturntypedeclarationrule)

This rule reports an error when a closure uses a nullable return type declaration.

##### Disabling the rule

[](#disabling-the-rule-4)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noNullableReturnTypeDeclaration:
			enabled: false
```

#### `Closures\NoParameterPassedByReferenceRule`

[](#closuresnoparameterpassedbyreferencerule)

This rule reports an error when a closure has a parameter that is [passed by reference](https://www.php.net/manual/en/language.references.pass.php).

##### Disabling the rule

[](#disabling-the-rule-5)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterPassedByReference:
			enabled: false
```

#### `Closures\NoParameterWithNullableTypeDeclarationRule`

[](#closuresnoparameterwithnullabletypedeclarationrule)

This rule reports an error when a closure has a parameter with a nullable type declaration.

##### Disabling the rule

[](#disabling-the-rule-6)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterWithNullableTypeDeclaration:
			enabled: false
```

#### `Closures\NoParameterWithNullDefaultValueRule`

[](#closuresnoparameterwithnulldefaultvaluerule)

This rule reports an error when a closure has a parameter with `null` as default value.

##### Disabling the rule

[](#disabling-the-rule-7)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterWithNullDefaultValue:
			enabled: false
```

### Expressions

[](#expressions)

#### `Expressions\NoAssignByReferenceRule`

[](#expressionsnoassignbyreferencerule)

This rule reports an error when [a variable is assigned by reference](https://www.php.net/manual/en/language.references.whatdo.php#language.references.whatdo.assign).

##### Disabling the rule

[](#disabling-the-rule-8)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noAssignByReference:
			enabled: false
```

#### `Expressions\NoCompactRule`

[](#expressionsnocompactrule)

This rule reports an error when the function [`compact()`](https://www.php.net/compact) is used.

##### Disabling the rule

[](#disabling-the-rule-9)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noCompact:
			enabled: false
```

#### `Expressions\NoErrorSuppressionRule`

[](#expressionsnoerrorsuppressionrule)

This rule reports an error when [`@`](https://www.php.net/manual/en/language.operators.errorcontrol.php) is used to suppress errors.

##### Disabling the rule

[](#disabling-the-rule-10)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noErrorSuppression:
			enabled: false
```

#### `Expressions\NoEvalRule`

[](#expressionsnoevalrule)

This rule reports an error when the language construct [`eval()`](https://www.php.net/eval) is used.

##### Disabling the rule

[](#disabling-the-rule-11)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noEval:
			enabled: false
```

#### `Expressions\NoIssetRule`

[](#expressionsnoissetrule)

This rule reports an error when the language construct [`isset()`](https://www.php.net/isset) is used.

##### Disabling the rule

[](#disabling-the-rule-12)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noIsset:
			enabled: false
```

### Files

[](#files)

#### `Files\DeclareStrictTypesRule`

[](#filesdeclarestricttypesrule)

This rule reports an error when a non-empty file does not contain a `declare(strict_types=1)` declaration.

##### Disabling the rule

[](#disabling-the-rule-13)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		declareStrictTypes:
			enabled: false
```

#### `Files\NoPhpstanIgnoreRule`

[](#filesnophpstanignorerule)

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`](https://phpstan.org/user-guide/ignoring-errors#ignoring-in-code-using-phpdocs).

##### Disabling the rule

[](#disabling-the-rule-14)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noPhpstanIgnore:
			enabled: false
```

### Functions

[](#functions)

#### `Functions\NoNullableReturnTypeDeclarationRule`

[](#functionsnonullablereturntypedeclarationrule)

This rule reports an error when a function uses a nullable return type declaration.

##### Disabling the rule

[](#disabling-the-rule-15)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noNullableReturnTypeDeclaration:
			enabled: false
```

#### `Functions\NoParameterPassedByReferenceRule`

[](#functionsnoparameterpassedbyreferencerule)

This rule reports an error when a function has a parameter that is [passed by reference](https://www.php.net/manual/en/language.references.pass.php).

##### Disabling the rule

[](#disabling-the-rule-16)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterPassedByReference:
			enabled: false
```

#### `Functions\NoParameterWithNullableTypeDeclarationRule`

[](#functionsnoparameterwithnullabletypedeclarationrule)

This rule reports an error when a function has a parameter with a nullable type declaration.

##### Disabling the rule

[](#disabling-the-rule-17)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterWithNullableTypeDeclaration:
			enabled: false
```

#### `Functions\NoParameterWithNullDefaultValueRule`

[](#functionsnoparameterwithnulldefaultvaluerule)

This rule reports an error when a function has a parameter with `null` as default value.

##### Disabling the rule

[](#disabling-the-rule-18)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterWithNullDefaultValue:
			enabled: false
```

#### `Functions\NoReturnByReferenceRule`

[](#functionsnoreturnbyreferencerule)

This rule reports an error when a function [returns by reference](https://www.php.net/manual/en/language.references.return.php).

##### Disabling the rule

[](#disabling-the-rule-19)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noReturnByReference:
			enabled: false
```

### Methods

[](#methods)

#### `Methods\FinalInAbstractClassRule`

[](#methodsfinalinabstractclassrule)

This rule reports an error when a concrete `public` or `protected` method in an `abstract` class is not `final`.

💡 This rule ignores

- Doctrine embeddables
- Doctrine entities

##### Disabling the rule

[](#disabling-the-rule-20)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		finalInAbstractClass:
			enabled: false
```

#### `Methods\InvokeParentHookMethodRule`

[](#methodsinvokeparenthookmethodrule)

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.

##### Defaults

[](#defaults-1)

By default, this rule requires the following hook methods to be invoked before doing something in the overriding method:

- [`Codeception\PHPUnit\TestCase::_setUp()`](https://github.com/Codeception/phpunit-wrapper/blob/9.0.0/src/TestCase.php#L11-L13)
- [`Codeception\PHPUnit\TestCase::_setUpBeforeClass()`](https://github.com/Codeception/phpunit-wrapper/blob/9.0.0/src/TestCase.php#L25-L27)
- [`Codeception\Test\Unit::_before()`](https://github.com/Codeception/Codeception/blob/4.2.2/src/Codeception/Test/Unit.php#L63-L65)
- [`Codeception\Test\Unit::_setUp()`](https://github.com/Codeception/Codeception/blob/4.2.2/src/Codeception/Test/Unit.php#L34-L58)
- [`PHPUnit\Framework\TestCase::assertPreConditions()`](https://github.com/sebastianbergmann/phpunit/blob/6.0.0/src/Framework/TestCase.php#L2073-L2075)
- [`PHPUnit\Framework\TestCase::setUp()`](https://github.com/sebastianbergmann/phpunit/blob/6.0.0/src/Framework/TestCase.php#L2063-L2065)
- [`PHPUnit\Framework\TestCase::setUpBeforeClass()`](https://github.com/sebastianbergmann/phpunit/blob/6.0.0/src/Framework/TestCase.php#L2055-L2057)

By default, this rule requires the following hook methods to be invoked after doing something in the overriding method:

- [`Codeception\PHPUnit\TestCase::_tearDown()`](https://github.com/Codeception/phpunit-wrapper/blob/9.0.0/src/TestCase.php#L18-L20)
- [`Codeception\PHPUnit\TestCase::_tearDownAfterClass()`](https://github.com/Codeception/phpunit-wrapper/blob/9.0.0/src/TestCase.php#L32-L34)
- [`Codeception\Test\Unit::_after()`](https://github.com/Codeception/Codeception/blob/4.2.2/src/Codeception/Test/Unit.php#L75-L77)
- [`Codeception\Test\Unit::_tearDown()`](https://github.com/Codeception/Codeception/blob/4.2.2/src/Codeception/Test/Unit.php#L67-L70)
- [`PHPUnit\Framework\TestCase::assertPostConditions()`](https://github.com/sebastianbergmann/phpunit/blob/6.0.0/src/Framework/TestCase.php#L2083-L2085)
- [`PHPUnit\Framework\TestCase::tearDown()`](https://github.com/sebastianbergmann/phpunit/blob/6.0.0/src/Framework/TestCase.php#L2091-L2093)
- [`PHPUnit\Framework\TestCase::tearDownAfterClass()`](https://github.com/sebastianbergmann/phpunit/blob/6.0.0/src/Framework/TestCase.php#L2098-L2100)

##### Disabling the rule

[](#disabling-the-rule-21)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		invokeParentHookMethod:
			enabled: false
```

##### Configuring methods to invoke the parent method in the right order:

[](#configuring-methods-to-invoke-the-parent-method-in-the-right-order)

You can set the `hookMethods` parameter to a list of hook methods:

```
parameters:
	ergebnis:
		invokeParentHookMethod:
			hookMethods:
				- className: "Example\Test\Functional\AbstractCest"
					methodName: "_before"
					hasContent: "yes"
					invocation: "first"
```

- `className`: name of the class that declares the hook method
- `methodName`: name of the hook method
- `hasContent`: one of `"yes"`, `"no"`, `"maybe"`
- `invocation`: one of `"any"` (needs to be invoked), `"first"` (needs to be invoked before all other statements in the overriding hook method, `"last"` (needs to be invoked after all other statements in the overriding hook method)

#### `Methods\NoConstructorParameterWithDefaultValueRule`

[](#methodsnoconstructorparameterwithdefaultvaluerule)

This rule reports an error when a constructor declared in

- an anonymous class
- a class

has a default value.

##### Disabling the rule

[](#disabling-the-rule-22)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noConstructorParameterWithDefaultValue:
			enabled: false
```

#### `Methods\NoParameterPassedByReferenceRule`

[](#methodsnoparameterpassedbyreferencerule)

This rule reports an error when a method has a parameter that is [passed by reference](https://www.php.net/manual/en/language.references.pass.php).

##### Disabling the rule

[](#disabling-the-rule-23)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterPassedByReference:
			enabled: false
```

#### `Methods\NoNullableReturnTypeDeclarationRule`

[](#methodsnonullablereturntypedeclarationrule)

This rule reports an error when a method declared in

- an anonymous class
- a class
- an interface

uses a nullable return type declaration.

##### Disabling the rule

[](#disabling-the-rule-24)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noNullableReturnTypeDeclaration:
			enabled: false
```

#### `Methods\NoParameterWithContainerTypeDeclarationRule`

[](#methodsnoparameterwithcontainertypedeclarationrule)

This rule reports an error when a method has a type declaration for a known dependency injection container or service locator.

##### Defaults

[](#defaults-2)

By default, this rule disallows the use of type declarations indicating an implementation of

- [`Psr\Container\ContainerInterface`](https://github.com/php-fig/container/blob/1.0.0/src/ContainerInterface.php)

is expected to be injected into a method.

##### Disabling the rule

[](#disabling-the-rule-25)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterWithContainerTypeDeclaration:
			enabled: false
```

##### Configuring container interfaces

[](#configuring-container-interfaces)

You 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\ServiceLocatorInterface
```

##### Configuring methods allowed to use parameters with container type declarations

[](#configuring-methods-allowed-to-use-parameters-with-container-type-declarations)

You 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:
				- loadExtension
```

#### `Methods\NoParameterWithNullableTypeDeclarationRule`

[](#methodsnoparameterwithnullabletypedeclarationrule)

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.

##### Disabling the rule

[](#disabling-the-rule-26)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterWithNullableTypeDeclaration:
			enabled: false
```

#### `Methods\NoParameterWithNullDefaultValueRule`

[](#methodsnoparameterwithnulldefaultvaluerule)

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.

##### Disabling the rule

[](#disabling-the-rule-27)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noParameterWithNullDefaultValue:
			enabled: false
```

#### `Functions\NoReturnByReferenceRule`

[](#functionsnoreturnbyreferencerule-1)

This rule reports an error when a method [returns by reference](https://www.php.net/manual/en/language.references.return.php).

##### Disabling the rule

[](#disabling-the-rule-28)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noReturnByReference:
			enabled: false
```

#### `Methods\PrivateInFinalClassRule`

[](#methodsprivateinfinalclassrule)

This rule reports an error when a method in a `final` class is `protected` but could be `private`.

##### Disabling the rule

[](#disabling-the-rule-29)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		privateInFinalClass:
			enabled: false
```

### Statements

[](#statements)

#### `Statements\NoSwitchRule`

[](#statementsnoswitchrule)

This rule reports an error when the statement [`switch()`](https://www.php.net/manual/control-structures.switch.php) is used.

##### Disabling the rule

[](#disabling-the-rule-30)

You can set the `enabled` parameter to `false` to disable this rule.

```
parameters:
	ergebnis:
		noSwitch:
			enabled: false
```

Disabling all rules
-------------------

[](#disabling-all-rules)

You can disable all rules using the `allRules` configuration parameter:

```
parameters:
	ergebnis:
		allRules: false
```

Enabling rules one-by-one
-------------------------

[](#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
---------

[](#changelog)

The maintainers of this project record notable changes to this project in a [changelog](CHANGELOG.md).

Contributing
------------

[](#contributing)

The maintainers of this project suggest following the [contribution guide](.github/CONTRIBUTING.md).

Code of Conduct
---------------

[](#code-of-conduct)

The maintainers of this project ask contributors to follow the [code of conduct](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md).

General Support Policy
----------------------

[](#general-support-policy)

The maintainers of this project provide limited support.

You can support the maintenance of this project by [sponsoring @ergebnis](https://github.com/sponsors/ergebnis).

PHP Version Support Policy
--------------------------

[](#php-version-support-policy)

This project supports PHP versions with [active and security support](https://www.php.net/supported-versions.php).

The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.

Security Policy
---------------

[](#security-policy)

This project has a [security policy](.github/SECURITY.md).

License
-------

[](#license)

This project uses the [MIT license](LICENSE.md).

Credits
-------

[](#credits)

The method [`FinalRule::isWhitelistedClass()`](src/Classes/FinalRule.php) is inspired by the work on [`FinalClassFixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/2.15/src/Fixer/ClassNotation/FinalClassFixer.php) and [`FinalInternalClassFixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/2.15/src/Fixer/ClassNotation/FinalInternalClassFixer.php), contributed by [Dariusz Rumiński](https://github.com/keradus), [Filippo Tessarotto](https://github.com/Slamdunk), and [Spacepossum](https://github.com/SpacePossum) for [`friendsofphp/php-cs-fixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer) (originally licensed under MIT).

Social
------

[](#social)

Follow [@localheinz](https://twitter.com/intent/follow?screen_name=localheinz) and [@ergebnis](https://twitter.com/intent/follow?screen_name=ergebnis) on Twitter.

###  Health Score

68

—

FairBetter than 100% of packages

Maintenance84

Actively maintained with recent releases

Popularity50

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity92

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~52 days

Total

51

Last Release

111d ago

Major Versions

0.15.3 → 1.0.02021-11-08

1.0.0 → 2.0.02023-05-01

PHP version history (8 changes)0.1.0PHP ^7.1

0.14.0PHP ^7.2

0.15.3PHP ^7.2 || ^8.0

2.0.0PHP ~8.0.0 || ~8.1.0 || ~8.2.0

2.1.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0

2.3.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

2.5.0PHP ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

2.11.0PHP ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8cabc9efd157e2b47aa5aa9830180f5ebd07813cc3e93ff1a9993b2c3d264909?d=identicon)[localheinz](/maintainers/localheinz)

---

Top Contributors

[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (838 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (552 commits)")[![ergebnis-bot](https://avatars.githubusercontent.com/u/59560144?v=4)](https://github.com/ergebnis-bot "ergebnis-bot (525 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (86 commits)")[![enumag](https://avatars.githubusercontent.com/u/539462?v=4)](https://github.com/enumag "enumag (2 commits)")[![manuelkiessling](https://avatars.githubusercontent.com/u/206592?v=4)](https://github.com/manuelkiessling "manuelkiessling (1 commits)")[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (1 commits)")[![rpkamp](https://avatars.githubusercontent.com/u/1059790?v=4)](https://github.com/rpkamp "rpkamp (1 commits)")[![Slamdunk](https://avatars.githubusercontent.com/u/152236?v=4)](https://github.com/Slamdunk "Slamdunk (1 commits)")[![williamrijksen](https://avatars.githubusercontent.com/u/1991582?v=4)](https://github.com/williamrijksen "williamrijksen (1 commits)")[![cosmastech](https://avatars.githubusercontent.com/u/42181698?v=4)](https://github.com/cosmastech "cosmastech (1 commits)")[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (1 commits)")[![dmecke](https://avatars.githubusercontent.com/u/1172148?v=4)](https://github.com/dmecke "dmecke (1 commits)")[![Great-Antique](https://avatars.githubusercontent.com/u/1128310?v=4)](https://github.com/Great-Antique "Great-Antique (1 commits)")[![hpatoio](https://avatars.githubusercontent.com/u/249948?v=4)](https://github.com/hpatoio "hpatoio (1 commits)")[![johnbillion](https://avatars.githubusercontent.com/u/208434?v=4)](https://github.com/johnbillion "johnbillion (1 commits)")

---

Tags

phpstanphpstan-rulesPHPStanphpstan-rules

###  Code Quality

TestsPHPUnit

Type Coverage Yes

### Embed Badge

![Health badge](/badges/localheinz-phpstan-rules/health.svg)

```
[![Health](https://phpackages.com/badges/localheinz-phpstan-rules/health.svg)](https://phpackages.com/packages/localheinz-phpstan-rules)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[ekino/phpstan-banned-code

Detected banned code using PHPStan

2925.6M92](/packages/ekino-phpstan-banned-code)[shipmonk/dead-code-detector

Dead code detector to find unused PHP code via PHPStan extension. Can automatically remove dead PHP code. Supports libraries like Symfony, Doctrine, PHPUnit etc. Detects dead cycles. Can detect dead code that is tested.

3462.2M52](/packages/shipmonk-dead-code-detector)[szepeviktor/phpstan-wordpress

WordPress extensions for PHPStan

3287.8M898](/packages/szepeviktor-phpstan-wordpress)[staabm/phpstan-dba

2912.3M2](/packages/staabm-phpstan-dba)[staabm/phpstan-todo-by

1991.8M55](/packages/staabm-phpstan-todo-by)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
