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. | Weak warning |
Condition always evaluates to 'true/false' | Reports the conditions that are already covered by earlier conditions and thus have no effect. | Weak warning |
Expression is always 'null' | Reports return variables which are effectively 'null' | Weak warning |
Loop does not iterate | Reports the loop statements whose bodies will execute at most once. | Weak warning |
Result of 'instanceof' is always 'true' | Reports the | Weak warning |
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. | Warning |
Unreachable statement | Reports the statements that cannot be normally reached. | Warning |
Variable is always true/false when reached | Reports variables that are always | Weak warning |
Composer
Inspection | Description | Default Severity |
---|---|---|
Duplicate package entries in composer.json | Reports duplicate package entries in the | Weak warning |
Extension is missing in composer.json | Reports the usages of classes, functions, and constants from the PHP extensions not specified in composer.json. | Warning |
Non-installed Composer packages | Reports the Composer packages that are required in composer.json but are not installed. | Warning |
Quality tool inspection is disabled | Highlights the quality tools' entries in composer.json in case the corresponding code inspections are disabled. | Warning |
Unresolved file references | Reports unresolved file references in composer.json. | Warning |
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. | Weak warning |
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:
| Warning |
Undefined class constant | Reports the references to class constants that are not declared. | Warning |
Undefined constant | Reports the references to constants that are not found in the built-in library and project files. | Warning |
Undefined function | Reports the references to functions that are not defined in the built-in library and project files. | Warning |
Undefined goto label | Reports the | Warning |
Undefined method | Reports the references to class methods that are not defined. | Warning |
Undefined namespace | Reports the references to a namespace that is not found. | Warning |
Undefined property | Reports the references to class properties that are not declared. | Warning |
Undefined variable | Produces two types of warnings:
Use the options below to customize the inspection:
| Error |
Replaceable assignments
Inspection | Description | Default Severity |
---|---|---|
Assignment replaceable with increment or decrement | Reports the assignments that can be replaced with incrementing ( | No highlighting, only fix |
Assignment replaceable with operator assignment | Reports the assignments that can be replaced with combined operator assignments (for example, | No highlighting, only fix |
PHPUnit
Inspection | Description | Default Severity |
---|---|---|
Covered function reference is provided without ‘::’ | Reports the references to functions/methods in the | Warning |
Deprecated @covers/@uses by access modifier annotation | Reports the | Weak warning |
Deprecated assertContains/assertNotContains usage | Reports deprecated usages of the | Weak warning |
Deprecated assertEquals/assertNotEquals usage | Reports deprecated usages of the | Weak warning |
Deprecated assertFileEquals/assertStringEqualsFile usage | Reports the deprecated usages of the | Weak warning |
Deprecated exception handling via doc tags | Reports the usages of the following deprecated PHPUnit doc tags:
| Weak warning |
Deprecated expectException usage | Reports deprecated usages of | Weak warning |
Method assertArrayHasKey/assertArrayNotHasKey can be used instead | Reports alternative usage of the | Weak warning |
Misordered assertEquals/assertNotEquals arguments | Reports any calls to PHPUnit | Weak warning |
Missing target element for PHPUnit test | Reports the test classes and methods, for which no target elements were found. | No highlighting, only fix |
Undefined PHPUnit data provider | Detects that the method referenced in the | Warning |
Usage assertCount/assertSameSize methods instead of assertEquals | Reports alternative usage of the | Weak warning |
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. | Weak warning |
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. | Weak warning |
Unused import | Reports the imports that are never used. | Warning |
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. | Warning |
Unused parameter | Reports the parameters that are considered unused in the following cases:
| Warning |
Unused private method | Reports the private methods that are never used. | Warning |
Unused private property | Reports the private properties that are never used. | Warning |
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 | Weak warning |
'#[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. | Weak warning |
Array key does not match array shape | Reports the array keys that do not match the keys specified via the | Weak warning |
Attribute can be added to overriding member | Reports the methods' and parameters' attributes that can be propagated to overriding methods/parameters. | Weak warning |
Class cannot be used as attribute | Reports the attributes that are resolved to a class not annotated with | Weak warning |
Comment is parsed as attribute in PHP 8.0 | Reports line comments starting with | Warning |
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 | Weak warning |
Immutable property written in invalid scope | Highlights write access references to properties, for which the write access scope declared via | Error |
NoReturn attribute can be added | Reports function without | Weak warning |
Non-applicable attribute target declaration | Reports the attributes that do not have the appropriate | Weak warning |
Non-repeatable attribute | Reports repeated attributes without the | Weak warning |
Pure function may produce side effects | Reports the | Weak warning |
Redundant parentheses in attribute | Reports empty arguments lists in attributes. | Weak warning |
Code smell
Inspection | Description | Default Severity |
---|---|---|
'__toString' may throw an exception | Reports the usages of | Warning |
Argument of 'instanceof' should be only objects or strings | Reports arguments of 'instanceof' that are not objects or strings | Warning |
Array used only with write access | Reports local arrays that are only updated, but never queried. | Weak warning |
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 | Weak warning |
Inconsistent return points | Reports inconsistencies in function/method exit points.
Technically these are not errors, but practically they usually indicate a programming mistake. | Warning |
Logical expression has same operands | Reports the expressions that use the same operands, but should rather use different operands. | Weak warning |
Match expression has only default arm and should be simplified | Reports match expressions with only default match arm | Warning |
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. | Warning |
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. | Weak warning |
Redundant 'static' in final class | Reports | Weak warning |
Redundant assignment to promoted property | Reports redundant assignments to class properties that duplicate automatic assignments performed through promoted constructor parameters. | Weak warning |
Redundant optional argument | Reports redundant arguments that match the corresponding default values for optional parameters. | Weak warning |
Ternary expression can be replaced with condition | Reports the ternary expressions specified as | Weak warning |
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 | Weak warning |
Unnecessary local variable | Reports the local variables that are used in exit statements, such as | Weak warning |
Unnecessary pass-by-ref | Reports elements that have | Weak warning |
Unnecessary semicolon | Reports unnecessary semicolons. | Weak warning |
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'
| Weak warning |
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. | Warning |
Static function should not be abstract | Reports the static methods that are declared as abstract. | Warning |
Code style
Inspection | Description | Default Severity |
---|---|---|
'array_fill' can be converted to loop | Reports the | No highlighting, only fix |
'array_filter' can be converted to loop | Reports the | No highlighting, only fix |
'array_map' call can be converted to loop | Reports the | No highlighting, only fix |
'get_class' can be replaced with '::class' | Reports the | No highlighting, only fix |
'match' expression can be replace with ternary expression | Reports match expressions with default arm and only one non-default arm | No highlighting, only fix |
'mixed' return type can be narrowed | Reports 'mixed' return types that can be narrowed down to more concrete types. | Weak warning |
'str*' calls can be replaced with PHP 8 'str_*' calls | Reports the | Warning |
'switch' can be replaced with 'match' expression | Reports 'switch' statements that could be replaced with 'match' expression | Weak warning |
Class path doesn't match project structure | Reports the classes with the filepath not following the PSR-0/PSR-4 project structure. | Warning |
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. | No highlighting, only fix |
Control statement body without braces |
| No highlighting, only fix |
Expression without clarifying parentheses | Reports potentially ambiguous expressions and proposes enclosing them in clarifying parentheses. | No highlighting, only fix |
Fully qualified name usage | Reports the fully qualified class names that can be shortened by adding the | Warning |
Loop can be converted to 'array_fill' | Reports the | No highlighting, only fix |
Loop can be converted to 'array_filter' call | Reports the | No highlighting, only fix |
Loop can be converted to 'array_map' call | Reports the | No highlighting, only fix |
Method may be 'static' | Reports the methods that don't use any instance references and thus may be converted to static methods. | No highlighting, only fix |
Multiple classes declarations in one file | Reports multiple class declarations in a single file, which violates the PSR-0/PSR-4 standards. | Warning |
Named arguments order does not match parameters order | Reports named argument with order that does not match parameter order | Weak warning |
Old style constructor | Reports old-style constructor declarations ( | Warning |
Redundant closing tag | Reports PHP closing tag | Weak warning |
Short open tag usage | Reports short PHP opening tag | Disabled |
Single-statement body with braces |
| No highlighting, only fix |
Traditional syntax array literal detected | Reports traditional array syntax ( | Disabled |
Trait use rule resolved to method with different containing class | Reports the trait method | Weak warning |
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 | Warning |
Unnecessary parentheses | Reports the expressions containing redundant parenthesis, which can be safely removed. | No highlighting, only fix |
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. | No highlighting, only fix |
Constant reassignment | Reports reassignments of constants. | Warning |
Division by zero | Reports division by zero or modulo by zero. | Disabled |
Duplicate arm in 'match' expression | Reports duplicate bodies in | Weak warning |
Duplicate array keys | Reports duplicate keys in array declarations. | Warning |
Duplicate branch in switch statement |
| Weak warning |
Duplicate case in switch statement | Reports duplicate | Warning |
Duplicate condition | Reports duplicate conditions in | Warning |
Expression result unused | Reports expressions that are calculated, but the calculation result is not used anywhere. | Warning |
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 | Warning |
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. | Warning |
Goto into loop statement | Reports the | Error |
Invalid type of unpacked argument |
| Warning |
Method __toString implementation | Reports the attempts to convert the objects having no | Warning |
Method __toString return type | Reports the | Error |
Missing 'break' statement | Reports the | Warning |
Missing parent call for constructor | Reports the constructors that do not call their parent constructor. | Warning |
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 | Warning |
Non-strict object equality | Reports the usages of the comparison operator (
See Comparing Objects (php.net) for details. | Warning |
Optional before required parameter | Reports the optional parameters that appear before the required parameters in function/method declaration. | Warning |
Pass parameter by reference | Reports the arguments in a function/method call that cannot be passed by reference. | Error |
Silly assignment | Reports the assignment statements, in which both sides are equal. Such assignments have no effect and can be removed. | Warning |
Statement has empty body | Reports the statements that have empty bodies. | Warning |
Switch statement without default branch |
| No highlighting, only fix |
Unnecessary statement use | Reports the | Warning |
Unused 'match' condition | Reports the conditions in | Warning |
Void function result used | Reports the attempts to use the value of a | Warning |
Wrong string concatenation | Reports the attempts to concatenate strings by using the | Warning |
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. | No highlighting, only fix |
Argument without name identifier | Reports arguments without name identifiers. | No highlighting, only fix |
Class can't implement Traversable directly | Reports the classes that are implementing the | Error |
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. | Error |
Curly brace access syntax usage |
| Error |
Deprecated | Reports the usages of deprecated entities. | Weak warning |
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. | Weak warning |
Deprecated implode/join usage | Reports deprecated usage of the | Warning |
Disabled extension stubs | Reports the usages of classes, functions, and constants, for which the extension stubs are disabled. | No highlighting, only fix |
Dynamic method called as static | Reports static calls to dynamic class methods. | Warning |
Element is not available in configured PHP version | Reports the usages of entities which were introduced in PHP version later than configured one. | Error |
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. | Weak warning |
Incorrect magic method signature | Reports incompatible magic methods signatures. | Error |
Invalid magic method modifiers | Reports magic methods that are not declared as | Warning |
Language level | Reports the language features used in source code that are not supported for the selected language level. | Error |
Method declaration of super class is incompatible with implemented interface | Reports the methods declarations in parent classes that are incompatible with implemented interfaces. | Error |
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. | Weak warning |
Nested ternary operator usage |
| Error |
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. | Weak warning |
Promoted property usage | Reports properties declared through promoted constructor parameters. | No highlighting, only fix |
Property can be promoted | Reports the properties that can be replaced with promoted versions. | No highlighting, only fix |
Static method called as dynamic | Reports dynamic calls to static class methods. | Disabled |
Unresolved include | Reports non-resolved | Warning |
Usage of internal entity | Reports the usages of the entities that are marked as | Weak warning |
Error handling
Inspection | Description | Default Severity |
---|---|---|
Redundant catch clause | Reports the | Warning |
Unhandled exception | Reports the exceptions that are neither enclosed in a | Weak warning |
Wrong catch clauses order | Reports the | Warning |
Type compatibility
Inspection | Description | Default Severity |
---|---|---|
Illegal array key type | Reports the array keys that are of illegal type, such as objects or arrays. | Warning |
Illegal string offset | Reports the usages of non- | Warning |
Incompatible return type | Reports the | Warning |
Invalid argument supplied for foreach() | Reports the | Warning |
Missing parameter's type declaration | Reports the parameters that have no type declaration specified. | Weak warning |
Missing property's type declaration | Reports the properties that have no type declaration. | Weak warning |
Missing return type declaration | Reports the functions that have no return type declaration specified. | Weak warning |
Missing strict types declaration | Detects the missing | Disabled |
PHP 8 TypeError on arithmetic operations | Reports arithmetic and bitwise expressions with unsupported operands. | Error |
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 | Warning |
Strict type checking rules violation | Reports violations of the strict type checking rules.
See Strict typing (php.net) for details. | Error |
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. | Weak warning |
Type mismatch in property assignment | Reports type violations in properties assignments | Warning |
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
| Weak warning |
Missing @return tag | Checks that the PHPDoc block for a function/method contains the | Weak warning |
Missing @throws tag(s) | Checks that the PHPDoc block contains the | Weak warning |
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. | Weak warning |
Redundant @throws tag(s) | Reports the | Weak warning |
Redundant @var tag | Reports the | Weak warning |
Redundant PHPDoc comment | Reports the PHPDoc comments that contain only the information already provided in declarations. | No highlighting, only fix |
Type already exists in PHPDoc tag | Reports duplicate types in PHPDoc comments. | Weak warning |
Type doesn't match property's declared type | Reports type mismatches in PHPDoc @var tags | Weak warning |