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 |
---|---|---|
Reports the keys and values in | Weak warning | |
Reports the | Weak warning | |
Reports the 'switch' statements with duplicated common parts. | Weak warning | |
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 | |
Reports the conditions that are already covered by earlier conditions and thus have no effect. | Weak warning | |
Condition inside logical expression checked by subsequent condition | Reports the conditions inside logical binary expressions that are are covered by subsequent conditions and are therefore redundant. | Weak warning |
Reports return variables which are effectively 'null' | Weak warning | |
Reports the loop statements whose bodies will execute at most once. | Weak warning | |
Reports the | Weak warning | |
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 | |
Reports the | No highlighting, only fix | |
Reports the statements that cannot be reached. | Warning | |
Reports variables that are always | Weak warning | |
Reports the write access expressions on variables that are still referencing the array value previously used in a | Warning |
Composer
Inspection | Description | Default Severity |
---|---|---|
Reports duplicate package entries in the | Weak warning | |
Reports the usages of classes, functions, and constants from the PHP extensions not specified in composer.json. If an extension is listed in the | Warning | |
Reports the Composer packages that are required in composer.json but are not installed. | Weak warning | |
Highlights the quality tools' entries in composer.json in case the corresponding code inspections are disabled. | Weak warning | |
Reports unresolved file references in composer.json. | Warning |
Replaceable assignments
Inspection | Description | Default Severity |
---|---|---|
Reports the assignments that can be replaced with incrementing ( | No highlighting, only fix | |
Reports the assignments that can be replaced with combined operator assignments (for example, | No highlighting, only fix |
Psalm
Inspection | Description | Default Severity |
---|---|---|
Reports the parameters in function calls whose types are not compatible with the ones defined via | Warning |
PHPUnit
Inspection | Description | Default Severity |
---|---|---|
Reports the | Weak warning | |
Reports the usages of | Weak warning | |
Reports the references to functions/methods in the | Weak warning | |
Reports deprecated usages of the | Weak warning | |
Reports deprecated usages of the | Weak warning | |
Reports the deprecated usages of the | Weak warning | |
Reports the | Weak warning | |
Reports the usages of the following deprecated PHPUnit doc tags:
| Weak warning | |
Reports deprecated usages of | Weak warning | |
Method 'assertArrayHasKey/assertArrayNotHasKey' can be used instead | Reports alternative usage of the | Weak warning |
Reports any calls to PHPUnit | Weak warning | |
Reports the test classes and methods, for which no corresponding production classes or methods were found. | No highlighting, only fix | |
Reports the references to functions/methods in the | Warning | |
Usage 'assertCount/assertSameSize' methods instead of assertEquals | Reports alternative usage of the | Weak warning |
PSR-12
Inspection | Description | Default Severity |
---|---|---|
Reports the usages of compound namespaces whose depth exceeds two levels. | ||
Reports the usages of the | ||
Reports missing parameter lists in a classes' instantiations. | ||
Reports the properties, constants, and methods that are declared without visibility definition.
See PSR-12: Extended Coding Style (php-fig.org) for details. | ||
Reports the cases of several traits being imported via a single | ||
Reports visibility modifiers that are specified in the incorrect order.
See PSR-12: Extended Coding Style (php-fig.org) for details. | ||
Reports usages of long form type keywords. | ||
Reports the usages of the |
Attributes
Inspection | Description | Default Severity |
---|---|---|
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 | |
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 | |
Reports the array keys that do not match the keys specified via the | Weak warning | |
Reports the methods' and parameters' attributes that can be propagated to overriding methods/parameters. | Weak warning | |
Reports the attributes that are resolved to a class not annotated with | Weak warning | |
Reports line comments starting with | Warning | |
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 | |
Highlights write access references to properties, for which the write access scope declared via | Error | |
Reports function without | Weak warning | |
Reports the attributes that do not have the appropriate | Weak warning | |
Reports repeated attributes without the | Weak warning | |
Reports the | Weak warning | |
Reports empty arguments lists in attributes. | Weak warning |
Code smell
Inspection | Description | Default Severity |
---|---|---|
Reports the usages of | Warning | |
Reports the
See continue (php.net), break (php.net), and switch (php.net) for details. | Weak warning | |
Reports the | Weak warning | |
Reports the | No highlighting, only fix | |
Reports the | Weak warning | |
'match' expression has only default arm and should be simplified | Reports the | Weak warning |
Reports arguments of 'instanceof' that are not objects or strings | Warning | |
Reports the array access expressions inside | Weak warning | |
Reports the iterated/accessed arrays that are known to be empty at the point of access. | Weak warning | |
Reports local arrays that are only updated, but never queried. | Weak warning | |
Reports the boolean expressions that contain the | Weak warning | |
Reports the class constant references that target the constant from the parent class of the referenced class. | Weak warning | |
Reports the | Weak warning | |
Reports the | Warning | |
Reports | Weak warning | |
Reports the | Weak warning | |
Reports the | Weak warning | |
Reports inconsistencies in function/method exit points.
Technically these are not errors, but practically they usually indicate a programming mistake. | Warning | |
Reports the expressions that use the same operands, but should rather use different operands (for example, | Weak warning | |
Reports the | Weak warning | |
Reports the | Weak warning | |
Checks that the methods don't override visibility. | ||
Reports the private methods returning the values that are not used. | Weak warning | |
Nested 'dirname' call can be replaced with 'levels' parameter usage | Reports the nested | Weak warning |
Reports the parameters in private methods that have the same value across all method calls. | Weak warning | |
Reports the function/method calls that take more parameters than specified in their declaration. | Weak warning | |
Reports the private properties that are used only in a single method. Such properties can be replaced with local variables. | Weak warning | |
Reports the private properties that are:
| Warning | |
Reports the redundant | Weak warning | |
Reports | Weak warning | |
Reports redundant assignments to class properties that duplicate automatic assignments performed through promoted constructor parameters. | Weak warning | |
Reports the | Weak warning | |
Reports the | Weak warning | |
Reports the overriding methods that only consist of a single call to the parent method. | Weak warning | |
Reports redundant arguments that match the corresponding default values for optional parameters. | Weak warning | |
Reports the ternary expressions specified as | Weak warning | |
Reports the | Weak warning | |
Reports the function/method declarations with the number of parameters exceeding the specified limit. | ||
Reports unnecessary | Weak warning | |
Reports the local variables that are used in exit statements, such as | Weak warning | |
Reports the variables that are passed by reference to a function/method but are not modified in the function/method body. In such cases, the | Weak warning | |
Reports unnecessary semicolons. | Weak warning | |
Reports the usages of the silence operator ( | ||
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 the PHP language level lower than 8.0. | Warning |
Reports the static methods that are declared as abstract. | Warning |
Code style
Inspection | Description | Default Severity |
---|---|---|
Reports the | No highlighting, only fix | |
Reports the | No highlighting, only fix | |
Reports the | No highlighting, only fix | |
Reports the | No highlighting, only fix | |
Reports the conditions using | Weak warning | |
Reports the | No highlighting, only fix | |
Reports 'mixed' return types that can be narrowed down to more concrete types. | Weak warning | |
Reports the | Weak warning | |
Reports the | Weak warning | |
Reports 'switch' statements that could be replaced with 'match' expression | Weak warning | |
Reports the usages of functions, methods, classes, and namespaces that do not match the case used in their declarations. | ||
Reports the classes with the filepath not following the PSR-0/PSR-4 project structure. | Warning | |
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 | |
Reports the control structures (such as loops or conditionals) whose bodies are not enclosed in braces. | No highlighting, only fix | |
Reports dangerous array initializations (such as | No highlighting, only fix | |
Reports | Weak warning | |
Reports the elements without a PHPDoc comment or with a PHPDoc comment only containing the | ||
Reports potentially ambiguous expressions and proposes enclosing them in clarifying parentheses. | No highlighting, only fix | |
Reports the fully qualified class names that can be shortened by adding the | Weak warning | |
Reports the | No highlighting, only fix | |
Reports the | No highlighting, only fix | |
Reports the | No highlighting, only fix | |
Reports the methods that don't use any instance references and thus may be converted to static methods. | No highlighting, only fix | |
Checks that the PHPDoc block contains the | Weak warning | |
Reports non-fully typed elements without a PHPDoc comment or with a PHPDoc comment only containing the | ||
Reports multiple class declarations in a single file, which violates the PSR-0/PSR-4 standards. | Weak warning | |
Reports named argument with order that does not match parameter order | Weak warning | |
Reports the PHPDoc tags that have elements listed in non-canonical order. | ||
Reports the null-checking conditional expressions that can be safely replaced with the | Weak warning | |
Reports old-style constructor declarations ( | Warning | |
Reports the PHPDoc comments that contain at least one | Weak warning | |
Reports PHP closing tag | Weak warning | |
Reports short PHP opening tag | Warning | |
Reports the control structures (such as loops or conditionals) whose bodies are enclosed in braces but only contain a single child statement. Using braces in such cases is not necessary. | No highlighting, only fix | |
Reports traditional array syntax ( | ||
Reports the class references that are resolved to traits but are specified outside | Weak warning | |
Trait use rule resolved to method with different containing class | Reports the trait method | Weak warning |
Reports the type cast operators used on the values that are already of the corresponding type. Such operators are redundant and can be safely removed. | Weak warning | |
Reports unnecessary | Weak warning | |
Reports double-quoted string literals that do not contain string interpolation, escape sequences, or single quotes. | ||
Reports the usages of fully qualified class names, which can be shortened without adding the | Weak warning | |
Reports the | Weak warning | |
Reports the expressions containing redundant parenthesis, which can be safely removed. | No highlighting, only fix | |
Reports the usages of variable variables (dynamic variable names such as |
Probable bugs
Inspection | Description | Default Severity |
---|---|---|
Reports the assignments that are used in conditional expressions. | No highlighting, only fix | |
Reports the arguments of enum's | Error | |
Reports the string concatenation expressions that are used together with | Warning | |
Reports reassignments of constants. | Warning | |
Reports division by zero or modulo by zero. | ||
Reports duplicate bodies in | Weak warning | |
Reports duplicate keys in array declarations. | Warning | |
Reports the | Weak warning | |
Reports duplicate | Warning | |
Reports duplicate conditions in | Warning | |
Reports the usages of empty index operator ( | Error | |
Reports the expressions that are calculated, but the calculation result is not used anywhere. | Warning | |
Reports the variables that are used in a | Warning | |
Reports the arguments of a format function (such as | Warning | |
Reports the | Error | |
Reports unpacked function arguments and array elements whose type is neither | Warning | |
Reports the attempts to convert the objects having no | Warning | |
Reports the | Error | |
Reports the | Weak warning | |
Reports the constructors that do not call their parent constructor. | Warning | |
Reports the magic methods that do not call their parent magic method. | ||
Reports the methods that do not call their parent method. | ||
Reports the variables that are used as a key or value both by the inner and outer | Warning | |
Reports the usages of the comparison operator (
See Comparing Objects (php.net) for details. | Weak warning | |
Reports the optional parameters that appear before the required parameters in a function/method declaration. | Warning | |
Reports the arguments in a function/method call that cannot be passed by reference. | Error | |
Reports the assignment statements, in which both sides are equal. Such assignments have no effect and can be removed. | Warning | |
Reports the | Weak warning | |
Reports the statements that have empty bodies. | Warning | |
Reports the | Weak warning | |
Reports the assignments and function calls where the name of the variable or parameter probably doesn't match the name of the assigned or passed value.
| Warning | |
Reports the | No highlighting, only fix | |
Reports the | Warning | |
Reports the conditions in | Weak warning | |
Reports the branches in | Weak warning | |
Reports the usages of a | Warning | |
Reports the attempts to concatenate strings by using the | Warning |
Naming conventions
Inspection | Description | Default Severity |
---|---|---|
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. | ||
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. | ||
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. | ||
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. | ||
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. | ||
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. |
General
Inspection | Description | Default Severity |
---|---|---|
Reports arguments with name identifiers. | No highlighting, only fix | |
Reports arguments without name identifiers. | No highlighting, only fix | |
Reports the classes that are implementing the | Error | |
Checks the classes' hierarchy: abstract methods implementation, the compatibility of implementing/overriding methods with their declarations in parent classes, and properties' types redeclarations. | Error | |
Reports the usages of curly brace syntax for accessing array elements and string offsets. | Error | |
Reports the usages of deprecated entities. | Weak warning | |
Reports deprecated usage of the | Warning | |
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 | |
Reports the usages of classes, functions, and constants, for which the stubs for the corresponding PHP interpreter extensions are disabled. | No highlighting, only fix | |
Reports static calls to dynamic class methods. | Warning | |
Reports the usages of entities which were introduced in PHP version later than configured one. | Error | |
Reports the class alias declarations that are ignored by the IDE because the actual class declaration with the same FQN exists. | Weak warning | |
Reports incompatible magic methods signatures. | Error | |
Reports the magic methods that are not declared as public or are declared as static. | Warning | |
Reports the language features used in source code that are not supported for the selected language level. | Error | |
Method declaration in parent class is incompatible with implemented interface | Reports the methods declarations in parent classes that are incompatible with implemented interfaces. | Error |
Reports the named arguments in method calls that might be unresolved depending on a specific class instance within the hierarchy. | Weak warning | |
Reports nested ternary expressions, which are deprecated starting from PHP 7.4. | Error | |
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 | |
Reports properties declared through promoted constructor parameters. | No highlighting, only fix | |
Reports the properties that can be replaced with promoted versions. | No highlighting, only fix | |
Reports dynamic calls to static class methods. | ||
Reports non-resolved | Weak warning | |
Reports the usages of the entities that are marked as | Weak warning |
Error handling
Inspection | Description | Default Severity |
---|---|---|
Reports the | Weak warning | |
Reports the exceptions that are neither enclosed in a | Weak warning | |
Reports the exceptions that are already caught by a preceding exception and the exceptions that are caught twice. | Warning |
Type compatibility
Inspection | Description | Default Severity |
---|---|---|
Reports the variables that are initialised via passing them by reference to a parameter incompatible with | Error | |
Reports the array offset access expressions that are used on illegal types. | Weak warning | |
Reports the array keys that are of illegal type, such as objects or arrays. | Warning | |
Reports the usages of non- | Warning | |
Reports the | Warning | |
Reports the | Warning | |
Reports the parameters that have no type declaration specified. | Weak warning | |
Reports the properties that have no type declaration. | Weak warning | |
Reports the functions that have no return type declaration specified. | Weak warning | |
Detects the missing | ||
Reports arithmetic and bitwise expressions with unsupported operands. | Error | |
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 | |
Reports violations of the strict type checking rules.
See Strict typing (php.net) for details. | Error | |
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 | |
Reports type violations in properties assignments. | Warning |
Undefined symbols
Inspection | Description | Default Severity |
---|---|---|
Reports the references to classes that have multiple declarations in project files.
| Weak warning | |
Reports polymorphic code usages. Such usages are ambiguous and can be potentially inoperable depending on the class instance passed as the argument. | Weak warning | |
Reports the functions, methods, properties, or classes that are referenced from a callback but are not found.
| ||
Reports the references to classes whose declarations are not found in the project files, configured include paths, or among the PHP predefined classes.
| Warning | |
Reports the references to class constants that are not declared. | Error | |
Reports the references to constants that are not found in the project files, configured include paths, or among the PHP predefined constants. | Warning | |
Reports the references to functions that are not defined in the project files, configured include paths, or among the PHP predefined functions. | Warning | |
Reports the | Warning | |
Reports the references to class methods that are not defined. | Warning | |
Reports the references to a namespace that is not found. | Warning | |
Reports the references to class properties that are not declared. | Warning | |
Produces two types of warnings:
Use the options below to customize the inspection:
| Error |
Quality tools
Inspection | Description | Default Severity |
---|---|---|
Reports coding style problems detected by PHP CS Fixer. | ||
Reports coding style problems detected by PHP Mess Detector. | ||
Runs PHPStan to find code problems. | ||
Reports coding style problems detected by PHP_CodeSniffer. | ||
Runs Psalm to find code problems. |
Unused symbols
Inspection | Description | Default Severity |
---|---|---|
Reports the fields with default initializers that are always overwritten in the class constructor. | Weak warning | |
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 | |
Reports the imports that are never used. | Weak warning | |
Reports the variables that are considered unused in the following cases:
| Weak warning | |
Reports the parameters that are considered unused in the following cases:
| Weak warning | |
Reports the private methods that are never used. | Weak warning | |
Reports the private properties that are never used. | Weak warning |
Refactoring opportunities
Inspection | Description | Default Severity |
---|---|---|
Reports the classes that have too many properties or methods. | ||
Reports the classes that are too complex.
| ||
Reports the functions or methods that are too complex.
| ||
Reports the methods that have high cyclomatic complexity and can probably be simplified. | ||
Reports the methods with high Halstead Complexity metric. | ||
Reports the classes that have high Lack of Cohesion metric value, which represents the degree of cohesiveness of a class. | ||
Reports the class methods and properties that should be pulled up to the parent class or interface. | ||
Reports the "Feature Envy" code smell. Feature envy is defined as occurring when a method calls methods on another class more times than on the source class. It often indicates that the intended functionality is located in the wrong class. |
PHPDoc
Inspection | Description | Default Severity |
---|---|---|
Reports inappropriate
| Weak warning | |
Reports the parameters' names and types in a PHPDoc comment that do not match the ones in the function/method declaration. | Weak warning | |
Reports the | Weak warning | |
Reports the | Weak warning | |
Reports the PHPDoc comments that contain only the information already provided in declarations. | No highlighting, only fix | |
Return type in PHPDoc comment does not match the actual return type | Reports the return types in PHPDoc comments that do not match the actual return type of a function. | Weak warning |
Reports duplicate types in PHPDoc comments. | Weak warning | |
Reports the properties' types in PHPDoc | Weak warning |