1.2.766. Never Called Parameter¶
This analysis reports when a parameter is never used at calltime.
Such parameter has a default value, and always falls back to it. As such, it may be turned into a local variable.
A never called parameter is often planned for future use, though, so far, the code base doesn’t make use of it. It also happens that the code use it, but is not part of the analyzed code base, such as a plugin system.
This issue is silent: it doesn’t yield any error. It is also difficult to identify, as it requires checking all the usage of the method.
This analysis checks for actual usage of the parameter, from the outside of the method. This is different from checking if the parameter is used inside the method.
<?php
// $b may be turned into a local var, it is unused
function foo($a, $b = 1) {
return $a + $b;
}
// whenever foo is called, the 2nd arg is not mentioned
foo($a);
foo(3);
foo('a');
foo($c);
?>
See also Unused Parameter, Cancelled Parameter and Parameter Hiding.
1.2.766.1. Connex PHP features¶
1.2.766.1.1. Suggestions¶
Drop the unused argument in the method definition
Actually use the argument when calling the method
Drop the default value, and check warnings that mention usage of this parameter
1.2.766.1.2. Specs¶
Short name |
Functions/NeverUsedParameter |
Rulesets |
|
Exakat since |
1.0.6 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
High |
Examples |
|
Related rule |
|
Available in |