1.2.42. Argument Should Be Typehinted¶
When a method expects objects as argument, those arguments should be typehinted. This way, it provides early warning that a wrong object is being sent to the method.
The analyzer will detect situations where a class, or the keywords ‘array’ or ‘callable’. Closure <https://www.php.net/manual/en/class.`closure.php>`_ arguments are omitted.
<?php
// What are the possible classes that have a 'foo' method?
function foo($bar) {
return $bar->foo();
}
?>
See also Type declarations.
1.2.42.1. Connex PHP features¶
1.2.42.1.1. Suggestions¶
Add the typehint to the function arguments
1.2.42.1.2. Specs¶
Short name |
Functions/ShouldBeTypehinted |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
ClearPHP |
|
Examples |
|
Available in |