Inspectopedia 2024.3 Help

Code style

'Closure::fromCallable()' can be converted to the first-class callable syntax   New in this release

Reports the callable creation expressions that use Closure::fromCallable but can be replaced with first-class callable syntax f(...) available since PHP 8.1.

'array_all()' call can be converted to a loop   New in this release

Reports the array_all() calls that can be replaced with foreach loops in PHP 8.4 and later.

'array_any()' call can be converted to a loop   New in this release

Reports the array_any() calls that can be replaced with foreach loops in PHP 8.4 and later.

'array_fill' can be converted to loop   New in this release

Reports the array_fill() calls that can be replaced with foreach loops.

'array_filter()' call can be converted to loop   New in this release

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

'array_find()' call can be converted to a loop   New in this release

Reports the array_find() calls that can be replaced with foreach loops in PHP 8.4 and later.

'array_find_key()' call can be converted to a loop   New in this release

Reports the array_find_key() calls that can be replaced with foreach loops in PHP 8.4 and later.

'array_map()' call can be converted to loop   New in this release

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

'get_class()' call can be replaced with '::class'   New in this release

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

'if' can be replaced with 'match' expression   New in this release

Reports the if statements inside if-elseif-else constructs that use strict comparisons (===) and could be replaced with match expressions.

'instanceof' checks in 'catch' block can be replaced with specific catches   New in this release

Reports the instanceof checks in single catch blocks that could be replaced with multiple catch blocks specific for each exception instance.

'isset' can be replaced with coalesce   New in this release

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

'isset' can check nested array access and sub properties directly   New in this release

Reports constructions like isset($a['a']) && isset($a['a']['b']) && isset($b) && isset($b->b) that can be replaced with isset($a['a']['b']) && isset($b->b).

'json_decode()' and 'json_last_error()' can be converted to 'json_validate()'   New in this release

In PHP 8.3 and later, suggests converting `json_decode()` and `json_last_error() === JSON_ERROR_NONE` to `json_validate()`.

'match' can be replaced with 'switch' statement   New in this release

Reports the match expressions that can be replaced with switch statements.

'match' expression can be replace with ternary expression   New in this release

Reports the match expressions containing a default arm and a single non-default arm.

'mixed' return type can be narrowed   New in this release

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

'mixed' type can be replaced with 'array'   New in this release

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

'pow()' call can be replaced with '**' operator   New in this release

Reports the pow() calls that can be replaced with the ** operator, which adds no overhead of calling a function.

'readonly' modifier is redundant   New in this release

Reports readonly modifiers applied to properties in read-only classes.

'str*()' calls can be replaced with PHP 8 'str_*()' calls   New in this release

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

'switch' can be replaced with 'match' expression   New in this release

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

Automatic conversion of 'false' to array is deprecated   New in this release

Reports automatic conversions of false values to arrays.

Case mismatch in method call or class usage   New in this release

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

Class can be 'readonly'   New in this release

Reports the classes which contain only readonly properties and can have the readonly modifier added to them.

Class constant can be 'final'   New in this release

Reports the non-final class constants that are not redefined in child classes.

Class path doesn't match project structure   New in this release

Reports the classes with the filepath not following the PSR-0/PSR-4 project structure.

Closure can be converted to arrow function   New in this release

Reports the anonymous functions and property hooks that can be transformed to short arrow functions.

Comment can be replaced with named argument   New in this release

Reports the inline comments before arguments in function calls that only contain the name of the parameter and thus serve as hints.

Control statement body without braces   New in this release

Reports the control structures (such as loops or conditionals) whose bodies are not enclosed in braces.

Dangerous array initialization   New in this release

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

Define constant name can be replaced with 'const' syntax   New in this release

Reports the define() calls that can be replaced with const syntax.

Expression without clarifying parentheses   New in this release

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

Fully qualified name usage   New in this release

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

Implicit octal literal can be replaced with explicit one   New in this release

Reports the implicit octal literals such as 071 that could be replaced with explicit ones such as 0o71.

Loop can be converted to 'array_fill()' call   New in this release

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

Loop can be converted to 'array_filter()' call   New in this release

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

Loop can be converted to 'array_map()' call   New in this release

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

Loop can be converted to an 'array_all()' call   New in this release

Reports the foreach loops that can be replaced with array_all() calls in PHP 8.4 and later.

Loop can be converted to an 'array_any()' call   New in this release

Reports the foreach loops that can be replaced with array_any() calls in PHP 8.4 and later.

Loop can be converted to an 'array_find()' call   New in this release

Reports the foreach loops that can be replaced with array_find() calls in PHP 8.4 and later.

Loop can be converted to an 'array_find_key()' call   New in this release

Reports the foreach loops that can be replaced with array_find_key() calls in PHP 8.4 and later.

Method can be made 'static'  

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

Multiple 'isset' calls can be replaced with one   New in this release

Reports multiple isset() checks that can be replaced with a single one.

Multiple classes declarations in one file   New in this release

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

Named arguments order does not match parameters order   New in this release

Reports named argument with order that does not match parameter order.

Nullsafe operator '?->' can be used   New in this release

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

Old style constructor   New in this release

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

Open 'echo' tag usage   New in this release

Reports the <?php echo usages that can be replaced with a short tag <?=.

Parentheses around the 'new' call can be omitted   New in this release

Reports parentheses around the new expression in statements with class member access on instantiation, e.g.

Redundant closing tag  

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

Short open 'echo' tag usage   New in this release

Reports short PHP echo tag <?= usages.

Short open tag usage   New in this release

Reports short PHP opening tag <? usages.

Single-statement body with braces   New in this release

Reports the control structures (such as loops or conditionals) whose bodies are enclosed in braces but only contain a single child statement.

Traditional syntax array literal detected   New in this release

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

Trait usage is not allowed   New in this release

Reports the class references that are resolved to traits but are specified outside use statements.

Trait use rule resolved to method with different containing class   New in this release

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.

Type cast is unnecessary   New in this release

Reports the type cast operators used on the values that are already of the corresponding type.

Type cast on a scalar value   New in this release

Reports the type casts that can be evaluated in place and suggests replacing them with actual computed values.

Type hint 'array|Traversable' can be replaced with 'iterable'   New in this release

Reports the array|Traversable type hints that can be replaced with iterable.

Unnecessary curly braces syntax for variable   New in this release

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

Unnecessary double quotes   New in this release

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

Unnecessary fully qualified name   New in this release

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

Unnecessary leading '\' in 'use' statement   New in this release

Reports the use statements with an unnecessary leading \.

Unnecessary parentheses  

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

Usage of a variable variable   New in this release

Reports the usages of variable variables (dynamic variable names such as $$a).

Variable is only used inside closure   New in this release

Reports variables in closures' use list that are only used inside closure.

PSR-12  

Sub-group of 8 inspections that provide checks for PSR-12

Last modified: 03 December 2024