Code Inspections in PHP
This topic lists all PhpStorm code inspections available in PHP.
You can toggle specific inspections or change their severity level on the Editor | Inspections page of the IDE settings Ctrl+Alt+S.
Control flow
| Inspection | Description | Default Severity |
|---|---|---|
| Array write access is not used | Reports the array write access expressions that are not used in code afterwards. The most common source of such problems is modifying an array passed via a parameter: if an array is passed by value, the change will not be visible outside the function. | |
| Condition always evaluates to 'true/false' | Reports the conditions that are already covered by earlier conditions and thus have no effect. | |
| Expression is always 'null' | Reports return variables which are effectively 'null' | |
| Loop does not iterate | Reports the loop statements whose bodies will execute at most once. | |
| Result of 'instanceof' is always 'true' | Reports the | |
| Typed Property might be uninitialized | Reports the attempts to read from an uninitialized typed property. Such attempts will result in
See Uninitialized and Unset Properties (php.net) for details. | |
| Unreachable statement | Reports the statements that cannot be normally reached. | |
| Variable is always true/false when reached | Reports variables that are always | |
Composer
| Inspection | Description | Default Severity |
|---|---|---|
| Duplicate package entries in composer.json | Reports duplicate package entries in the | |
| Extension is missing in composer.json | Reports the usages of classes, functions, and constants from the PHP extensions not specified in composer.json. | |
| Non-installed Composer packages | Reports the Composer packages that are required in composer.json but are not installed. | |
| Quality tool inspection is disabled | Highlights the quality tools' entries in composer.json in case the corresponding code inspections are disabled. | |
| Unresolved file references | Reports unresolved file references in composer.json. | |
Undefined
| Inspection | Description | Default Severity |
|---|---|---|
| Possible polymorphic call | Reports polymorphic code usages. Such usages are ambiguous and can be potentially inoperable depending on the class instance passed as the argument. | |
| Undefined callback | Reports the functions, methods, properties, or classes that are referenced from a callback but are not found.
| Disabled |
| Undefined class | Produces two types of warnings:
Use the options below to customize the inspection:
| |
| Undefined class constant | Reports the references to class constants that are not declared. | |
| Undefined constant | Reports the references to constants that are not found in the built-in library and project files. | |
| Undefined function | Reports the references to functions that are not defined in the built-in library and project files. | |
| Undefined goto label | Reports the | |
| Undefined method | Reports the references to class methods that are not defined. | |
| Undefined namespace | Reports the references to a namespace that is not found. | |
| Undefined property | Reports the references to class properties that are not declared. | |
| Undefined variable | Produces two types of warnings:
Use the options below to customize the inspection:
| |
Replaceable assignments
| Inspection | Description | Default Severity |
|---|---|---|
| Assignment replaceable with increment or decrement | Reports the assignments that can be replaced with incrementing ( | |
| Assignment replaceable with operator assignment | Reports the assignments that can be replaced with combined operator assignments (for example, | |
PHPUnit
| Inspection | Description | Default Severity |
|---|---|---|
| Covered function reference is provided without ‘::’ | Reports the references to functions/methods in the | |
| Deprecated @covers/@uses by access modifier annotation | Reports the | |
| Deprecated assertContains/assertNotContains usage | Reports deprecated usages of the | |
| Deprecated assertEquals/assertNotEquals usage | Reports deprecated usages of the | |
| Deprecated assertFileEquals/assertStringEqualsFile usage | Reports the deprecated usages of the | |
| Deprecated exception handling via doc tags | Reports the usages of the following deprecated PHPUnit doc tags:
| |
| Deprecated expectException usage | Reports deprecated usages of | |
| Method assertArrayHasKey/assertArrayNotHasKey can be used instead | Reports alternative usage of the | |
| Misordered assertEquals/assertNotEquals arguments | Reports any calls to PHPUnit | |
| Missing target element for PHPUnit test | Reports the test classes and methods, for which no target elements were found. | |
| Undefined PHPUnit data provider | Detects that the method referenced in the | |
| Usage assertCount/assertSameSize methods instead of assertEquals | Reports alternative usage of the | |
PSR-12
| Inspection | Description | Default Severity |
|---|---|---|
| Compound namespace depth is more than 2 | Reports the usages of compound namespaces whose depth exceeds two levels. | Disabled |
| Else if | Reports the usages of the | Disabled |
| Missing parameter list | Reports missing parameter lists in a classes' instantiations. | Disabled |
| Missing visibility | Reports properties, constants, and methods that are declared without visibility definition.
See PSR-12: Extended Coding Style (php-fig.org) for details. | Disabled |
| One-per-line trait uses | Reports the cases of several traits being imported via a single | Disabled |
| Order of modifiers | Reports visibility modifiers that are specified in the incorrect order.
See PSR-12: Extended Coding Style (php-fig.org) for details. | Disabled |
| Short form of type keywords | Reports usages of long form type keywords. | Disabled |
| Usage of var | Reports the usages of the | Disabled |
Unused
| Inspection | Description | Default Severity |
|---|---|---|
| Redundant property initializer | Reports the fields with default initializers that are always overwritten in the class constructor. | |
| Unused declaration | Reports the classes, methods, functions, constants, or properties that are not used or not reachable from entry points. It also reports all method implementations/overriders. | |
| Unused import | Reports the imports that are never used. | |
| Unused local variable | Reports the variables that are considered unused in the following cases:
By default, the inspection is disabled for global space. To enable it, select the Enable inspection in global space checkbox below. See global space (php.net) for details. | |
| Unused parameter | Reports the parameters that are considered unused in the following cases:
| |
| Unused private method | Reports the private methods that are never used. | |
| Unused private property | Reports the private properties that are never used. | |
Attributes
| Inspection | Description | Default Severity |
|---|---|---|
| '#[ArrayShape]' attribute can be added | Reports the methods and functions that are returning arrays with known non-trivial keys. Suggests specifying the shape of the returned array via the | |
| '#[Pure]' attribute can be added | Reports the functions that are non-trivially pure. Such functions have other functions calls in their body, but all such calls do not produce any side effects. | |
| Array key does not match array shape | Reports the array keys that do not match the keys specified via the | |
| Attribute can be added to overriding member | Reports the methods' and parameters' attributes that can be propagated to overriding methods/parameters. | |
| Class cannot be used as attribute | Reports the attributes that are resolved to a class not annotated with | |
| Comment is parsed as attribute in PHP 8.0 | Reports line comments starting with | |
| Expected values should be used | Reports the values in assignment and comparison expressions that should be replaced with one of the expected values (that is, the values specified via the | |
| Immutable property written in invalid scope | Highlights write access references to properties, for which the write access scope declared via | |
| NoReturn attribute can be added | Reports function without | |
| Non-applicable attribute target declaration | Reports the attributes that do not have the appropriate | |
| Non-repeatable attribute | Reports repeated attributes without the | |
| Pure function may produce side effects | Reports the | |
| Redundant parentheses in attribute | Reports empty arguments lists in attributes. | |
Code smell
| Inspection | Description | Default Severity |
|---|---|---|
| '__toString' may throw an exception | Reports the usages of | |
| Argument of 'instanceof' should be only objects or strings | Reports arguments of 'instanceof' that are not objects or strings | |
| Array used only with write access | Reports local arrays that are only updated, but never queried. | |
| Case mismatch in method call or class usage | Reports the usages of functions, methods, classes, and namespaces that do not match the case used in their declarations. | Disabled |
| Duplicate branch in 'catch' statement | Reports | |
| Inconsistent return points | Reports inconsistencies in function/method exit points.
Technically these are not errors, but practically they usually indicate a programming mistake. | |
| Logical expression has same operands | Reports the expressions that use the same operands, but should rather use different operands. | |
| Match expression has only default arm and should be simplified | Reports match expressions with only default match arm | |
| Method visibility shouldn't be overridden | Checks that the methods don't override visibility. | Disabled |
| Parameters number mismatch declaration | Reports the function/method calls that take more parameters than specified in their declaration. | |
| Private property can be local | Reports the private properties that are used only in a single method. Such properties can be replaced with local variables. | |
| Redundant 'static' in final class | Reports | |
| Redundant assignment to promoted property | Reports redundant assignments to class properties that duplicate automatic assignments performed through promoted constructor parameters. | |
| Redundant optional argument | Reports redundant arguments that match the corresponding default values for optional parameters. | |
| Ternary expression can be replaced with condition | Reports the ternary expressions specified as | |
| Too many parameters in function declaration | Reports the function/method declarations with the number of parameters exceeding the specified limit. | Disabled |
| Unnecessary 'return' statement | Reports unnecessary | |
| Unnecessary local variable | Reports the local variables that are used in exit statements, such as | |
| Unnecessary pass-by-ref | Reports elements that have | |
| Unnecessary semicolon | Reports unnecessary semicolons. | |
| Usage of a silence operator | Reports the usages of the silence operator ( | Disabled |
| Useless trailing comma | Reports the trailing commas in parameters lists and closures'
| |
PHP strict standards
| Inspection | Description | Default Severity |
|---|---|---|
| Declaration of overridden method should be compatible with parent class | Reports the overridden methods declarations that are not compatible with the parent class. The inspection is enabled only for PHP language level lower than 8.0. | |
| Static function should not be abstract | Reports the static methods that are declared as abstract. | |
Code style
| Inspection | Description | Default Severity |
|---|---|---|
| 'array_fill' can be converted to loop | Reports the | |
| 'array_filter' can be converted to loop | Reports the | |
| 'array_map' call can be converted to loop | Reports the | |
| 'get_class' can be replaced with '::class' | Reports the | |
| 'match' expression can be replace with ternary expression | Reports match expressions with default arm and only one non-default arm | |
| 'mixed' return type can be narrowed | Reports 'mixed' return types that can be narrowed down to more concrete types. | |
| 'str*' calls can be replaced with PHP 8 'str_*' calls | Reports the | |
| 'switch' can be replaced with 'match' expression | Reports 'switch' statements that could be replaced with 'match' expression | |
| Class path doesn't match project structure | Reports the classes with the filepath not following the PSR-0/PSR-4 project structure. | |
| Closure can be converted to arrow function | Reports the anonymous functions that can be transformed to short arrow functions. Support for short arrow functions is available since PHP 7.4. | |
| Control statement body without braces |
| |
| Expression without clarifying parentheses | Reports potentially ambiguous expressions and proposes enclosing them in clarifying parentheses. | |
| Fully qualified name usage | Reports the fully qualified class names that can be shortened by adding the | |
| Loop can be converted to 'array_fill' | Reports the | |
| Loop can be converted to 'array_filter' call | Reports the | |
| Loop can be converted to 'array_map' call | Reports the | |
| Method may be 'static' | Reports the methods that don't use any instance references and thus may be converted to static methods. | |
| Multiple classes declarations in one file | Reports multiple class declarations in a single file, which violates the PSR-0/PSR-4 standards. | |
| Named arguments order does not match parameters order | Reports named argument with order that does not match parameter order | |
| Old style constructor | Reports old-style constructor declarations ( | |
| Redundant closing tag | Reports PHP closing tag | |
| Short open tag usage | Reports short PHP opening tag | Disabled |
| Single-statement body with braces |
| |
| Traditional syntax array literal detected | Reports traditional array syntax ( | Disabled |
| Trait use rule resolved to method with different containing class | Reports the trait method | |
| Unnecessary double quotes | Reports double-quoted string literals that do not contain string interpolation, escape sequences, or single quotes. | Disabled |
| Unnecessary fully qualified name | Reports the usages of fully qualified class names, which can be shortened without adding the | |
| Unnecessary parentheses | Reports the expressions containing redundant parenthesis, which can be safely removed. | |
| Usage of a variable variable | Reports the usages of variable variables (dynamic variable names). | Disabled |
Probable bugs
| Inspection | Description | Default Severity |
|---|---|---|
| Assignment in condition | Reports the assignments that are used in conditional expressions. | |
| Constant reassignment | Reports reassignments of constants. | |
| Division by zero | Reports division by zero or modulo by zero. | Disabled |
| Duplicate arm in 'match' expression | Reports duplicate bodies in | |
| Duplicate array keys | Reports duplicate keys in array declarations. | |
| Duplicate branch in switch statement |
| |
| Duplicate case in switch statement | Reports duplicate | |
| Duplicate condition | Reports duplicate conditions in | |
| Expression result unused | Reports expressions that are calculated, but the calculation result is not used anywhere. | |
| Foreach array is used as value | Reports the variables that are used as both an array expression and an array's key or value in | |
| Format function parameters mismatch | Reports the parameters and specification conversion entries that are passed as the format function's arguments but are not mapped to any entries. | |
| Goto into loop statement | Reports the | |
| Invalid type of unpacked argument |
| |
| Method __toString implementation | Reports the attempts to convert the objects having no | |
| Method __toString return type | Reports the | |
| Missing 'break' statement | Reports the | |
| Missing parent call for constructor | Reports the constructors that do not call their parent constructor. | |
| Missing parent call for magic methods | Reports the magic methods that do not call their parent magic method. | Disabled |
| Missing parent call for method | Reports the methods that do not call their parent method. | Disabled |
| Nested vs outer 'foreach' variables conflict | Reports the variables that are used as a key or value both by the inner and outer | |
| Non-strict object equality | Reports the usages of the comparison operator (
See Comparing Objects (php.net) for details. | |
| Optional before required parameter | Reports the optional parameters that appear before the required parameters in function/method declaration. | |
| Pass parameter by reference | Reports the arguments in a function/method call that cannot be passed by reference. | |
| Silly assignment | Reports the assignment statements, in which both sides are equal. Such assignments have no effect and can be removed. | |
| Statement has empty body | Reports the statements that have empty bodies. | |
| Switch statement without default branch |
| |
| Unnecessary statement use | Reports the | |
| Unused 'match' condition | Reports the conditions in | |
| Void function result used | Reports the attempts to use the value of a | |
| Wrong string concatenation | Reports the attempts to concatenate strings by using the | |
Naming conventions
| Inspection | Description | Default Severity |
|---|---|---|
| Class name is not following coding convention | Reports the classes' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for classes. | Disabled |
| Constant name is not following coding convention | Reports the constants' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for constants. | Disabled |
| Function name is not following coding convention | Reports the functions' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for functions. | Disabled |
| Method name is not following coding convention | Reports the methods' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for methods. | Disabled |
| Property name is not following coding convention | Reports the properties' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for properties. | Disabled |
| Variable name is not following coding convention | Reports the variables' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for variables. | Disabled |
General
| Inspection | Description | Default Severity |
|---|---|---|
| Argument with name identifier | Reports arguments with name identifiers. | |
| Argument without name identifier | Reports arguments without name identifiers. | |
| Class can't implement Traversable directly | Reports the classes that are implementing the | |
| Class hierarchy checks | Checks the classes' hierarchy: abstract methods implementation, the compatibility of implementing/overriding methods with their declarations in parent classes, and properties' types redeclarations. | |
| Curly brace access syntax usage |
| |
| Deprecated | Reports the usages of deprecated entities. | |
| Deprecated cast | Reports deprecated cast expressions:
See Deprecated features in PHP 7.2.x (php.net) and Deprecations for PHP 7.4 (php.net) for details. | |
| Deprecated implode/join usage | Reports deprecated usage of the | |
| Disabled extension stubs | Reports the usages of classes, functions, and constants, for which the extension stubs are disabled. | |
| Dynamic method called as static | Reports static calls to dynamic class methods. | |
| Element is not available in configured PHP version | Reports the usages of entities which were introduced in PHP version later than configured one. | |
| Ignored class alias declaration | Reports the class alias declarations that are ignored by the IDE because the actual class declaration with the same FQN exists. | |
| Incorrect magic method signature | Reports incompatible magic methods signatures. | |
| Invalid magic method modifiers | Reports magic methods that are not declared as | |
| Language level | Reports the language features used in source code that are not supported for the selected language level. | |
| Method declaration of super class is incompatible with implemented interface | Reports the methods declarations in parent classes that are incompatible with implemented interfaces. | |
| Named argument may be unresolved | Reports the named arguments in method calls that might be unresolved depending on a specific class instance within the hierarchy. | |
| Nested ternary operator usage |
| |
| Parameter's name changed during inheritance | Reports the methods' parameters whose names differ from the same parameters defined in parent methods. Starting with PHP 8.0, such code can cause runtime errors. | |
| Promoted property usage | Reports properties declared through promoted constructor parameters. | |
| Property can be promoted | Reports the properties that can be replaced with promoted versions. | |
| Static method called as dynamic | Reports dynamic calls to static class methods. | Disabled |
| Unresolved include | Reports non-resolved | |
| Usage of internal entity | Reports the usages of the entities that are marked as | |
Error handling
| Inspection | Description | Default Severity |
|---|---|---|
| Redundant catch clause | Reports the | |
| Unhandled exception | Reports the exceptions that are neither enclosed in a | |
| Wrong catch clauses order | Reports the | |
Type compatibility
| Inspection | Description | Default Severity |
|---|---|---|
| Illegal array key type | Reports the array keys that are of illegal type, such as objects or arrays. | |
| Illegal string offset | Reports the usages of non- | |
| Incompatible return type | Reports the | |
| Invalid argument supplied for foreach() | Reports the | |
| Missing parameter's type declaration | Reports the parameters that have no type declaration specified. | |
| Missing property's type declaration | Reports the properties that have no type declaration. | |
| Missing return type declaration | Reports the functions that have no return type declaration specified. | |
| Missing strict types declaration | Detects the missing | Disabled |
| PHP 8 TypeError on arithmetic operations | Reports arithmetic and bitwise expressions with unsupported operands. | |
| Parameter type | Reports the parameters passed to a function call, whose types do not match the ones specified in the function definition via type declaration or the PHPDoc | |
| Strict type checking rules violation | Reports violations of the strict type checking rules.
See Strict typing (php.net) for details. | |
| Type declaration is redundant and could be simplified | Reports union type declarations that contain redundant types, for example, a union type that contains both the class alias and the original class. | |
| Type mismatch in property assignment | Reports type violations in properties assignments | |
Quality tools
| Inspection | Description | Default Severity |
|---|---|---|
| PHP CS Fixer validation | Reports coding style problems detected by PHP CS Fixer. | Disabled |
| PHP Mess Detector validation | Reports coding style problems detected by PHP Mess Detector. | Disabled |
| PHPStan validation | Runs PHPStan to find code problems. | Disabled |
| PHP_CodeSniffer validation | Reports coding style problems detected by PHP_CodeSniffer. | Disabled |
| Psalm validation | Runs Psalm to find code problems. | Disabled |
PHPDoc
| Inspection | Description | Default Severity |
|---|---|---|
| Inappropriate @inheritDoc usage | Reports inappropriate
| |
| Missing @return tag | Checks that the PHPDoc block for a function/method contains the | |
| Missing @throws tag(s) | Checks that the PHPDoc block contains the | |
| Missing PHPDoc comment | Reports the elements without a PHPDoc comment specified. | Disabled |
| Non-canonical order of elements | Reports the PHPDoc tags that have elements listed in non-canonical order. | Disabled |
| PHPDoc comment matches function/method signature | Checks that the number of parameters, their names, or types (if any) in a PHPDoc comment matches the ones in the function/method declaration. | |
| Redundant @throws tag(s) | Reports the | |
| Redundant @var tag | Reports the | |
| Redundant PHPDoc comment | Reports the PHPDoc comments that contain only the information already provided in declarations. | |
| Type already exists in PHPDoc tag | Reports duplicate types in PHPDoc comments. | |
| Type doesn't match property's declared type | Reports type mismatches in PHPDoc @var tags | |