1.2.433. Exceeding Typehint

The typehint is not fully used in the method. Some of the defined methods in the typehint are unused. A tighter typehint could be used, to avoid method pollution. Tight typehint prevents the argument from doing too much. They also require more maintenance : creation of dedicated interfaces, method management to keep all typehint tight.

<?php

interface i {
    function i1();
    function i2();
}

interface j {
    function j1();
    function j2();
}

function foo(i $a, j $b) {
    // the i typehint is totally used
    $a->i1();
    $a->i2();

    // the i typehint is not totally used : j2() is not used.
    $b->j1();
}

?>

See also Insufficient Typehint.

1.2.433.1. Connex PHP features

1.2.433.1.1. Suggestions

  • Keep the typehint tight, do not inject more than needed.

1.2.433.1.2. Specs

Short name

Functions/ExceedingTypehint

Rulesets

All, Changed Behavior, Class Review

Exakat since

2.0.3

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud