1.2.1387. Useless Interfaces

The interfaces below are defined and are implemented by some classes.

However, they are never used to enforce an object’s class in the code, using instanceof or in a type. As they are currently used, those interfaces may be removed without change in behavior. Interfaces should be used in type or with the instanceof operator.

<?php
    // only defined interface but never enforced
    interface i {};
    class c implements i {}
?>

1.2.1387.1. Suggestions

  • Use the interface with instanceof, or a type

  • Drop the interface altogether : both definition and implements keyword

1.2.1387.2. Specs

Short name

Interfaces/UselessInterfaces

Rulesets

All, Analyze, Changed Behavior, Class Review, Typechecks

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

interface

ClearPHP

no-useless-interfaces

Examples

Woocommerce

Available in

Entreprise Edition, Exakat Cloud