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 functions with the | 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 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 reportforeach loops with a key or value used inside the loop body. Commonly, such loops are intended to perform an action only on their first iteration (for example, get the first element of an array). | Weak warning | |
Reports the | Weak warning | |
Reports the attempts to read from an uninitialized typed property. Such attempts will result in
| 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 unset . 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 | Weak warning | |
Reports the | Weak warning | |
Reports the references to functions/methods in the | Weak warning | |
Reports deprecated usages of the $needle and optional boolean $ignoreCase parameters of the assertContains and assertNotContains functions are deprecated and will be removed in PHPUnit 9. See Usage of the assertEquals function (phpunit.readthedocs.io) for details. | Weak warning | |
Reports deprecated usages of the $delta , $maxDepth , $canonicalize , and $ignoreCase parameters of the assertEquals and assertNotEquals functions are deprecated and will be removed in PHPUnit 9. See Usage of the assertEquals function (phpunit.readthedocs.io) for details. | Weak warning | |
Reports the deprecated usages of the $canonicalize and $ignoreCase parameters of the assertFileEquals and assertFileNotEquals functions are deprecated and will be removed in PHPUnit 9. 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 expectException() method with \PHPUnit\Framework\Error\Deprecated , \PHPUnit\Framework\Error\Error , \PHPUnit\Framework\Error\Notice , and \PHPUnit\Framework\Error\Warning is deprecated and will be removed in PHPUnit 10. Instead, the expectDeprecation() , expectError() , expectNotice() , and expectWarning() methods should be used. See Testing PHP Errors, Warnings, and Notices (phpunit.readthedocs.io) for details. | Weak warning | |
Method 'assertArrayHasKey/assertArrayNotHasKey' can be used instead | Reports the | 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 | 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 dataProvider , PHPUnit doesn't take use statements into account. | 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. 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 elseif SHOULD be used instead of else if so that all control keywords look like single words. 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:
| ||
Reports the cases of several traits being imported via a single use import statement. 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:
| ||
Reports usages of long form type keywords. According to PSR-12, short form of type keywords MUST be used, that isbool instead of boolean , int instead of integer , and so on. See Keywords and Types (php-fig.org) for details. | ||
Reports the usages of the var keyword MUST NOT be used to declare a property. 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. | 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. See Attributes (php.net) for details. | 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. See Attributes (php.net) for details. | Weak warning |
Code smell
Inspection | Description | Default Severity |
---|---|---|
Reports the usages of | Warning | |
Reports the | Weak warning | |
Reports the | Weak warning | |
Reports the
| 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 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 | 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 aE_NOTICE level error. In PHP 8.0, an E-WARNING is emitted. | 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 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:
| 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. Overriding aprotected method with a public method in a child class makes this method accessible from everywhere. This violates the encapsulation principle and is considered bad practice. 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 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 | 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 | Weak warning | |
Reports unnecessary semicolons. | Weak warning | |
Reports the usages of the spread operator ( | 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 |
---|---|---|
'Closure::fromCallable()' can be converted to the first-class callable syntax | Reports the | Weak warning |
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 match expressions use strict type comparison, while switch statements rely on loose comparison. As a result, the expression semantics may change after replacement. See match (php.net) and switch (php.net) for details. | No highlighting, only fix | |
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 automatic conversions of | 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. You can configure the project vendor roots under Settings/Preferences | 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 $arr already contains some value (for example, a string from a request variable), then this value will stay in place and [] may actually stand for string access operator. It is always preferable to initialize a variable by direct assignment. 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 | ||
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 0o/0O prefix are supported in PHP 8.1 and later. 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 | |
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. 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@property , @param , or @var , the inspection will report the usages of [name] ["Type"] instead of ["Type"] [name] . | ||
Reports the null-checking conditional expressions that can be safely replaced with the | Weak warning | |
Reports old-style constructor declarations ( E_DEPRECATED error. If both a __construct() and a ClassName() method are defined, __construct() will be called. In namespaced classes, or any classes as of PHP 8.0, a ClassName() method never has any special meaning and will never be called as a constructor. As a result, the inspection does not report such cases if the PHP language level is set to 8.0 or later. 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 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. 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 | 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 | 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 Foo\Bar as opposed to global names that do not, such as FooBar ), the leading backslash is unnecessary and not recommended, as import names must be fully qualified and are not processed relative to the current namespace. 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 | Error | |
Reports the string concatenation expressions that are used together with | Warning | |
Reports reassignments of constants. Since constants cannot be changed, such assignments will have no effect and will emit anE_NOTICE (in PHP 7.4 and earlier) or E_WARNING (in PHP 8.0 and later). | Warning | |
Reports division by zero or modulo by zero. | Error | |
Reports duplicate bodies in | 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 switch statement contains multiple duplicate case expressions, only the first one is executed. | Warning | |
Reports duplicate characters provided in the | 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. Such errors can be caused, for example, by misspelling the= operator as == . | Warning | |
Reports the variables that are used in a | Warning | |
Reports the arguments of a format function (such as | Warning | |
Reports the | 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 Fatal error . | 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 E_RECOVERABLE_ERROR level error. In PHP 7.4, a fatal non-recoverable ERROR is thrown. In PHP 8.0, the return value follows the standard PHP type semantics and will be coerced into a string if possible and if strict typing is disabled. 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 __toString method implementation. See __toString (php.net) for details. | Warning | |
Reports the E_RECOVERABLE_ERROR level error. In PHP 7.4, a fatal non-recoverable ERROR is thrown. In PHP 8.0, the return value follows the standard PHP type semantics and will be coerced into a string if possible and if strict typing is disabled. See __toString (php.net) for details. | Error | |
Reports the case clause does not end with break or return , its execution can unintentionally fall through the next case. | 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 (
| 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 | |
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 | 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 | Warning | |
Reports the conditions in === ) to check the types in match conditions against the match argument type, regardless of the strict_types directive. Since no type coercion occurs, some conditions may be non-matched due to non-matching types. See Match expression (php.net) for details. | Weak warning | |
Reports the branches in | Weak warning | |
Reports the usages of a void functions do not have a return value, such usages are most likely a programming mistake. | Warning | |
Reports the attempts to concatenate strings by using the | Warning |
Regular expressions
Inspection | Description | Default Severity |
---|---|---|
Reports the regular expression patterns that comprise repeating characters ending with an asterisk | Weak warning | |
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 |
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. To learn more 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. To learn more 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. To learn more 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. To learn more 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. To learn more 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. To learn more 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 Traversable interface is an internal engine interface; it cannot be implemented in PHP scripts. See The Traversable interface (php.net) for details. | 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 Serializable , and do not implement __serialize() and __unserialize() will throw a deprecation warning. See Phasing out Serializable (php.net) for details. | Warning | |
Reports deprecated usage of the implode and join with an array as the first argument and a string as the second argument is deprecated. 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:
| Warning | |
Reports deprecated cast expressions:
| 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/Preferences | 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__callStatic , a separate inspection severity and highlighting level can be set. | 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 | |
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 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 | Error | |
Reports dynamic calls to static class methods. If the target has the magic method__call , a separate inspection severity and highlighting level can be set. | ||
Reports non-resolved | Weak warning | |
Reports the usages of the entities that are marked as | Weak warning | |
Write access to 'readonly' property outside of declaration scope | Reports the write accesses to | 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. Thecatch clauses must be ordered from more specific to more generic ones. Otherwise, some exceptions may not be caught by the most specific handler. 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+ , - , * , / , ** , % , << , >> , & , | , ^ , ~ , ++ , -- when one of the operands is an array, resource, or non-overloaded object will result in a TypeError . The only exception is the array + array merge operation, which remains supported. 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- | 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 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 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:
| 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 goto label must reside in the same file and context: you cannot jump into or out of a function or method, and cannot jump into a loop or switch structure. 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 thestdClass or derived types. | Warning | |
Produces two types of warnings:
| 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/Preferences | PHP | Quality Tools | PHP CS Fixer. To learn more 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/Preferences | PHP | Quality Tools | Mess Detector. To learn more 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/Preferences | PHP | Quality Tools | PHPStan. To learn more 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/Preferences | PHP | Quality Tools | PHP_CodeSniffer. To learn more 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/Preferences | PHP | Quality Tools | Psalm. To learn more 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 | 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 |