use
PHP-W1039One or more variables mentioned in the closure's use
clause are unused.
It is recommended to remove them from the use
clause.
The constructor signature contains one or more unused parameters. Since these are nowhere used in the class, it can be safely removed.
isset
PHP-W1040isset
is either used with an undefined variable or a variable that is known to be defined and non-null.
return
PHP-W1074The 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.
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.
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.
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.
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.
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.
This issue is raised when a function is declared inside another function or method. The nested function is always created in the global scope and not in the enclosing function or method's scope.
This will also lead to a Fatal Error
during runtime if the enclosing function or method is called more than once.
This happens because the enclosed function is defined in the Global scope when the enclosing function is called the first time. On subsequent calls, PHP will find the enclosed function already defined and run into an error.
It is therefore recommended to refactor it to an anonymous function/closure, class method, or a top-level-defined function.
switch
statements found PHP-W1091Nested 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.
final
keyword is redundant PHP-W1082The 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-W1087When concatenating string with concatenation operator, implicitly casting a value to string
type is not necessary. All types are by default casted to string
.
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.