1.2.41. 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.41.1. Suggestions

  • Add the typehint to the function arguments

1.2.41.2. Specs

Short name

Functions/ShouldBeTypehinted

Rulesets

All, Typechecks

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

Very high

Features

typehint

ClearPHP

always-typehint

Examples

Dolphin, Mautic

Available in

Entreprise Edition, Exakat Cloud