1.2.136. Class Has Fluent Interface

Mark a class as such when it contains at least one fluent method. A fluent method is a method that returns $this, for chaining.

<?php

class foo {
    private $count = 0;

    function a() {
        ++$this->count;
        return $this;
    }

    function b() {
        $this->count += 2;
        return $this;
    }

    function c() {
        return $this->count;
    }
}

$bar = new foo();
print $bar->a()
          ->b()
          ->c();

// display 3 (1 + 2).

?>

See also Fluent interface are evil, The basics of Fluent interfaces in PHP and FluentInterface.

1.2.136.1. Specs

Short name

Classes/HasFluentInterface

Rulesets

All

Exakat since

0.8.4

PHP Version

All

Severity

Time To Fix

Precision

High

Features

fluent-interface

Available in

Entreprise Edition, Exakat Cloud