PhpStorm 2021.1 Help

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

InspectionDescriptionDefault Severity
Array write access is not used

Reports the array write access expressions that are not used in code afterwards. The most common source of such problems is modifying an array passed via a parameter: if an array is passed by value, the change will not be visible outside the function.

Weak Warning Weak warning
Condition always evaluates to 'true/false'

Reports the conditions that are already covered by earlier conditions and thus have no effect.

Weak Warning Weak warning
Expression is always 'null'

Reports return variables which are effectively 'null'

Weak Warning Weak warning
Loop does not iterate

Reports the loop statements whose bodies will execute at most once.

The inspection does not report foreach 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 Weak warning
Result of 'instanceof' is always 'true'

Reports the instanceof expressions whose argument is within the hierarchy of the checked variable. Such expressions will always evaluate to true.

Weak Warning Weak warning
Typed Property might be uninitialized

Reports the attempts to read from an uninitialized typed property. Such attempts will result in TypeError.

Typed properties should be initialized in any of the following ways:

  • by a default value

  • in the constructor

  • by the __get() magic getter

  • in-place, at the moment of usage



See Uninitialized and Unset Properties (php.net) for details.

Warning Warning
Unreachable statement

Reports the statements that cannot be normally reached.

Warning Warning
Variable is always true/false when reached

Reports variables that are always true (or always false) when reached.

Weak Warning Weak warning

Composer

InspectionDescriptionDefault Severity
Duplicate package entries in composer.json

Reports duplicate package entries in the require and require-dev sections of composer.json.

Weak Warning Weak warning
Extension is missing in composer.json

Reports the usages of classes, functions, and constants from the PHP extensions not specified in composer.json.

Warning Warning
Non-installed Composer packages

Reports the Composer packages that are required in composer.json but are not installed.

Warning Warning
Quality tool inspection is disabled

Highlights the quality tools' entries in composer.json in case the corresponding code inspections are disabled.

Warning Warning
Unresolved file references

Reports unresolved file references in composer.json.

Warning Warning

Undefined

InspectionDescriptionDefault Severity
Possible polymorphic call

Reports polymorphic code usages. Such usages are ambiguous and can be potentially inoperable depending on the class instance passed as the argument.

Weak Warning Weak warning
Undefined callback

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:

  • Ignore callback from *_exists and is_callable functions: if selected, the inspection will skip callback references from the method_exists, function_exists, property_exists, class_exists and is_callable functions.

  • Don't report in case of ambiguity: if selected, the inspection will skip the parameters with multiple possible types, for example marked as callable|string.

Disabled
Undefined class

Produces two types of warnings:

  • Undefined class: the declaration of referenced class is not found in the built-in library and project files.

  • Multiple declarations: multiple class definitions were found in project files. This can lead to issues with code completion, members resolution, and class inheritance analysis.



Use the options below to customize the inspection:
  • Don't report multiple class declaration potential problems: if selected, the inspection will not report classes having multiple definitions in project files.

  • Ignore: if selected, the inspection will not report the undefined classes referenced in PHPDoc blocks.

Warning Warning
Undefined class constant

Reports the references to class constants that are not declared.

Warning Warning
Undefined constant

Reports the references to constants that are not found in the built-in library and project files.

Warning Warning
Undefined function

Reports the references to functions that are not defined in the built-in library and project files.

Warning Warning
Undefined goto label

Reports the goto labels that are not found in the current scope.

Warning Warning
Undefined method

Reports the references to class methods that are not defined.

Warning Warning
Undefined namespace

Reports the references to a namespace that is not found.

Warning Warning
Undefined property

Reports the references to class properties that are not declared.

The inspection skips the objects of the stdClass or derived types.

Warning Warning
Undefined variable

Produces two types of warnings:

  • Undefined variable: the variable's definition is not found in the built-in library and project files.

  • Variable might have not been defined: there are one or more paths to reach the line with the variable usage without defining it.



Use the options below to customize the inspection:
  • Report that variable is probably undefined: clear the checkbox to disable the Variable might have not been defined warnings.

  • Enable inspection in global space: by default, the inspection is enabled for global space. Clear the checkbox to only report undefined variables from functions' local scope.



  • Search for variable's definition outside the current file: if selected, the IDE reports a global variable as undefined only in case there are no include or require statements in the current file and the variable's definition cannot be found in the project.

    Otherwise, if not selected, the IDE searches for the variable's definition only in the current file and ignores the include or require statements if any.

Error Error

Replaceable assignments

InspectionDescriptionDefault Severity
Assignment replaceable with increment or decrement

Reports the assignments that can be replaced with incrementing (++) or decrementing (--) operations.

Using increment or decrement operators instead of assignments can make the code clearer and potentially more performant.

Info No highlighting, only fix
Assignment replaceable with operator assignment

Reports the assignments that can be replaced with combined operator assignments (for example, +=).

Using combined operator assignments can make the code clearer and potentially more performant.

Info No highlighting, only fix

PHPUnit

InspectionDescriptionDefault Severity
Covered function reference is provided without ‘::’

Reports the references to functions/methods in the @covers PHPDoc tags that are not prepended with the scope resolution operator (::).

Warning Warning
Deprecated @covers/@uses by access modifier annotation

Reports the @covers and @uses PHPUnit doc tags that are using ClassName::<*>. Such annotations won't be supported in PHPUnit 10 and later.

Weak Warning Weak warning
Deprecated assertContains/assertNotContains usage

Reports deprecated usages of the assertContains and assertContains functions with string $needle and $ignoreCase parameter.

The string $needle and optional $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 Weak warning
Deprecated assertEquals/assertNotEquals usage

Reports deprecated usages of the assertEquals and assertNotEquals functions with $delta, $maxDepth, $canonicalize, and $ignoreCase parameters.

The optional $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 Weak warning
Deprecated assertFileEquals/assertStringEqualsFile usage

Reports the deprecated usages of the assertFileEquals, assertFileNotEquals, assertStringEqualsFile, and assertStringNotEqualsFile functions with the $canonicalize and $ignoreCase parameters.

The optional $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 Weak warning
Deprecated exception handling via doc tags

Reports the usages of the following deprecated PHPUnit doc tags:

  • @expectedException

  • @expectedExceptionMessage

  • @expectedExceptionCode

  • @expectedExceptionMessageRegExp

Weak Warning Weak warning
Deprecated expectException usage

Reports deprecated usages of expectException().

Support for using the 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 Weak warning
Method assertArrayHasKey/assertArrayNotHasKey can be used instead

Reports alternative usage of the assertTrue and assertNotTrue methods with array_key_exists function as a parameter

See assertArrayHasKey for details.

Weak Warning Weak warning
Misordered assertEquals/assertNotEquals arguments

Reports any calls to PHPUnit assertEquals and assertNotEquals which have a non-literal as the expected result argument and a literal as the actual result argument. Such calls will behave fine for assertions which pass, but may give confusing error reports if their expected and actual arguments differ.

See assertEquals for details.

Weak Warning Weak warning
Missing target element for PHPUnit test

Reports the test classes and methods, for which no target elements were found.

Info No highlighting, only fix
Undefined PHPUnit data provider

Detects that the method referenced in the @dataProvider PHPDoc tag is not found.

Note that when resolving dataProvider, PHPUnit doesn't take use statements into account.

Warning Warning
Usage assertCount/assertSameSize methods instead of assertEquals

Reports alternative usage of the assertEquals and assertNotEquals methods with count function as a parameter

See Usage of the assertCount for details.

See Usage of the assertSameSize for details.

Weak Warning Weak warning

PSR-12

InspectionDescriptionDefault Severity
Compound namespace depth is more than 2

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.

Disabled
Else if

Reports the usages of the else if constructs specified in two words.

According to PSR-12, the keyword 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.

Disabled
Missing parameter list

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.

Disabled
Missing visibility

Reports properties, constants, and methods that are declared without visibility definition.

According to PSR-12, visibility MUST be defined on:

  • All properties,

  • All constants if your project's PHP minimum version supports constant visibilities (PHP 7.1 or later),

  • All methods.



See PSR-12: Extended Coding Style (php-fig.org) for details.

Disabled
One-per-line trait uses

Reports the cases of several traits being imported via a single use statement.

According to PSR-12, each individual trait imported into a class MUST be included one-per-line, and each inclusion MUST have its own use import statement.

See PSR-12: Extended Coding Style (php-fig.org) for details.

Disabled
Order of modifiers

Reports visibility modifiers that are specified in the incorrect order.

According to PSR-12, the correct order is as follows:

  • When present, the abstract and final declarations MUST precede the visibility declaration.

  • When present, the static declaration MUST come after the visibility declaration.



See PSR-12: Extended Coding Style (php-fig.org) for details.

Disabled
Short form of type keywords

Reports usages of long form type keywords.

According to PSR-12, short form of type keywords MUST be used, that is bool instead of boolean, int instead of integer, and so on.

See Keywords and Types (php-fig.org) for details.

Disabled
Usage of var

Reports the usages of the var keyword for declaring class properties.

According to PSR-12, the var keyword MUST NOT be used to declare a property.

See PSR-12: Extended Coding Style (php-fig.org) for details.

Disabled

Unused

InspectionDescriptionDefault Severity
Redundant property initializer

Reports the fields with default initializers that are always overwritten in the class constructor.

Weak Warning Weak warning
Unused declaration

Reports the classes, methods, functions, constants, or properties that are not used or not reachable from entry points. It also reports all method implementations/overriders.

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 Weak warning
Unused import

Reports the imports that are never used.

Warning Warning
Unused local variable

Reports the variables that are considered unused in the following cases:

  • The value of the variable is not used anywhere or is overwritten immediately.

  • The reference stored in the variable is not used anywhere or is overwritten immediately.



By default, the inspection is disabled for global space. To enable it, select the Enable inspection in global space checkbox below.

See global space (php.net) for details.

Warning Warning
Unused parameter

Reports the parameters that are considered unused in the following cases:

  • The parameter is passed by value, and the value is not used anywhere or is overwritten immediately.

  • The parameter is passed by reference, and the reference is not used anywhere or is overwritten immediately.

Warning Warning
Unused private method

Reports the private methods that are never used.

Warning Warning
Unused private property

Reports the private properties that are never used.

Warning Warning

Attributes

InspectionDescriptionDefault Severity
'#[ArrayShape]' attribute can be added

Reports the methods and functions that are returning arrays with known non-trivial keys. Suggests specifying the shape of the returned array via the #[ArrayShape] attribute.

Weak Warning Weak warning
'#[Pure]' attribute can be added

Reports the functions that are non-trivially pure. Such functions have other functions calls in their body, but all such calls do not produce any side effects.

Weak Warning Weak warning
Array key does not match array shape

Reports the array keys that do not match the keys specified via the #[ArrayShape] attribute.

Weak Warning Weak warning
Attribute can be added to overriding member

Reports the methods' and parameters' attributes that can be propagated to overriding methods/parameters.

See Attributes (php.net) for details.

Weak Warning Weak warning
Class cannot be used as attribute

Reports the attributes that are resolved to a class not annotated with #[Attribute].

See Attributes (php.net) for details.

Weak Warning Weak warning
Comment is parsed as attribute in PHP 8.0

Reports line comments starting with #[. In PHP 8.0 and later, such comments are parsed as attributes.

See Attributes (php.net) for details.

Warning Warning
Expected values should be used

Reports the values in assignment and comparison expressions that should be replaced with one of the expected values (that is, the values specified via the #[ExpectedValues] attribute).

See Attributes (php.net) for details.

Weak Warning Weak warning
Immutable property written in invalid scope

Highlights write access references to properties, for which the write access scope declared via #[Immutable] is stricter than the reference scope.

Error Error
NoReturn attribute can be added

Reports function without #[NoReturn] that are always halting their execution by calling other exitPoint functions attribute.

Weak Warning Weak warning
Non-applicable attribute target declaration

Reports the attributes that do not have the appropriate Attribute::TARGET_* flag in their arguments declaration.

See Attributes (php.net) for details.

Weak Warning Weak warning
Non-repeatable attribute

Reports repeated attributes without the Attribute::IS_REPEATABLE flag in their arguments declaration.

See Attributes (php.net) for details.

Weak Warning Weak warning
Pure function may produce side effects

Reports the #[Pure] annotations used on functions that may produce side effects.

Weak Warning Weak warning
Redundant parentheses in attribute

Reports empty arguments lists in attributes.

See Attributes (php.net) for details.

Weak Warning Weak warning

Code smell

InspectionDescriptionDefault Severity
'__toString' may throw an exception

Reports the usages of __toString that may throw an exception, which is not allowed for PHP language level lower than 7.4.

Warning Warning
Argument of 'instanceof' should be only objects or strings

Reports arguments of 'instanceof' that are not objects or strings

Warning Warning
Array used only with write access

Reports local arrays that are only updated, but never queried.

Weak Warning Weak warning
Case mismatch in method call or class usage

Reports the usages of functions, methods, classes, and namespaces that do not match the case used in their declarations.

Disabled
Duplicate branch in 'catch' statement

Reports catch statements with duplicated bodies.

Weak Warning Weak warning
Inconsistent return points

Reports inconsistencies in function/method exit points.

The following types of inconsistencies are reported:

  • The function/method contains the return statements both with and without arguments.

  • The function/method may return a value or otherwise end its execution without returning anything.



Technically these are not errors, but practically they usually indicate a programming mistake.

Warning Warning
Logical expression has same operands

Reports the expressions that use the same operands, but should rather use different operands.

Weak Warning Weak warning
Match expression has only default arm and should be simplified

Reports match expressions with only default match arm

Warning Warning
Method visibility shouldn't be overridden

Checks that the methods don't override visibility.

Overriding a protected 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.

Disabled
Parameters number mismatch declaration

Reports the function/method calls that take more parameters than specified in their declaration.

Warning Warning
Private property can be local

Reports the private properties that are used only in a single method. Such properties can be replaced with local variables.

Weak Warning Weak warning
Redundant 'static' in final class

Reports static usages inside final class

Weak Warning Weak warning
Redundant assignment to promoted property

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 Weak warning
Redundant optional argument

Reports redundant arguments that match the corresponding default values for optional parameters.

Weak Warning Weak warning
Ternary expression can be replaced with condition

Reports the ternary expressions specified as condition ? true : false that can be safely replaced with just condition.

Weak Warning Weak warning
Too many parameters in function declaration

Reports the function/method declarations with the number of parameters exceeding the specified limit.

Disabled
Unnecessary 'return' statement

Reports unnecessary return statements at the end of functions having the void return type. Such statements are unnecessary and can be safely removed.

See PHP RFC: Void Return Type (php.net) for details.

Weak Warning Weak warning
Unnecessary local variable

Reports the local variables that are used in exit statements, such as throw, return, or yield, immediately after their introduction.

Weak Warning Weak warning
Unnecessary pass-by-ref

Reports elements that have & in declaration and not effectively used as references.

Weak Warning Weak warning
Unnecessary semicolon

Reports unnecessary semicolons.

Weak Warning Weak warning
Usage of a silence operator

Reports the usages of the silence operator (@), which is highly discouraged.

See Error Control Operators (php.net) for details.

Disabled
Useless trailing comma

Reports the trailing commas in parameters lists and closures' use lists that do not bring any benefit.

  • In a single-line list, a trailing comma is redundant and can be removed.

  • In a multiline list, if no line break is provided after a trailing comma, it becomes impossible to easily add, remove, or move lines.

Weak Warning Weak warning

PHP strict standards

InspectionDescriptionDefault Severity
Declaration of overridden method should be compatible with parent class

Reports the overridden methods declarations that are not compatible with the parent class. The inspection is enabled only for PHP language level lower than 8.0.

Warning Warning
Static function should not be abstract

Reports the static methods that are declared as abstract.

Warning Warning

Code style

InspectionDescriptionDefault Severity
'array_fill' can be converted to loop

Reports the array_fill calls that can be replaced with the foreach loop.

Info No highlighting, only fix
'array_filter' can be converted to loop

Reports the array_filter calls that can be replaced with the foreach loop.

Info No highlighting, only fix
'array_map' call can be converted to loop

Reports the array_map calls that can be replaced with the foreach loop.

Info No highlighting, only fix
'get_class' can be replaced with '::class'

Reports the get_class calls and suggests replacing them with ::class when PHP Language level is set to 8.0 or later.

See Allow ::class on objects (php.net) for details.

Info No highlighting, only fix
'match' expression can be replace with ternary expression

Reports match expressions with default arm and only one non-default arm

Info No highlighting, only fix
'mixed' return type can be narrowed

Reports 'mixed' return types that can be narrowed down to more concrete types.

Weak Warning Weak warning
'str*' calls can be replaced with PHP 8 'str_*' calls

Reports the strpos and substr functions calls that can be replaced with the str_* functions calls (introduced in PHP 8.0).

See str_contains (php.net) and str_starts_with and str_ends_with functions (php.net) for details.

Warning Warning
'switch' can be replaced with 'match' expression

Reports 'switch' statements that could be replaced with 'match' expression

Weak Warning Weak warning
Class path doesn't match project structure

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 Warning
Closure can be converted to arrow function

Reports the anonymous functions that can be transformed to short arrow functions. Support for short arrow functions is available since PHP 7.4.

See PHP RFC: Arrow Functions 2.0 (php.net) for details.

Info No highlighting, only fix
Control statement body without braces



Reports the control statements that are not enclosed in braces.

Info No highlighting, only fix
Expression without clarifying parentheses

Reports potentially ambiguous expressions and proposes enclosing them in clarifying parentheses.

Info No highlighting, only fix
Fully qualified name usage

Reports the fully qualified class names that can be shortened by adding the use statement.

Warning Warning
Loop can be converted to 'array_fill'

Reports the for loops that can be replaced with the array_fill calls.

Info No highlighting, only fix
Loop can be converted to 'array_filter' call

Reports the foreach loops that can be replaced with the array_filter calls.

Info No highlighting, only fix
Loop can be converted to 'array_map' call

Reports the foreach loops that can be replaced with array_map calls.

Info No highlighting, only fix
Method may be 'static'

Reports the methods that don't use any instance references and thus may be converted to static methods.

Info No highlighting, only fix
Multiple classes declarations in one file

Reports multiple class declarations in a single file, which violates the PSR-0/PSR-4 standards.

See PSR-0/PSR-4 standards (php-fig.org) for details.

Warning Warning
Named arguments order does not match parameters order

Reports named argument with order that does not match parameter order

Weak Warning Weak warning
Old style constructor

Reports old-style constructor declarations (ClassName()) and suggests replacing them with new-style constructors (__construct()).

Warning Warning
Redundant closing tag

Reports PHP closing tag ?> usages, which are redundant in files containing only PHP code.

Weak Warning Weak warning
Short open tag usage

Reports short PHP opening tag <? usages.

Disabled
Single-statement body with braces



Reports the control statements that have bodies with braced statement-groups containing a single child statement.

Info No highlighting, only fix
Traditional syntax array literal detected

Reports traditional array syntax (array()) usages in array literals and suggests replacing them with short array syntax ([]).

Disabled
Trait use rule resolved to method with different containing class

Reports the trait method use rules that are resolved to methods from a different containing class rather than the one specified in the use declaration.

Weak Warning Weak warning
Unnecessary double quotes

Reports double-quoted string literals that do not contain string interpolation, escape sequences, or single quotes.

Disabled
Unnecessary fully qualified name

Reports the usages of fully qualified class names, which can be shortened without adding the use statement.

Warning Warning
Unnecessary parentheses

Reports the expressions containing redundant parenthesis, which can be safely removed.

Info No highlighting, only fix
Usage of a variable variable

Reports the usages of variable variables (dynamic variable names).

Disabled

Probable bugs

InspectionDescriptionDefault Severity
Assignment in condition

Reports the assignments that are used in conditional expressions.

Using such assignments may cause hard to detect errors. It is therefore considered a bad programming practice.

Info No highlighting, only fix
Constant reassignment

Reports reassignments of constants.

Since constants cannot be changed, such assignments will have no effect.

Warning Warning
Division by zero

Reports division by zero or modulo by zero.

Disabled
Duplicate arm in 'match' expression

Reports duplicate bodies in match arms.

See Match expression (php.net) for details.

Weak Warning Weak warning
Duplicate array keys

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 Warning
Duplicate branch in switch statement



Reports switch statements containing the same code in different branches.

Weak Warning Weak warning
Duplicate case in switch statement

Reports duplicate case expressions in switch statements.

If a switch statement contains multiple case expressions, only the first one is executed.

Warning Warning
Duplicate condition

Reports duplicate conditions in match expressions.

See Match expression (php.net) for details.

Warning Warning
Expression result unused

Reports 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 Warning
Foreach array is used as value

Reports the variables that are used as both an array expression and an array's key or value in foreach loops. Commonly, this indicates a typing error.

Warning Warning
Format function parameters mismatch

Reports the parameters and specification conversion entries that are passed as the format function's arguments but are not mapped to any entries.

Warning Warning
Goto into loop statement

Reports the goto labels that are located inside loop or switch statements.

Error Error
Invalid type of unpacked argument



Reports unpacked array elements with type neither array nor Traversable.

Warning Warning
Method __toString implementation

Reports the attempts to convert the objects having no __toString method implementation to string.

In PHP 5.2.0 and later, such attempts will cause E_RECOVERABLE_ERROR. See __toString (php.net) for details.

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 ot them doesn't contain the __toString method implementation.

Warning Warning
Method __toString return type

Reports the __toString methods that do not return string, which leads to a fatal E_RECOVERABLE_ERROR level error.

Error Error
Missing 'break' statement

Reports the case clauses in switch statements that do not end with a break or a return statement.

If a case clause does not end with break or return, its execution can unintentionally fall through the next case, which is most often an error.

Warning Warning
Missing parent call for constructor

Reports the constructors that do not call their parent constructor.

Warning Warning
Missing parent call for magic methods

Reports the magic methods that do not call their parent magic method.

Disabled
Missing parent call for method

Reports the methods that do not call their parent method.

Disabled
Nested vs outer 'foreach' variables conflict

Reports the variables that are used as a key or value both by the inner and outer foreach loops. In most cases, this is an error or may result in an error in the future.

Warning Warning
Non-strict object equality

Reports the usages of the comparison operator (==) for comparing object variables.

Object variables are compared as follows:

  • When using the comparison operator (==), two object instances are considered equal if they have the same attributes and values (values are compared with ==), and are instances of the same class.

  • When using the identity operator (===), object variables are considered identical if and only if they refer to the same instance of the same class.



See Comparing Objects (php.net) for details.

Warning Warning
Optional before required parameter

Reports the optional parameters that appear before the required parameters in function/method declaration.

See Default argument values (php.net) for details.

Warning Warning
Pass parameter by reference

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 Error
Silly assignment

Reports the assignment statements, in which both sides are equal. Such assignments have no effect and can be removed.

Warning Warning
Statement has empty body

Reports the statements that have empty bodies.

While occasionally useful, such statements are often the result of typos and may cause confusion.

Warning Warning
Switch statement without default branch



Reports switch statements without default branch

Info No highlighting, only fix
Unnecessary statement use

Reports the use statements that contain non-fully qualified import names and thus have no effect.

Import names must be fully qualified. Note that for namespaced names (that is, FQNs containing the namespace separator, such as Foo\Bar), using the leading backslash is not necessary and not recommended. For global names that do not contain the namespace separator, such as FooBar, using the leading backslash is required.

See Using namespaces: Aliasing/Importing (php.net) for details.

Warning Warning
Unused 'match' condition

Reports the conditions in match expressions that will never be matched.

Similarly to PHP Engine behavior, the inspection uses strict comparison (===) 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.

Warning Warning
Void function result used

Reports the attempts to use the value of a void function.

Since void functions do not have a return value, such attempts are most likely a programming mistake.

Warning Warning
Wrong string concatenation

Reports the attempts to concatenate strings by using the + operator instead of the dot (.) concatenation operator. Such attempts are most likely a programming mistake.

Warning Warning

Naming conventions

InspectionDescriptionDefault Severity
Class name is not following coding convention

Reports the classes' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for classes.

Use the fields below 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).

Disabled
Constant name is not following coding convention

Reports the constants' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for constants.

Use the fields below 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).

Disabled
Function name is not following coding convention

Reports the functions' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for functions.

Use the fields below 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).

Disabled
Method name is not following coding convention

Reports the methods' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for methods.

Use the fields below 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).

Disabled
Property name is not following coding convention

Reports the properties' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for properties.

Use the fields below 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).

Disabled
Variable name is not following coding convention

Reports the variables' names that are either too short, too long, or do not follow the specified regular expression pattern. Some coding styles have a special naming convention for variables.

Use the fields below 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).

Disabled

General

InspectionDescriptionDefault Severity
Argument with name identifier

Reports arguments with name identifiers.

Info No highlighting, only fix
Argument without name identifier

Reports arguments without name identifiers.

Info No highlighting, only fix
Class can't implement Traversable directly

Reports the classes that are implementing the Traversable interface alone, not as part of Iterator or IteratorAggregate interfaces.

The Traversable interface is an internal engine interface; it cannot be implemented in PHP scripts. See The Traversable interface (php.net) for details.

Error Error
Class hierarchy checks

Checks the classes' hierarchy: abstract methods implementation, the compatibility of implementing/overriding methods with their declarations in parent classes, and properties' types redeclarations.

All reported violations result in PHP fatal errors. It is not recommended disabling or suppressing this inspection.

Error Error
Curly brace access syntax usage



Reports the usages of curly brace syntax for accessing array elements and string offsets.

Error Error
Deprecated

Reports the usages of deprecated entities.

In most cases, such usages should be removed or replaced with other constructs.

Weak Warning Weak warning
Deprecated cast

Reports deprecated cast expressions:

  • (unset) cast expressions, which are deprecated starting from PHP 7.2.

  • (real) cast expressions, which are deprecated starting from PHP 7.4.



See Deprecated features in PHP 7.2.x (php.net) and Deprecations for PHP 7.4 (php.net) for details.

Weak Warning Weak warning
Deprecated implode/join usage

Reports deprecated usage of the implode and join functions.

Starting from PHP 7.4, using 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 Warning
Disabled extension stubs

Reports the usages of classes, functions, and constants, for which the extension stubs are disabled.

Info No highlighting, only fix
Dynamic method called as static

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 Warning
Element is not available in configured PHP version

Reports the usages of entities which were introduced in PHP version later than configured one.

Error Error
Ignored class alias declaration

Reports the class alias declarations that are ignored by the IDE because the actual class declaration with the same FQN exists.

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 missing 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 Weak warning
Incorrect magic method signature

Reports incompatible magic methods signatures.

See RFC: Ensure correct signatures of magic methods (php.net) for details.

Error Error
Invalid magic method modifiers

Reports magic methods that are not declared as public or are declared as static.

Warning Warning
Language level

Reports the language features used in source code that are not supported for the selected language level.

For example, traits can be used only in PHP 5.4 and later.

Error Error
Method declaration of super class is incompatible with implemented interface

Reports the methods declarations in parent classes that are incompatible with implemented interfaces.

Error Error
Named argument may be unresolved

Reports the named arguments in method calls that might be unresolved depending on a specific class instance within the hierarchy.

Weak Warning Weak warning
Nested ternary operator usage



Reports nested ternary expressions. They are deprecated starting from PHP 7.4.

Error Error
Parameter's name changed during inheritance

Reports the methods' parameters whose names differ from the same parameters defined in parent methods. Starting with PHP 8.0, such code can cause runtime errors.

Weak Warning Weak warning
Promoted property usage

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.

Info No highlighting, only fix
Property can be promoted

Reports the properties that can be replaced with promoted versions.

See Constructor Property Promotion (php.net) for details.

Info No highlighting, only fix
Static method called as dynamic

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.

Disabled
Unresolved include

Reports non-resolved include expressions.

Warning Warning
Usage of internal entity

Reports the usages of the entities that are marked as @internal.

In most cases, such usages should be removed or replaced with other constructs.

Weak Warning Weak warning

Error handling

InspectionDescriptionDefault Severity
Redundant catch clause

Reports the catch clauses with exceptions that are never thrown from the corresponding try block.

Warning Warning
Unhandled exception

Reports the exceptions that are neither enclosed in a try-catch block nor documented via the @throws tag.

Weak Warning Weak warning
Wrong catch clauses order

Reports the catch clauses listed in the incorrect order and the exception classes caught twice.

The catch 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 Warning

Type compatibility

InspectionDescriptionDefault Severity
Illegal array key type

Reports the array keys that are of illegal type, such as objects or arrays.

See Arrays (php.net) for details.

Warning Warning
Illegal string offset

Reports the usages of non- integer offsets in string access expressions such as $str[42].

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 Warning
Incompatible return type

Reports the return statements whose return value type is not compatible with the one declared for a function/method.

Warning Warning
Invalid argument supplied for foreach()

Reports the foreach constructs used on variables that are not of the array or object type.

See foreach (php.net) for details.

Warning Warning
Missing parameter's type declaration

Reports the parameters that have no type declaration specified.

Weak Warning Weak warning
Missing property's type declaration

Reports the properties that have no type declaration.

Weak Warning Weak warning
Missing return type declaration

Reports the functions that have no return type declaration specified.

Weak Warning Weak warning
Missing strict types declaration

Detects the missing declare(strict_types=1) directive in the file.

See PHP RFC: Scalar Type Declarations (php.net) to learn more about why you may need use this directive.

Disabled
PHP 8 TypeError on arithmetic operations

Reports arithmetic and bitwise expressions with unsupported operands.

Starting with PHP 8, 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 Error
Parameter type

Reports the parameters passed to a function call, whose types do not match the ones specified in the function definition via type declaration or the PHPDoc @param tag.

See Type declarations (php.net) and @param (phpdoc.org) for details.

Warning Warning
Strict type checking rules violation

Reports violations of the strict type checking rules.

In strict mode, only variables exactly matching the declaration types are accepted. Strict type-checking mode can be enabled:

  • Per file, if the declare(strict_types=1) directive is specified. The directive must be the first statement in a file, block mode is explicitly disallowed.

  • For all files, if the Enable for all files option is selected below.



See Strict typing (php.net) for details.

Error Error
Type declaration is redundant and could be simplified

Reports union type declarations that contain redundant types, for example, a union type that contains both the class alias and the original class.

See Union Types RFC: Duplicate and redundant types (php.net) for details.

Weak Warning Weak warning
Type mismatch in property assignment

Reports type violations in properties assignments

Warning Warning

Quality tools

InspectionDescriptionDefault Severity
PHP CS Fixer validation

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.

It is recommended to install PHP CS Fixer either as a Composer dependency or globally. See PHP-CS-Fixer installation (GitHub) for details.

Disabled
PHP Mess Detector validation

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.

It is recommended to install PHP Mess Detector either as a Composer dependency or globally. 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.

Disabled
PHPStan validation

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.


It is recommended to install PHPStan either as a Composer dependency or globally. For more information, see: https://github.com/phpstan/phpstan#installation

Disabled
PHP_CodeSniffer validation

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.

It is recommended to install PHP_CodeSniffer either as a Composer dependency or globally.

See PHP_CodeSniffer installation (GitHub) for details.

Disabled
Psalm validation

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.


It is recommended to install Psalm either as a Composer dependency or globally. For more information, see: https://psalm.dev/docs/running_psalm/installation/

Disabled

PHPDoc

InspectionDescriptionDefault Severity
Inappropriate @inheritDoc usage

Reports inappropriate @inheritDoc usages:

  • On non-class members

  • On class members without any super members having a doc comment.

Weak Warning Weak warning
Missing @return tag

Checks that the PHPDoc block for a function/method contains the @return tag.

Weak Warning Weak warning
Missing @throws tag(s)

Checks that the PHPDoc block contains the @throws tag for each exception thrown by a function/method.

Weak Warning Weak warning
Missing PHPDoc comment

Reports the elements without a PHPDoc comment specified.

Disabled
Non-canonical order of elements

Reports the PHPDoc tags that have elements listed in non-canonical order.

For example, for such tags as @property, @param, or @var, the inspection will report the usages of [name] ["Type"] instead of ["Type"] [name].

Disabled
PHPDoc comment matches function/method signature

Checks that the number of parameters, their names, or types (if any) in a PHPDoc comment matches the ones in the function/method declaration.

Weak Warning Weak warning
Redundant @throws tag(s)

Reports the @throws tags for exceptions that are not thrown by the function/method.

Weak Warning Weak warning
Redundant @var tag

Reports the @var tags for variables whose type is already inferred from source code.

Weak Warning Weak warning
Redundant PHPDoc comment

Reports the PHPDoc comments that contain only the information already provided in declarations.

Info No highlighting, only fix
Type already exists in PHPDoc tag

Reports duplicate types in PHPDoc comments.

Weak Warning Weak warning
Type doesn't match property's declared type

Reports type mismatches in PHPDoc @var tags

Weak Warning Weak warning
Last modified: 16 July 2021