PHP

PHP

Made by DeepSource
Function with cyclomatic complexity higher than threshold found PHP-R1006
Anti-pattern
Minor

A function with high cyclomatic complexity can be hard to understand and maintain. Cyclomatic complexity is a software metric that measures the number of independent paths through a function. A higher cyclomatic complexity indicates that the function has more decision points and is more complex.

Unused constructor parameter PHP-W1037
Anti-pattern
Major

The constructor signature contains one or more unused parameters. Since these are nowhere used in the class, it can be safely removed.

Bad argument passed to isset PHP-W1040
Anti-pattern
Major

isset is either used with an undefined variable or a variable that is known to be defined and non-null.

Empty block of code found PHP-W1085
Anti-pattern
Major
Autofix

An empty block is considered as dead code as it doesn't do anything. The issue is raised when loops, conditionals, or other statements contains empty body which implies some piece of code is missing.

It is advised to remove the empty block since keeping them in the codebase wastes computation time and memory.

Unused variable in the closure use PHP-W1039
Anti-pattern
Major

One or more variables mentioned in the closure's use clause are unused. It is recommended to remove them from the use clause.

Dead code found after return PHP-W1074
Anti-pattern
Major
Autofix

The return keyword ends the function execution. If return is used outside of a function, it stops PHP code in the file from running. Therefore, any code after return is considered as dead code as it won't be executed ever and can be safely removed.

Unused private class property found PHP-W1075
Anti-pattern
Minor
Autofix

The class contains unused private property. These private class properties should be removed as they can sometimes lead to confusion while reading the code.

It is also recommended that you review these unused private properties, in case they were added for later use in the code, but the author missed using them.

Unused private class method found PHP-W1076
Anti-pattern
Minor
Autofix

The class contains unused private methods. These private class methods are dead code, and do nothing. It is recommended to remove these unused private methods.

It is also recommended that you review these unused private methods if they were added for later use in the code, but the author missed using them.

Parameter with a default value is not last PHP-W1079
Anti-pattern
Major

Parameters having a default value should always come last after the non-default parameters. Default parameters are optional during function calls. This means, if an argument is not provided for the parameter, the default value defined for the parameter would be used.

Declaring default parameters before non-default parameters defies this purpose since in that case, you have to pass a value for it, even if you want to use the default value. This is just because of the non-default values that are defined after them.

Therefore, it is strongly advised to place the default parameters after the non-default ones.

Empty function/method found PHP-W1080
Anti-pattern
Major

An empty function or method is considered as dead code, and removing it from the codebase wouldn't make any difference to the application's logic. This might even confuse the developer in the future, questioning the existence and use of the code block. If the code block is not necessary, it is highly recommended it remove it. This would also improve the code readability.

In case it is left empty intentionally, or you are planning to implement it in the future, please consider adding a comment stating the reason why it has been left empty. DeepSource won't raise an issue if there's a comment for the empty function/method.

final keyword is redundant PHP-W1082
Anti-pattern
Major
Autofix

The final keyword prevents child classes from overriding methods or constants with the final prefix. Here, the class is already defined as final; therefore, prefixing the class methods or the constants with final is redundant and safely be dropped.

string casting in concatenation is redundant PHP-W1087
Anti-pattern
Major

When concatenating string with concatenation operator, implicitly casting a value to string type is not necessary. All types are by default casted to string.

Use of nested switch statements found PHP-W1091
Anti-pattern
Major

Nested switch statements are difficult to understand and affect code readability. In addition, it is considered a code smell since they are harder to maintain and can easily be confused with the outer switch statement. Therefore it is recommended to avoid using nested switch statements or consider moving the inner switch to another function/method.