PHPackages                             skybluesofa/chainable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. skybluesofa/chainable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

skybluesofa/chainable
=====================

Allow for chainable, fluent method calls

v0.1.0(9y ago)01752MITPHPPHP &gt;=5.6.0

Since Oct 3Pushed 9y ago1 watchersCompare

[ Source](https://github.com/skybluesofa/chainable)[ Packagist](https://packagist.org/packages/skybluesofa/chainable)[ Docs](https://github.com/skybluesofa/chainable)[ RSS](/packages/skybluesofa-chainable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/7f2fb3e28dc8929fed836e937656bd9e653a5a85b7701daee02f7a9a4b3ca7ff/68747470733a2f2f7472617669732d63692e6f72672f736b79626c7565736f66612f636861696e61626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/skybluesofa/chainable) [![Code Climate](https://camo.githubusercontent.com/6b21e24654bc5cfdbd9f28cc5b73ab07232744d916824bec30469e823a27075c/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f736b79626c7565736f66612f636861696e61626c652f6261646765732f6770612e737667)](https://codeclimate.com/github/skybluesofa/chainable) [![Test Coverage](https://camo.githubusercontent.com/0c9b60ec291a8ab95456cc91fc47d1da3c78f3a706ddd445254c9a90bd154b87/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f736b79626c7565736f66612f636861696e61626c652f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/skybluesofa/chainable/coverage) [![Total Downloads](https://camo.githubusercontent.com/ee30125f646cb6b56ea797116178a85f30507842c9b9ad2eec44ec3e9d2c34e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736b79626c7565736f66612f636861696e61626c652e7376673f7374796c653d666c6174)](https://packagist.org/packages/skybluesofa/chainable) [![Version](https://camo.githubusercontent.com/dd022743f0dab56e0df2145b1a20f3c0fcc4f9e265ea37ed803d8badc8b65a72/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736b79626c7565736f66612f636861696e61626c652e7376673f7374796c653d666c6174)](https://packagist.org/packages/skybluesofa/chainable) [![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE)

Chainable
=========

[](#chainable)

Allow for chainable, fluent method calls

Chaining Methods
----------------

[](#chaining-methods)

Check out the \[Tests/Sandwich(\] class. It gives a bunch of uses for the Chainable trait.

Basic use of this trait:

- Set the visibility for the chainable functions to 'private'
- Ensure that you either modify the current class or return a cloned version of the class
- Ensure that you return a reference to the class

```
private function withBread($breadType=null) {
  $this->breadType = $breadType;
  return $this;
}

```

### Calling fluent methods

[](#calling-fluent-methods)

Now you can call these methods fluently:

```
Sandwich::withBread('white')->
  addCondiment('peanut butter')->
  addCondiment('jelly')->
  make();

```

or the same sandwich, but the methods are called in a different order:

```
Sandwich::addCondiment('peanut butter')->
  withBread('white')->
  addCondiment('jelly')->
  make();

```

### Modifying the output

[](#modifying-the-output)

Any time up until you return something other than a reference to the chained class, you can modify what will be output:

```
Sandwich::withBread('wheat')->
  addCondiment('peanut butter')->
  addCondiment('grape jelly')->
  withBread('white')->
  removeCondiment('grape jelly')->
  addCondiment('strawberry jelly')->
  make();

```

### Missing methods

[](#missing-methods)

This will return an exception, as the 'addBananas' method does not exist.

```
Sandwich::withBread('white')->
  addCondiment('peanut butter')->
  addBananas()->
  make();

```

### Public methods

[](#public-methods)

This will return an error, as the 'addVegetable' method is not static:

```
Sandwich::addVegetable('lettuce')->
  withBread('white')->
  make();

```

To work around this, use the 'chainableProxy' method before calling 'addVegetable':

```
Sandwich::chainableProxy()->
  addVegetable('lettuce')->
  withBread('white')->
  make();

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3509d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/60324d72e7a3c7dea85699215cb194d3962647df1e860ae0ec1c6d53858e9a9b?d=identicon)[skybluesofa](/maintainers/skybluesofa)

---

Top Contributors

[![skybluesofa](https://avatars.githubusercontent.com/u/1657128?v=4)](https://github.com/skybluesofa "skybluesofa (16 commits)")[![jmauerhan](https://avatars.githubusercontent.com/u/4204262?v=4)](https://github.com/jmauerhan "jmauerhan (5 commits)")

---

Tags

objectfluentmethodchainablemethod\_exists

### Embed Badge

![Health badge](/badges/skybluesofa-chainable/health.svg)

```
[![Health](https://phpackages.com/badges/skybluesofa-chainable/health.svg)](https://phpackages.com/packages/skybluesofa-chainable)
```

###  Alternatives

[myclabs/deep-copy

Create deep copies (clones) of your objects

8.9k849.8M169](/packages/myclabs-deep-copy)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
