1.2.676. Method Has Fluent Interface

Mark a method when it only returns $this.

Fluent interfaces allows for chaining methods calls. This implies that $this is always returned, so that the next method call is done on the same object.

<?php

$object = new foo();
$object->this()
       ->is()
       ->a()
       ->fluent()
       ->interface();

class foo {
    function this() {
        // doSomething
        return $this;
    }

    function is() {
        // doSomethingElse
        return $this;
    }

    /// Etc. for a(), fluent(), interface()...
}

?>

See also Fluent Interfaces in PHP and Fluent Interfaces are Evil.

1.2.676.1. Specs

Short name

Functions/HasFluentInterface

Rulesets

All

Exakat since

0.8.4

PHP Version

All

Severity

Time To Fix

Precision

Very high

Features

class

Available in

Entreprise Edition, Exakat Cloud