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 Control+Alt+S.
Control flow
Inspection | Description | Default Severity |
---|---|---|
Reports the keys and values in | Weak warning | |
Reports the | Weak warning | |
Reports the functions with the See noreturn type (php.net) for details. | Error | |
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 as well as the variables that are always true (or always false) when reached. | Weak warning | |
Condition inside logical expression checked by subsequent condition | Reports the conditions inside logical binary expressions that are covered by subsequent conditions and are therefore redundant. | Weak warning |
Reports the variables in | Weak warning | |
Reports the loop statements whose bodies will execute at most once. The inspection does not report | Weak warning | |
Reports the | Weak warning | |
Reports the attempts to read from an uninitialized typed property. Such attempts will result in Typed properties should be initialized in any of the following ways:
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 the write access expressions on variables that are still referencing the array value previously used in a It is recommended to destroy such references by using See foreach (php.net) and unset (php.net) for details. | 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 PHPUnit | Warning | |
Reports the See assertEmpty (phpunit.readthedocs.io) for details. | Weak warning | |
Reports the | Weak warning | |
Reports the references to functions/methods in the | Weak warning | |
Reports the deprecated The string See Usage of the assertEquals function (phpunit.readthedocs.io) for details. | Weak warning | |
Reports deprecated usages of the The optional See Usage of the assertEquals function (phpunit.readthedocs.io) for details. | Weak warning | |
Reports the deprecated usages of the The optional See Usage of the assertFileEquals function (phpunit.readthedocs.io) or Usage of the assertFileEquals function (phpunit.readthedocs.io) for details. | Weak warning | |
Reports the | Weak warning | |
Reports the usages of the following deprecated PHPUnit doc tags:
| Weak warning | |
Reports deprecated usages of Support for using the Instead, the See Testing PHP Errors, Warnings, and Notices (phpunit.readthedocs.io) for details. | Weak warning | |
Reports the methods and classes that are incorrectly mocked in PHPUnit tests. The following entities are reported:
| Error | |
Method 'assertArrayHasKey/assertArrayNotHasKey' can be used instead | Reports the See assertArrayHasKey (phpunit.readthedocs.io) for details. | Weak warning |
Reports the calls to the PHPUnit assertion methods that are removed in PHPUnit 10. | Warning | |
Reports the calls to PHPUnit equality assertion methods (such as See assertEquals for details. | 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 Note that when resolving | Warning | |
Usage 'assertCount/assertSameSize' methods instead of assertEquals | Reports alternative usage of the See Usage of the assertCount for details. See Usage of the assertSameSize for details. | Weak warning |
PSR-12
Inspection | Description | Default Severity |
---|---|---|
Reports the usages of compound namespaces whose depth exceeds two levels. According to PSR-12, compound namespaces with a depth of more than two MUST NOT be used. See PSR-12: Extended Coding Style (php-fig.org) for details. | ||
Reports the usages of the According to PSR-12, the keyword See PSR-12: Extended Coding Style (php-fig.org) for details. | ||
Reports missing parameter lists in a classes' instantiations. According to the PSR-12 specification, when instantiating a new class, parentheses MUST always be present even when there are no arguments passed to the constructor. See PSR-12: Extended Coding Style (php-fig.org) for details. | ||
Reports the properties, constants, and methods that are declared without visibility definition. According to PSR-12, visibility MUST be defined on:
See PSR-12: Extended Coding Style (php-fig.org) for details. | ||
Reports the cases of several traits being imported via a single According to PSR-12, each individual trait imported into a class MUST be included one-per-line, and each inclusion MUST have its own See PSR-12: Extended Coding Style (php-fig.org) for details. | ||
Reports visibility modifiers that are specified in the incorrect order. According to PSR-12, the correct order is as follows:
See PSR-12: Extended Coding Style (php-fig.org) for details. | ||
Reports usages of long form type keywords. According to PSR-12, short form of type keywords MUST be used, that is See Keywords and Types (php-fig.org) for details. | ||
Reports the usages of the According to PSR-12, the See PSR-12: Extended Coding Style (php-fig.org) for details. |
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. | No highlighting, only fix | |
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. See Attributes (php.net) for details. | Weak warning | |
Reports the attributes that are resolved to a class not annotated with See Attributes (php.net) for details. | Weak warning | |
Reports line comments starting with See Attributes (php.net) for details. | 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 See Attributes (php.net) for details. | 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 See Attributes (php.net) for details. | Weak warning | |
Reports repeated attributes without the See Attributes (php.net) for details. | Weak warning | |
Reports the | Weak warning | |
Reports empty arguments lists in attributes. See Attributes (php.net) for details. | Weak warning |
Code smell
Inspection | Description | Default Severity |
---|---|---|
Reports the usages of | Warning | |
Reports the See array_push (php.net) for details. | Weak warning | |
Reports the | Weak 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 See in_array (php.net) for details. | Weak warning | |
'match' expression has only default arm and should be simplified | Reports the See Match expression (php.net) for details. | Weak warning |
Reports the | Weak warning | |
Reports the | Weak warning | |
Reports the | Weak warning | |
Reports the static member access expressions used on traits. Such direct access is deprecated starting from PHP 8.1. Instead, static members should be accessed on the class that uses the trait. See Deprecations for PHP 8.1: Accessing static members on traits (php.net) for details. | Weak warning | |
Reports arguments of 'instanceof' that are not objects or strings | Warning | |
Reports the array access expressions inside | Weak warning | |
Reports the See reset (php.net) for details. | Weak warning | |
Reports the iterated/accessed arrays that are known to be empty at the point of access. | Weak warning | |
Reports array to string conversions, that is, the arrays that are provided in the contexts where a string is expected. Prior to PHP 8.0, this would lead to a | 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 conditions that perform manual min/max calculation instead of calling | Weak warning | |
Reports the | Warning | |
Reports | Weak warning | |
Reports duplicate operands in binary expressions ( | Weak warning | |
Reports the | Weak warning | |
Reports the | Weak warning | |
Reports the | Weak warning | |
Reports the binary expression operands that do not change the expression result (such as | Weak warning | |
Reports inconsistencies in function/method exit points. The following types of inconsistencies are reported:
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 See implode (php.net) for details. | Weak warning | |
Reports the | Weak warning | |
Checks that the methods don't override visibility. Overriding a See Method Visibility (php.net) for details. | ||
Reports the private methods returning the values that are not used. | Weak warning | |
Reports the modulo expressions | Weak warning | |
Nested 'dirname()' call can be replaced with 'levels' parameter usage | Reports the nested | Weak warning |
Reports 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 boolean expressions inside | 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 | |
Redundant 'array_values' call on a value iterated in 'foreach' | Reports the | Weak warning |
Reports the redundant See continue (php.net) and break (php.net) for details. | Weak warning | |
Reports | Weak warning | |
Reports redundant assignments to class properties that duplicate automatic assignments performed through promoted constructor parameters. See Constructor Property Promotion (php.net) for details. | 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 See Passing by Reference (php.net) for details. | Weak warning | |
Reports unnecessary semicolons. | Weak warning | |
Reports the usages of the spread operator ( | Weak warning | |
Reports the usages of the silence operator ( See Error Control Operators (php.net) for details. | ||
Reports the trailing commas in parameters lists and closures'
| Weak warning | |
Reports the | 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 |
---|---|---|
'Closure::fromCallable()' can be converted to the first-class callable syntax | Reports the See First-class callable syntax (php.net) for details. | Weak warning |
Reports the | No highlighting, only fix | |
Reports the | No highlighting, only fix | |
Reports the | No highlighting, only fix | |
Reports the See Allow ::class on objects (php.net) for details. | No highlighting, only fix | |
Reports the | No highlighting, only fix | |
'instanceof' checks in 'catch' block can be replaced with specific catches | Reports the | Weak warning |
Reports the conditions using See Null coalesce operator (php.net) for details. | Weak warning | |
Reports the Note that See match (php.net) and switch (php.net) for details. | No highlighting, only fix | |
Reports the See Match expression (php.net) for details. | 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 See Power operator (php.net) for details. | No highlighting, only fix | |
Reports the See str_contains (php.net) and str_starts_with and str_ends_with functions (php.net) for details. | Weak warning | |
Reports 'switch' statements that could be replaced with 'match' expression | Weak warning | |
Reports automatic conversions of See Deprecate autovivification on false for details. | Weak warning | |
Reports the usages of functions, methods, classes, and namespaces that do not match the case used in their declarations. | ||
Reports the non- See Final class constants (php.net) for details. | No highlighting, only fix | |
Reports the classes with the filepath not following the PSR-0/PSR-4 project structure. You can configure the project vendor roots under Settings | Directories. See PSR-0/PSR-4 standards (php-fig.org) for details. | Warning | |
Reports the anonymous functions that can be transformed to short arrow functions. Support for short arrow functions is available since PHP 7.4. See PHP RFC: Arrow Functions 2.0 (php.net) for details. | No highlighting, only fix | |
Reports the inline comments before arguments in function calls that only contain the name of the parameter and thus serve as hints. In PHP 8.0 and later, named arguments can be used instead. See Named arguments (php.net) for details. | Weak warning | |
Reports the control structures (such as loops or conditionals) whose bodies are not enclosed in braces. See Control structures (php.net) for details. | No highlighting, only fix | |
Reports dangerous array initializations (such as This practice is discouraged because if See Creating/modifying with square bracket syntax (php.net) for details. | No highlighting, only fix | |
Reports the | Weak warning | |
Reports the elements without a PHPDoc comment or with a PHPDoc comment only containing the You can use Missing PHPDoc Comment inspection to report only non-fully typed elements. | ||
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 implicit octal literals such as Explicit octal literals using the See Explicit octal integer literal notation (php.net) for details. | No highlighting, only fix | |
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 | |
Reports missing PHPDoc The exception classes added to the Unchecked Exceptions list under Settings | PHP | Analysis are excluded from the inspection scope. | Weak warning | |
Reports non-fully typed elements without a PHPDoc comment or with a PHPDoc comment only containing the You can use the Enforce PHPDoc Comment inspection to report fully typed elements. | ||
Reports multiple class declarations in a single file, which violates the PSR-0/PSR-4 standards. See PSR-0/PSR-4 standards (php-fig.org) for details. | 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. For example, for such tags as | ||
Reports the null-checking conditional expressions that can be safely replaced with the | Weak warning | |
Reports old-style constructor declarations ( Prior to PHP 8.0, old-style constructor syntax used in the classes in the global namespace is treated as deprecated and will result in an In namespaced classes, or any classes as of PHP 8.0, a See Constructors and destructors (php.net) for details. | Warning | |
Reports the PHPDoc comments that contain at least one | Weak warning | |
Reports PHP closing tag | Weak warning | |
Reports short PHP | No highlighting, only fix | |
Reports short PHP opening tag See PHP tags (php.net) for details. | 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. See Control structures (php.net) for details. | No highlighting, only fix | |
Reports traditional array syntax ( | ||
Reports the class references that are resolved to traits but are specified outside See Traits (php.net) for details. | 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. See Type juggling (php.net) for details. | Weak warning | |
Reports the type casts that can be evaluated in place and suggests replacing them with actual computed values. See Type juggling (php.net) for details. | Weak warning | |
Reports unnecessary See Variable parsing (php.net) for details. | 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 For namespaced names (fully qualified namespace names containing a namespace separator, such as See Using namespaces: Aliasing/Importing (php.net) for details. | 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 See Enumerations (php.net) for details. | Error | |
Reports the string concatenation expressions that are used together with See Concatenation precedence (php.net) for details. | Warning | |
Reports reassignments of constants. Since constants cannot be changed, such assignments will have no effect and will emit an | Warning | |
Reports division by zero or modulo by zero. | Error | |
Reports duplicate bodies in See Match expression (php.net) for details. | Weak warning | |
Reports duplicate keys in array declarations. If multiple elements in the array declaration use the same key, only the last one will be used, and all others will be overwritten. | Warning | |
Reports the | Weak warning | |
Reports duplicate If a | Warning | |
Reports duplicate characters provided in the | Warning | |
Reports duplicate conditions in See Match expression (php.net) for details. | Warning | |
Reports the usages of empty index operator ( Starting from PHP 7.1, applying the empty index operator on a string throws a fatal error. See Creating/modifying with square bracket syntax (php.net) for details. | Error | |
Reports the expressions that are calculated, but the calculation result is not used anywhere. Such errors can be caused, for example, by misspelling the | Warning | |
Reports the variables that are used in a Commonly, this is the result of a typing error. | Warning | |
Reports the arguments of a format function (such as See printf (php.net) and sprintf (php.net) for details. | Warning | |
Reports the See goto (php.net) for details. | Error | |
Reports invalid string offset usages that will result in a runtime error. The following usages are reported:
| Error | |
Reports unpacked function arguments and array elements whose type is neither Starting with PHP 8.0, such usages will result in | Warning | |
Reports the variable assignments to new objects that are used only for writing the object's properties without observable side effects. | Warning | |
Reports the attempts to convert the objects having no Prior to PHP 7.4, this would lead to a fatal If the Check __toString exists for each expression type option is enabled, the inspection will check all possible types of the expression and report if at least one of them doesn't contain the See __toString (php.net) for details. | Warning | |
Reports the Prior to PHP 7.4, this would lead to a fatal See __toString (php.net) for details. | Error | |
Reports the | Error | |
Reports the If a | 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 ( Object variables are compared as follows:
See Comparing Objects (php.net) for details. | Weak warning | |
Reports the optional parameters that appear before the required parameters in a function/method declaration. See Default argument values (php.net) for details. | Warning | |
Reports the arguments in a function/method call that cannot be passed by reference. Only variables and references returned from functions can be passed by reference. See Passing by Reference (php.net) for details. | Error | |
Private method may be inaccessible during late static binding call | Reports the late static binding method calls (that is, performed via See Late Static Bindings (php.net) for details. | Warning |
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. While occasionally useful, such statements are often the result of typos and may cause confusion. | Warning | |
Reports the See PHP type comparison tables (php.net) for details. | 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. The following sets of names are supported:
| Warning | |
Reports the | No highlighting, only fix | |
Reports the See Using namespaces: Aliasing/Importing (php.net) for details. | Warning | |
Reports the conditions in Similarly to PHP Engine behavior, the inspection uses strict comparison ( See Match expression (php.net) for details. | Weak warning | |
Reports the branches in See Enumerations (php.net) for details. | Weak warning | |
Reports the usages of a Since | Warning | |
Reports the attempts to concatenate strings by using the | Warning |
Regular expressions
Inspection | Description | Default Severity |
---|---|---|
Reports the elements in regular expression character classes that are already covered by another element in the same class. Such elements are redundant and can be safely removed. | Weak warning | |
Reports the alphabetic ranges or characters in regular expression character classes that only adjust the already existing ranges. Such elements can be merged with the adjusted ranges. | Weak warning | |
Reports the | Weak warning | |
Reports the usages of 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. Use the inspection options to specify minimum/maximum length and the regular expression expected for classes' names. To ignore the names' length, specify 0. For more information about regular expressions, refer to the Quick Start guide (regular-expressions.info). | ||
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. Use the inspection options to specify minimum/maximum length and the regular expression expected for constants' names. To ignore the names' length, specify 0. For more information about regular expressions, refer to the Quick Start guide (regular-expressions.info). | ||
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. Use the inspection options to specify minimum/maximum length and the regular expression expected for functions' names. To ignore the names' length, specify 0. For more information about regular expressions, refer to the Quick Start guide (regular-expressions.info). | ||
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. Use the inspection options to specify minimum/maximum length and the regular expression expected for methods' names. To ignore the names' length, specify 0. For more information about regular expressions, refer to the Quick Start guide (regular-expressions.info). | ||
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. Use the inspection options to specify minimum/maximum length and the regular expression expected for properties' names. To ignore the names' length, specify 0. For more information about regular expressions, refer to the Quick Start guide (regular-expressions.info). | ||
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. Use the inspection options to specify minimum/maximum length and the regular expression expected for variables' names. To ignore the names' length, specify 0. For more information about regular expressions, refer to the Quick Start guide (regular-expressions.info). |
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 write expressions on array indexes which are immediately overwritten before being accessed. | Warning | |
Reports the classes that are implementing the 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. All reported violations result in PHP fatal errors. It is not recommended disabling or suppressing this inspection. | Error | |
Reports the usages of curly brace syntax for accessing array elements and string offsets. | Error | |
Reports the usages of deprecated entities. In most cases, such usages should be removed or replaced with other constructs. | Weak warning | |
Reports the usages of deprecated Starting from PHP 8.1, classes that are non-abstract, implement See Phasing out Serializable (php.net) for details. | Warning | |
Reports the
See __autoload (php.net) for details. | Warning | |
Reports the
See assert (php.net) for details. | Error | |
Reports deprecated usage of the Starting from PHP 7.4, using See Deprecations for PHP 7.4 (php.net) for details. | Warning | |
Reports the calls to Standard PHP Library functions that are deprecated starting from PHP 8.1. The following calls are reported:
See PHP RFC: Deprecations for PHP 8.1 for details. | 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. You can configure the set of stubs under Settings | PHP | PHP Runtime. See PhpStorm stubs (blog.jetbrains.com/phpstorm) for details. | No highlighting, only fix | |
Reports static calls to dynamic class methods. For classes having the magic method | 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. The inspection is intended to clarify the IDE’s behavior in the cases when both the class and the class alias declarations are present. When several declarations with the same FQN exist, the IDE usually fails to choose a single one between them. This leads to incorrect code completion, erroneous type inference, and so on. Since the class declaration prevails over the class alias declaration, the latter becomes redundant and therefore ignored by the IDE. Note that ignoring class alias declarations does not affect the behavior of the PHP interpreter. | Weak warning | |
Reports incompatible magic methods signatures. See RFC: Ensure correct signatures of magic methods (php.net) for details. | 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. For example, union types can be used only in PHP 8.0 and later. | Error | |
Reports method reference chains that are too long for IDE to analyze. | Weak warning | |
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. Using promoted properties is only possible since PHP 8.0. In earlier PHP versions, it leads to a parse error. See Constructor Property Promotion (php.net) for details. | No highlighting, only fix | |
Reports the private promoted properties that are never written to. In PHP 8.1 and later, such properties can be declared See Readonly properties (php.net) for details. | Weak warning | |
Reports the properties that can be replaced with promoted versions. See Constructor Property Promotion (php.net) for details. | No highlighting, only fix | |
Reports the write expressions on properties which are immediately overwritten before being accessed. | Warning | |
Reports reassignments of See Readonly properties (php.net) for details. | Error | |
Reports dynamic calls to static class methods. If the target has the magic method | ||
Reports non-resolved | Weak warning | |
Reports the usages of the entities that are marked as In most cases, the reported usages should be removed or replaced with other constructs. | Weak warning | |
Write access to 'readonly' property outside of declaration scope | Reports the write accesses to See Readonly properties (php.net) for details. | Error |
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. The See Exceptions (php.net) for details. | 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 arithmetic and bitwise expressions with unsupported operands. Starting with PHP 8.0, using the arithmetic and bitwise operators See PHP's internal test source for the complete list of operations. | 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. See Arrays (php.net) for details. | Warning | |
Reports the usages of non- Starting from PHP 5.4, string offsets have to be either integers or integer-like strings. Since it's considered bad practice to use strings as a string offset, the inspection reports them, as well. See String access and modification by character (php.net) for details. | Warning | |
Reports the | Warning | |
Reports the See foreach (php.net) for details. | 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 See Strict typing (php.net) to learn more about why you may need use this directive. | ||
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 See Type declarations (php.net) and @param (phpdoc.org) for details. | Warning | |
Reports the intersection type declarations that contain redundant types, for example, an intersection type that contains both the parent class and its subclass. See PHP RFC: Pure intersection types (php.net) for details. | Weak warning | |
Reports violations of the strict type checking rules. In strict mode, only the variables exactly matching the declaration types are accepted. Strict type-checking mode can be enabled:
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. See Union Types RFC: Duplicate and redundant types (php.net) for details. | 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. Use the options below to customize the inspection:
| 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. Use the options below to customize the inspection:
| ||
Reports the references to classes whose declarations are not found in the project files, configured include paths, or among the PHP predefined classes. Use the options below to customize the inspection:
| 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 The target See goto (php.net) for details. | 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. The inspection skips the objects of the | 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. The inspection requires PHP CS Fixer to be properly installed and set up in the IDE under Settings | PHP | Quality Tools | PHP CS Fixer. For more information about installing PHP CS Fixer, see PHP-CS-Fixer installation (GitHub). | ||
Reports coding style problems detected by PHP Mess Detector. The inspection requires PHP Mess Detector to be properly installed and set up in the IDE under Settings | PHP | Quality Tools | Mess Detector. For more information about installing PHP Mess Detector, see PHP Mess Detector installation (phpmd.org) for details. You can use a predefined set of rules or add your own by specifying valid ruleset.xml files. See the rules index (phpmd.org) and How to create a custom rule set (phpmd.org) for details. | ||
Runs PHPStan to find code problems. The inspection requires PHPStan to be properly installed and set up in the IDE under Settings | PHP | Quality Tools | PHPStan. For more information about installing PHPStan, see: https://phpstan.org/user-guide/getting-started | ||
Reports coding style problems detected by PHP_CodeSniffer. The inspection requires PHP_CodeSniffer to be properly installed and set up in the IDE under Settings | PHP | Quality Tools | PHP_CodeSniffer. For more information about installing PHP_CodeSniffer, see PHP_CodeSniffer installation (GitHub). | ||
Runs Psalm to find code problems. The inspection requires Psalm to be properly installed and set up in the IDE under Settings | PHP | Quality Tools | Psalm. For more information about installing Psalm, see: https://psalm.dev/docs/running_psalm/installation/ |
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. Some unused members might not be reported in the code editor on the fly. Due to performance reasons, a non-private member is checked only when its name rarely occurs in the project. To see all results, run the inspection in batch mode by using Code | Inspect Code... or Code | Run Inspection by Name.... | 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. Class complexity is evaluated based on three metrics:
| ||
Reports the functions or methods that are too complex. Complexity is evaluated based on four metrics:
| ||
Reports the methods that have high cyclomatic complexity and can probably be simplified. See Cyclomatic complexity (wikipedia.org) for details. | ||
Reports the methods with high Halstead Complexity metric. See Halstead measure (wikipedia.org) for details. | ||
Reports the classes that have high Lack of Cohesion metric value, which represents the degree of cohesiveness of a class. It uses class dependency graph components for class cohesiveness measure (M. Hitz and B. Montazeri definition of LCOM metric) | ||
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. Calls to library classes, parent classes, and contained or containing classes are not counted by this inspection. |
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 exception classes added to the Unchecked Exceptions list under Settings | PHP | Analysis are excluded from the inspection scope. | 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 |