Search by

ergebnis / phpstan-rules

localheinz

Provides rules for phpstan/phpstan.

Package info

github.com/ergebnis/phpstan-rules

Type:phpstan-extension

pkg:composer/ergebnis/phpstan-rules

Statistics

Installs: 12 062 978

Dependents: 208

Suggesters: 3

Stars: 460

Open Issues: 2

2.16.0 2026-10-28 23:53 UTC

README

Integrate Merge Release Renew

Code Coverage

Latest Stable Version Total Downloads Monthly Downloads

This project provides a composer package with rules for phpstan/phpstan.

Installation

Run

composer require --dev ergebnis/phpstan-rules

Usage

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:

Rules

This package provides the following rules for use with phpstan/phpstan:

ArrowFunctions

ArrowFunctions\NoNullableReturnTypeDeclarationRule

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.

ArrowFunctions\NoParameterPassedByReferenceRule

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.

ArrowFunctions\NoParameterWithNullDefaultValueRule

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.

ArrowFunctions\NoParameterWithNullableTypeDeclarationRule

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.

CallLikes

CallLikes\NoNamedArgumentRule

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.

Classes

Classes\FinalRule

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\Entity annotations
  • use Doctrine\ORM\Mapping\Entity attributes

on the class level.

πŸ’‘ Find out more in the rule documentation for Classes\FinalRule.

Classes\NoExtendsRule

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

πŸ’‘ Find out more in the rule documentation for Classes\NoExtendsRule.

Classes\PHPUnit\Framework\TestCaseWithSuffixRule

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.

Closures

Closures\NoNullableReturnTypeDeclarationRule

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

πŸ’‘ Find out more in the rule documentation for Closures\NoNullableReturnTypeDeclarationRule.

Closures\NoParameterPassedByReferenceRule

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.

Closures\NoParameterWithNullDefaultValueRule

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.

Closures\NoParameterWithNullableTypeDeclarationRule

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.

Expressions

Expressions\NoAssignByReferenceRule

This rule reports an error when a variable is assigned by reference.

πŸ’‘ Find out more in the rule documentation for Expressions\NoAssignByReferenceRule.

Expressions\NoCompactRule

This rule reports an error when the function compact() is used.

πŸ’‘ Find out more in the rule documentation for Expressions\NoCompactRule.

Expressions\NoErrorSuppressionRule

This rule reports an error when @ is used to suppress errors.

πŸ’‘ Find out more in the rule documentation for Expressions\NoErrorSuppressionRule.

Expressions\NoEvalRule

This rule reports an error when the language construct eval() is used.

πŸ’‘ Find out more in the rule documentation for Expressions\NoEvalRule.

Expressions\NoIssetRule

This rule reports an error when the language construct isset() is used.

πŸ’‘ Find out more in the rule documentation for Expressions\NoIssetRule.

Files

Files\DeclareStrictTypesRule

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.

Files\NoPhpstanIgnoreRule

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.

Functions

Functions\NoNullableReturnTypeDeclarationRule

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

πŸ’‘ Find out more in the rule documentation for Functions\NoNullableReturnTypeDeclarationRule.

Functions\NoParameterPassedByReferenceRule

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.

Functions\NoParameterWithNullDefaultValueRule

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.

Functions\NoParameterWithNullableTypeDeclarationRule

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.

Functions\NoReturnByReferenceRule

This rule reports an error when a function returns by reference.

πŸ’‘ Find out more in the rule documentation for Functions\NoReturnByReferenceRule.

Methods

Methods\FinalInAbstractClassRule

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.

Methods\InvokeParentHookMethodRule

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.

Methods\NoConstructorParameterWithDefaultValueRule

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.

Methods\NoNullableReturnTypeDeclarationRule

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

πŸ’‘ Find out more in the rule documentation for Methods\NoNullableReturnTypeDeclarationRule.

Methods\NoParameterPassedByReferenceRule

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.

Methods\NoParameterWithContainerTypeDeclarationRule

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.

Methods\NoParameterWithNullDefaultValueRule

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.

Methods\NoParameterWithNullableTypeDeclarationRule

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.

Methods\NoReturnByReferenceRule

This rule reports an error when a method returns by reference.

πŸ’‘ Find out more in the rule documentation for Methods\NoReturnByReferenceRule.

Methods\PrivateInFinalClassRule

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.

PropertyHooks

PropertyHooks\NoParameterWithNullableTypeDeclarationRule

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.

PropertyHooks\NoReturnByReferenceRule

This rule reports an error when a property hook returns by reference.

πŸ’‘ Find out more in the rule documentation for PropertyHooks\NoReturnByReferenceRule.

Statements

Statements\NoSwitchRule

This rule reports an error when the statement switch() is used.

πŸ’‘ Find out more in the rule documentation for Statements\NoSwitchRule.

Disabling all rules

You can disable all rules using the allRules configuration parameter:

parameters:
	ergebnis:
		allRules: false

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

The maintainers of this project record notable changes to this project in a changelog.

Contributing

The maintainers of this project suggest following the contribution guide.

Code of Conduct

The maintainers of this project ask contributors to follow the code of conduct.

General Support Policy

The maintainers of this project provide limited support.

PHP Version Support Policy

This project currently supports the following PHP versions:

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.

Security Policy

This project has a security policy.

License

This project uses the MIT license.

Credits

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).

Social

Follow @localheinz and @ergebnis on X.