1.2.679. Method Is Not For Fluent Interface

Mark a method when it contains at least one return that doesn’t return $this. Such method cannot be used for fluent interface, which always require the current object to be returned.

Null is not accepted here: it would break the execution of the method call chains if it was returned.

<?php

class x {
     // fluent interface : $this is chainable
     function foo() {
             return $this;
     }

     // Not for fluent interface : the method may return something else
     function goo($a) {
             if ($a == true) {
                     return $this;
             } else {
                     return 3;
             }
     }
}

?>

1.2.679.1. Specs

Short name

Functions/HasNotFluentInterface

Rulesets

All, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Time To Fix

Precision

Very high

Features

method, fluent-interface

Available in

Entreprise Edition, Exakat Cloud