PhpStorm 2021.2 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
'foreach' variable overwrites already defined variable

Reports the keys and values in foreach loops that are assigned a non-primitive value before the foreach loop and are accessed after it. Such usages may unwillingly overwrite an already defined value and cause latent bugs.

Weak Warning Weak warning
'if' with common parts

Reports the if statements with duplicated common parts.

Weak Warning Weak warning
'switch' with common parts

Reports the 'switch' statements with duplicated common parts.

Weak Warning Weak warning
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
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 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
Unnecessary 'else' branch

Reports the else branches in if statements whose bodies always execute a terminating statement such as return or throw. Such branches are redundant and can be safely omitted.

Info No highlighting, only fix
Unreachable statement

Reports the statements that cannot be 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
Write access to referenced array value without 'unset'

Reports the write access expressions on variables that are still referencing the array value previously used in a foreach statement.

It is recommended to destroy such references by using unset.

See foreach (php.net) and unset (php.net) for details.

Warning 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. If an extension is listed in the require-dev section of composer.json, the inspection reports the corresponding symbols' usages located outside of the folders marked as test roots.

Warning Warning
Non-installed Composer packages

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

Weak Warning Weak warning
Quality tool inspection is disabled

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

Weak Warning Weak warning
Unresolved file references

Reports unresolved file references in composer.json.

Warning Warning

Replaceable assignments

InspectionDescriptionDefault Severity
Assignment replaceable with increment or decrement

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

Info No highlighting, only fix
Assignment replaceable with operator assignment

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

Info No highlighting, only fix

Psalm

InspectionDescriptionDefault Severity
Function call is not compatible with 'callable' declaration

Reports the parameters in function calls whose types are not compatible with the ones defined via Closure.

Warning Warning

PHPUnit

InspectionDescriptionDefault Severity
Assertion can be replaced with 'assertEmpty/assertNotEmpty'

Reports the assertTrue/ assertFalse usages that can be replaced with assertEmpty/ assertNotEmpty in PHPUnit tests.

See assertEmpty (phpunit.readthedocs.io) for details.

Weak Warning Weak warning
Assertion can be replaced with 'fail'

Reports the usages of assertTrue/ assertFalse methods with the false/ true arguments in PHPUnit tests. Such usages can be replaced with fail calls to indicate that a test is expected to fail.

Weak Warning Weak warning
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 (::).

Weak Warning Weak warning
Deprecated 'assertContains/assertNotContains' usage

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

The string $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 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 @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 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 corresponding production classes or methods were found.

Info No highlighting, only fix
Undefined PHPUnit data provider

Reports the references to functions/methods in the @dataProvider PHPDoc tag that are not resolved.

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

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
'continue' is targeting 'switch' statement

Reports the continue statements that are targeting switch statements. In PHP 7.3 and later, such usages are deprecated and will emit an E_WARNING, since they are most likely the result of a programming mistake.

  • In PHP, such continue statements are equivalent to break, that is, they end the execution of the current switch structure.

  • In other languages, such continue statements behave as continue 2 in PHP, that is, they take the execution to a higher level control structure (for example, the next iteration of an outer loop).



See continue (php.net), break (php.net), and switch (php.net) for details.

Weak Warning Weak warning
'func_get_arg' call can be replaced with parameter access

Reports the func_get_arg calls that can be replaced with direct parameter access.

Weak Warning Weak warning
'if' can be merged with subsequent condition

Reports the if statements that are followed by elseif or other if statements having the same bodies. Such statements can be merged together.

Info No highlighting, only fix
'in_array' can be replaced with comparison

Reports the in_array calls that are provided with a single-element array as the $haystack argument. Such calls can be replaced with direct comparisons.

See in_array (php.net) for details.

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

Reports the match expressions only containing a default arm. Such expressions are redundant and should be simplified.

See Match expression (php.net) for details.

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

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

Warning Warning
Array access can be replaced with 'foreach' value

Reports the array access expressions inside foreach loops that can be replaced with a foreach value.

Weak Warning Weak warning
Array is always empty at the point of access

Reports the iterated/accessed arrays that are known to be empty at the point of access.

Weak Warning Weak warning
Array used only with write access

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

Weak Warning Weak warning
Boolean expression can be simplified

Reports the boolean expressions that contain the true or false literals and can be simplified.

Weak Warning Weak warning
Class constant referenced via child class

Reports the class constant references that target the constant from the parent class of the referenced class.

Weak Warning Weak warning
Concatenation to empty string can be merged with assignment

Reports the .= concatenation assignments performed right after assignment to an empty string literal. Such assignments can be merged together.

Weak Warning Weak warning
Constant name defined with a leading slash

Reports the define constructs in which the constant's FQN starts with a leading slash. Such constants will not be correctly registered by PHP.

Warning Warning
Duplicate branch in 'catch' statement

Reports catch statements with duplicated bodies.

Weak Warning Weak warning
Exception is immediately rethrown

Reports the catch statements that only rethrow a caught exception, which is located in a class hierarchy different from the subsequent exception types.

Weak Warning Weak warning
Format function call with single argument

Reports the sprintf and vsprintf calls with a single argument. Such calls can be safely unwrapped.

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 (for example, $var == $var). These include comparison, logical, null-coalescing, subtraction, and division expressions.

Weak Warning Weak warning
Loop can be replaced with 'implode'

Reports the foreach loops that can be safely replaced with implode calls.

See implode (php.net) for details.

Weak Warning Weak warning
Loop can be replaced with 'str_repeat'

Reports the for loops that can be safely replaced with str_repeat calls.

Weak Warning Weak warning
Method visibility should not 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
Method's return value is never used

Reports the private methods returning the values that are not used.

Weak Warning Weak warning
Nested 'dirname' call can be replaced with 'levels' parameter usage

Reports the nested dirname calls that can be omitted by using the levels parameter instead.

Weak Warning Weak warning
Parameter's value is always the same

Reports the parameters in private methods that have the same value across all method calls.

Weak Warning Weak warning
Parameters number mismatch declaration

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

Weak Warning Weak 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
Property usages have same access

Reports the private properties that are:

  • written but never read

  • read but never written

Warning Warning
Redundant 'continue/break' argument

Reports the redundant 1 argument of continue and break statements. Since this argument is optional and its default value is 1, such usages can be omitted.

See continue (php.net) and break (php.net) for details.

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 cast to boolean

Reports the (bool)/ (boolean) casts and boolval calls that are redundant since casting to bool is performed implicitly.

Weak Warning Weak warning
Redundant cast to string

Reports the (string) casts and strval calls that are redundant since casting to string is performed implicitly.

Weak Warning Weak warning
Redundant method override

Reports the overriding methods that only consist of a single call to the parent method.

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
Ternary expression can be replaced with short version

Reports the ?: ternary expressions in which the condition and the true statement are matching.

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/continue' statement

Reports unnecessary return and continue statements that can be safely removed.

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

Weak Warning Weak warning
Unnecessary pass-by-ref

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 & in parameter's declaration can be safely removed.

See Passing by Reference (php.net) for details.

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 the 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 foreach loops.

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

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

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

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

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
'isset' can be replaced with coalesce

Reports the conditions using isset that can be safely replaced with expressions using the ?? null coalesce operator.

See Null coalesce operator (php.net) for details.

Weak Warning Weak warning
'match' expression can be replace with ternary expression

Reports the match expressions containing a default arm and a single non-default arm. Such match expressions can be replaced with ternary expressions.

See Match expression (php.net) for details.

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
'mixed' type can be replaced with 'array'

Reports the mixed[] usages in PHPDoc blocks that can be safely replaced with array.

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.

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

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

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
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 structures (such as loops or conditionals) whose bodies are not enclosed in braces.

See Control structures (php.net) for details.

Info No highlighting, only fix
Dangerous array initialization

Reports dangerous array initializations (such as $arr[] = value).

This practice is discouraged because if $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.

Info No highlighting, only fix
Define constant name can be replaced with 'const' syntax

Reports define calls that can be replaced with const syntax

Weak Warning Weak warning
Enforce PHPDoc comment

Reports the elements without a PHPDoc comment or with a PHPDoc comment only containing the @noinspection tag.

You can use Missing PHPDoc Comment inspection to report only non-fully typed elements.

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

Weak Warning Weak warning
Loop can be converted to 'array_fill' call

Reports the for loops that can be replaced with 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 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
Missing @throws tag(s)

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

The exception classes added to the Unchecked Exceptions list under Settings/Preferences | PHP | Analysis are excluded from the inspection scope.

Weak Warning Weak warning
Missing PHPDoc comment

Reports non-fully typed elements without a PHPDoc comment or with a PHPDoc comment only containing the @noinspection tag.

You can use the Enforce PHPDoc Comment inspection to report fully typed elements.

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

Weak Warning Weak warning
Named arguments order does not match parameters order

Reports named argument with order that does not match parameter order

Weak Warning Weak warning
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
Nullsafe operator '?->' can be used

Reports the null-checking conditional expressions that can be safely replaced with the ?-> nullsafe operator.

Weak Warning Weak warning
Old style constructor

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

Prior to PHP 8.0, old-style constructor syntax used in the classes in the global namespace is treated as deprecated and will result in an 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 Warning
PHPDoc comment signature is not complete

Reports the PHPDoc comments that contain at least one @param or @return tag but are missing some of the @param or @return tags for parameters or return types specified in the function/method declaration.

Weak Warning Weak 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. Since short tags can be disabled in the PHP interpreter configuration, using them may lead to code compatibility issues.

See PHP tags (php.net) for details.

Warning Warning
Single-statement body with braces

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.

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 usage is not allowed

Reports the class references that are resolved to traits but are specified outside use statements. Such usages are most probably the result of a programming mistake, since traits cannot be instantiated and any instanceof -like behaviour is not supported for traits by design.

See Traits (php.net) for details.

Weak Warning Weak warning
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
Type cast is unnecessary

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 Weak warning
Unnecessary curly braces syntax for variable

Reports unnecessary { and } used for interpolating variables in string literals.

See Variable parsing (php.net) for details.

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.

Weak Warning Weak warning
Unnecessary leading '\' in 'use' statement

Reports the use statements with an unnecessary leading \.

For namespaced names (fully qualified namespace names containing a namespace separator, such as 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 Weak 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 such as $$a).

Disabled

Probable bugs

InspectionDescriptionDefault Severity
Assignment in condition

Reports the assignments that are used in conditional expressions.

Info No highlighting, only fix
Case with specified value not found in enum

Reports the arguments of enum's from method calls that are not found in target enum classes.

See Enumerations (php.net) for details.

Error Error
Concatenation with arithmetic usage

Reports the string concatenation expressions that are used together with +, -, <<, and >> operators. Starting with PHP 8, the concatenation operation has lower precedence and such expressions can thus produce unexpected results.

See Concatenation precedence (php.net) for details.

Warning Warning
Constant reassignment

Reports reassignments of constants.

Since constants cannot be changed, such assignments will have no effect and will emit an E_NOTICE (in PHP 7.4 and earlier) or E_WARNING (in PHP 8.0 and later).

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 the 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 duplicate 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
Empty index operator not supported for strings

Reports the usages of empty index operator ([]) on strings.

Starting from PHP 7.1, applying the empty index operator on a string throws a fatal error.

See Creating/modifying with square bracket syntax (php.net) for details.

Error Error
Expression result unused

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

Reports the variables that are used in a foreach loop as both an array expression and an array's key or value (for example, foreach ($items as $items) {}).

Commonly, this is the result of a typing error.

Warning Warning
Format function parameters mismatch

Reports the arguments of a format function (such as printf or sprintf) that are not mapped to any parameters or specification conversions.

See printf (php.net) and sprintf (php.net) for details.

Warning Warning
Goto into loop statement

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

See goto (php.net) for details.

Error Error
Invalid type of unpacked argument

Reports unpacked function arguments and array elements whose type is neither array nor Traversable.

Starting with PHP 8.0, such usages will result in Fatal error.

Warning Warning
Method '__toString' implementation

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

Prior to PHP 7.4, this would lead to a fatal 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 Warning
Method '__toString' return type

Reports the __toString methods that do not return string.

Prior to PHP 7.4, this would lead to a fatal 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 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.

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

Weak Warning Weak warning
Optional before required parameter

Reports the optional parameters that appear before the required parameters in a 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
Redundant assignment

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

Warning Warning
Some enum cases are uncovered

Reports the match expressions that don't cover all enum cases in match arm conditions.

Weak Warning Weak 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
Strict comparison of operands with incompatible types

Reports the === or !== strict comparisons used on operands with incompatible types.

See PHP type comparison tables (php.net) for details.

Weak Warning Weak warning
Suspicious names combination

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:

  • needle, haystack

  • x, y

  • top, bottom, left, right

  • year, month, week, day, hour, minute, second

Warning Warning
Switch statement without default branch

Reports the switch statements without a default branch.

Info No highlighting, only fix
Unnecessary statement use

Reports the use statements that contain non-fully qualified class names and thus have no effect. The inspection only reports classes imports; functions and constants imports are not considered.

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.

Weak Warning Weak warning
Unused 'switch' branch

Reports the branches in switch statements that do not belong to the set of enum cases and as a result are never executed.

See Enumerations (php.net) for details.

Weak Warning Weak warning
Void function result used

Reports the usages of a void function's return value.

Since void functions do not have a return value, such usages 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 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).

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

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

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

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

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

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 '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
Deprecated cast

Reports deprecated cast expressions:

  • (unset) cast expressions, which are deprecated in PHP 7.2 and later.

  • (real) cast expressions, which are deprecated in PHP 7.4 and later.



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

Weak Warning Weak warning
Disabled extension stubs

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.

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 the 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, union types can be used only in PHP 8.0 and later.

Error 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 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, which 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, include_once, require, and require_once expressions.

Weak Warning Weak warning
Usage of internal entity

Reports the usages of the entities that are marked as @internal and are located in different source roots. The usages located in the same source root are not reported.

In most cases, the reported 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.

Weak Warning Weak 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 exceptions that are already caught by a preceding exception and the exceptions that are 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
'null' is not compatible with parameter's declared type

Reports the variables that are initialised via passing them by reference to a parameter incompatible with null.

Error Error
Array offset access on illegal type

Reports the array offset access expressions that are used on illegal types.

Weak Warning Weak warning
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 of the string, float, int, or boolean 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 Strict typing (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 the 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 inspection option is enabled.



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

Undefined symbols

InspectionDescriptionDefault Severity
Multiple class declarations

Reports the references to classes that have multiple declarations in project files.

Use the options below to customize the inspection:

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

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

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:

  • Ignore PHPDoc: 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.

Error Error
Undefined constant

Reports the references to constants that are not found in the project files, configured include paths, or among the PHP predefined constants.

Warning Warning
Undefined function

Reports the references to functions that are not defined in the project files, configured include paths, or among the PHP predefined functions.

Warning Warning
Undefined goto label

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

The target 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 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 project files, configured include paths, or among the PHP predefined variables.

  • 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

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.

To learn more about installing PHP CS Fixer, see PHP-CS-Fixer installation (GitHub).

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.

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.

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.


To learn more about installing PHPStan, see: https://phpstan.org/user-guide/getting-started

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.

To learn more about installing PHP_CodeSniffer, see PHP_CodeSniffer installation (GitHub).

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.


To learn more about installing Psalm, see: https://psalm.dev/docs/running_psalm/installation/

Disabled

Unused symbols

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.

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

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

Weak Warning Weak warning
Unused private method

Reports the private methods that are never used.

Weak Warning Weak warning
Unused private property

Reports the private properties that are never used.

Weak Warning Weak warning

Refactoring opportunities

InspectionDescriptionDefault Severity
Class has too many declared members

Reports the classes that have too many properties or methods.

Disabled
Complex class should be refactored

Reports the classes that are too complex.

Class complexity is evaluated based on three metrics:

  • TCC (Tight class cohesion) — the measure of class cohesiveness (more is better).

  • WMC (Weighted Method count) — the sum of cyclomatic complexities for all methods in a class (less is better).

  • ATFD (Access to foreign data) — the number of properties from another class that are accessed in the current class (less is better).

Disabled
Complex function should be refactored

Reports the functions or methods that are too complex.

Complexity is evaluated based on four metrics:

  • Lines of code — the number of code lines in a function/method (less is better)

  • Maximum Nesting depth — the maximum number of nested statements in a function/method body (less is better)

  • Cyclomatic complexity — the function/method cyclomatic complexity (less is better)

  • Number of variables — the number of variables used in function/method body

Disabled
Function has too high cyclomatic complexity

Reports the methods that have high cyclomatic complexity and can probably be simplified.

See Cyclomatic complexity (wikipedia.org) for details.

Disabled
Halstead metric

Reports the methods with high Halstead Complexity metric.

See Halstead measure (wikipedia.org) for details.

Disabled
LCOM metric

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)

Disabled
Member can be pulled up

Reports the class methods and properties that should be pulled up to the parent class or interface.

Disabled
Method has Feature Envy on another class

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.

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
PHPDoc comment matches function/method signature

Reports the parameters' names and types in a PHPDoc comment that do not match 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.

The exception classes added to the Unchecked Exceptions list under Settings/Preferences | PHP | Analysis are excluded from the inspection scope.

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
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 Weak warning
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 the properties' types in PHPDoc @var tags that do not match the declared type of a property.

Weak Warning Weak warning
Last modified: 15 September 2021