PHPackages                             decodelabs/enumerable - 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. decodelabs/enumerable

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

decodelabs/enumerable
=====================

Helper traits for enums

v0.2.8(10mo ago)111.7k5MITPHPPHP ^8.4CI passing

Since Jun 15Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/decodelabs/enumerable)[ Packagist](https://packagist.org/packages/decodelabs/enumerable)[ RSS](/packages/decodelabs-enumerable/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (16)Used By (5)

Enumerable
==========

[](#enumerable)

[![PHP from Packagist](https://camo.githubusercontent.com/4a60d0114602e1c89caa47348d6fb10f4ebb3333e3548fa9f5c47cde824c5dea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6465636f64656c6162732f656e756d657261626c653f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/enumerable)[![Latest Version](https://camo.githubusercontent.com/de1702e53452a74422bdada416b108d4204348e49ae2bcf0e6d60cdb15f716f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465636f64656c6162732f656e756d657261626c652e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/enumerable)[![Total Downloads](https://camo.githubusercontent.com/2d775574113307eec2caf166c05a7d666a828058a146ae37dc32254b94715fcc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465636f64656c6162732f656e756d657261626c652e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/enumerable)[![GitHub Workflow Status](https://camo.githubusercontent.com/c182bf82e1cc081bb05a2544c02ea22217ab75f65edb23db9ee45f23bb055ebd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6465636f64656c6162732f656e756d657261626c652f696e746567726174652e796d6c3f6272616e63683d646576656c6f70)](https://github.com/decodelabs/enumerable/actions/workflows/integrate.yml)[![PHPStan](https://camo.githubusercontent.com/e25c14ce011edabdd0fbd2e10415b41cc5d66ed11ef3e5b7edd074c5bdd35a2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d3434434331312e7376673f6c6f6e6743616368653d74727565267374796c653d666c6174)](https://github.com/phpstan/phpstan)[![License](https://camo.githubusercontent.com/6de224449262343a622a24710e324914111ef2231c88207b6a9c0a283ef55eec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465636f64656c6162732f656e756d657261626c653f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/enumerable)

### Helper traits for enums

[](#helper-traits-for-enums)

Enumerable provides a simple structure of interfaces and traits to unlock the full power of PHP enums.

---

Installation
------------

[](#installation)

This package requires PHP 8.4 or higher.

Install via Composer:

```
composer require decodelabs/enumerable
```

Usage
-----

[](#usage)

Enumerable defines a powerful top level Enum interface that expands the range of functionality enums provide whilst consolidating the same functionality across both `UnitEnum` and `BackedEnum` types.

All Enumerable enums implement a type specific interface and use an accompanying trait. Each form dictates a type for a `key`, `value` and `label` property, where the key is used as the index in lists and the label is used for display purposes.

Unit enums
----------

[](#unit-enums)

### Named UnitEnum

[](#named-unitenum)

```
use DecodeLabs\Enumerable\Unit\Named;
use DecodeLabs\Enumerable\Unit\NamedTrait;

enum MyNamedUnitEnum implements Named
{
    use NamedTrait;

    const OptionOne;
    const OptionTwo;
    const OptionThree;
}

MyNamedUnitEnum::OptionOne->getName();  // 'OptionOne'
MyNamedUnitEnum::OptionOne->getKey();   // 'OptionOne'
MyNamedUnitEnum::OptionOne->getLabel(); // 'Option One'
MyNamedUnitEnum::OptionOne->getValue(); // 'OptionOne'
```

### Indexed UnitEnum

[](#indexed-unitenum)

```
use DecodeLabs\Enumerable\Unit\Indexed;
use DecodeLabs\Enumerable\Unit\IndexedTrait;

enum MyIndexedUnitEnum implements Indexed
{
    use IndexedTrait;

    const OptionOne;
    const OptionTwo;
    const OptionThree;
}

MyNamedUnitEnum::OptionOne->getName();  // 'OptionOne'
MyNamedUnitEnum::OptionOne->getKey();   // 0
MyNamedUnitEnum::OptionOne->getLabel(); // 'Option One'
MyNamedUnitEnum::OptionOne->getValue(); // 'OptionOne'
```

Backed enums
------------

[](#backed-enums)

### Named String BackedEnum

[](#named-string-backedenum)

```
use DecodeLabs\Enumerable\Backed\NamedString;
use DecodeLabs\Enumerable\Backed\NamedStringTrait;

enum MyNamedStringBackedEnum : string implements NamedString
{
    use NamedStringTrait;

    const OptionOne = 'one';
    const OptionTwo = 'two';
    const OptionThree = 'three';
}

MyNamedStringBackedEnum::OptionOne->getName();  // 'OptionOne'
MyNamedStringBackedEnum::OptionOne->getKey();   // 'OptionOne'
MyNamedStringBackedEnum::OptionOne->getLabel(); // 'Option One'
MyNamedStringBackedEnum::OptionOne->getValue(); // 'one'
```

### Labelled String BackedEnum

[](#labelled-string-backedenum)

```
use DecodeLabs\Enumerable\Backed\LabelledString;
use DecodeLabs\Enumerable\Backed\LabelledStringTrait;

enum MyLabelledStringBackedEnum : string implements LabelledString
{
    use LabelledStringTrait;

    const OptionOne = 'one';
    const OptionTwo = 'two';
    const OptionThree = 'three';
}

MyLabelledStringBackedEnum::OptionOne->getName();  // 'OptionOne'
MyLabelledStringBackedEnum::OptionOne->getKey();   // 'OptionOne'
MyLabelledStringBackedEnum::OptionOne->getLabel(); // 'one'
MyLabelledStringBackedEnum::OptionOne->getValue(); // 'one'
```

### Value String BackedEnum

[](#value-string-backedenum)

```
use DecodeLabs\Enumerable\Backed\ValueString;
use DecodeLabs\Enumerable\Backed\ValueStringTrait;

enum MyValueStringBackedEnum : string implements ValueString
{
    use ValueStringTrait;

    const OptionOne = 'one';
    const OptionTwo = 'two';
    const OptionThree = 'three';
}

MyValueStringBackedEnum::OptionOne->getName();  // 'OptionOne'
MyValueStringBackedEnum::OptionOne->getKey();   // 'one'
MyValueStringBackedEnum::OptionOne->getLabel(); // 'Option One'
MyValueStringBackedEnum::OptionOne->getValue(); // 'one'
```

### Named Int BackedEnum

[](#named-int-backedenum)

```
use DecodeLabs\Enumerable\Backed\NamedInt;
use DecodeLabs\Enumerable\Backed\NamedIntTrait;

enum MyNamedIntBackedEnum : int implements NamedInt
{
    use NamedIntTrait;

    const OptionOne = 1;
    const OptionTwo = 2;
    const OptionThree = 3;
}

MyNamedIntBackedEnum::OptionOne->getName();  // 'OptionOne'
MyNamedIntBackedEnum::OptionOne->getKey();   // 'OptionOne'
MyNamedIntBackedEnum::OptionOne->getLabel(); // 'Option One'
MyNamedIntBackedEnum::OptionOne->getValue(); // 1
```

### Value Int BackedEnum

[](#value-int-backedenum)

```
use DecodeLabs\Enumerable\Backed\ValueInt;
use DecodeLabs\Enumerable\Backed\ValueIntTrait;

enum MyValueIntBackedEnum : int implements ValueInt
{
    use ValueIntTrait;

    const OptionOne = 1;
    const OptionTwo = 2;
    const OptionThree = 3;
}

MyValueIntBackedEnum::OptionOne->getName();  // 'OptionOne'
MyValueIntBackedEnum::OptionOne->getKey();   // 1
MyValueIntBackedEnum::OptionOne->getLabel(); // 'Option One'
MyValueIntBackedEnum::OptionOne->getValue(); // 1
```

Instantiation
-------------

[](#instantiation)

All enum types can be instantiaed with the following methods:

```
MyEnum::fromKey('');
MyEnum::fromValue('');
MyEnum::fromName('');
MyEnum::fromIndex('');
// or
MyEnum::tryFromKey('');
MyEnum::tryFromValue('');
MyEnum::tryFromName('');
MyEnum::tryFromIndex('');
```

Lists
-----

[](#lists)

Enumerable provides three main ways of listing cases:

```
// Key to label map
MyEnum::getOptions() => [
    '' => '',
];

// Key to value map
MyEnum::getValues() => [
    '' => '',
];

// Alias to cases()
MyEnum::getCases() => [
    '' => '[MyEnum::]',
];
```

Licensing
---------

[](#licensing)

Enumerable is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance64

Regular maintenance activity

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~30 days

Recently: every ~13 days

Total

14

Last Release

303d ago

PHP version history (2 changes)v0.1.0PHP ^8.1

v0.2.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a241d64d12b3b5ee94197862ec1ec30b82ed2efa34a0cd7f4c3565a021daddd?d=identicon)[betterthanclay](/maintainers/betterthanclay)

---

Top Contributors

[![betterthanclay](https://avatars.githubusercontent.com/u/1273586?v=4)](https://github.com/betterthanclay "betterthanclay (61 commits)")

---

Tags

enumlanguagephp

### Embed Badge

![Health badge](/badges/decodelabs-enumerable/health.svg)

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

PHPackages © 2026

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