PhpStorm 2020.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 Settings/Preferences Ctrl+Alt+S.

Composer

Inspection

Description

Default 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

Inspection

Description

Default Severity

Possible polymorphic call

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

Weak Warning 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.

  • Report in files containing include statements: by default, all global-space variables in the files containing the include or require statements are considered defined. To enable inspecting and reporting such variables, select the checkbox and make sure the inspection is enabled for global space.

Error Error

Replaceable assignments

Inspection

Description

Default 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

Inspection

Description

Default 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 deprecated usages of the assertFileEquals, assertFileNotEquals, assertStringEqualsFile and assertStringNotEqualsFile functions with $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

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.

Warning Warning
Static function should not be abstract

Reports the static methods that are declared as abstract.

Warning Warning

PSR-12

Inspection

Description

Default Severity

Compound namespace depth is more than 2

Reports the usages of compound namespaces whose depth exceeds two levels.

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 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



Based on PSR-12, short form of type keywords MUST be used i.e. bool instead of boolean, int instead of integer etc.

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

Inspection

Description

Default 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

Code Style

Inspection

Description

Default 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

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. The support for short arrow functions is announced for 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
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
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

Inspection

Description

Default 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 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
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
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

Control Flow

Inspection

Description

Default Severity

Expression is always 'null'

Reports return variables which are effectively 'null'

Weak Warning Weak warning
Unreachable statement

Reports the statements that cannot be normally reached.

Warning Warning

Code Smell

Inspection

Description

Default Severity

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
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
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
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 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

Naming conventions

Inspection

Description

Default Severity

Class name is not following coding convention

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

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

Inspection

Description

Default Severity

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
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
Nested ternary operator usage



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

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

Inspection

Description

Default 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

Inspection

Description

Default 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 string indexes that are not of the integer type.

As of PHP 5.4, string offsets have to either be integers or integer-like strings. Since it's considered bad practice to use strings as a string index, the inspection reports them, as well.

See Strings (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 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.

Info No highlighting, only fix

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
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 mismatch in property assignment

Reports type violations in properties assignments

Warning Warning

Quality tools

Inspection

Description

Default 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 | Languages & Frameworks | 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 | Languages & Frameworks | 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
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 | Languages & Frameworks | 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

PHPDoc

Inspection

Description

Default 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 PHPDoc comments which only duplicate information from 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: 5 June 2020