PHPackages                             dive-be/php-enum-utils - 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. dive-be/php-enum-utils

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

dive-be/php-enum-utils
======================

Those utilities you always need when dealing with native enumerations.

1.5.0(4mo ago)31297.6k↓21.1%1MITPHPPHP ~8.5CI passing

Since May 7Pushed 4mo agoCompare

[ Source](https://github.com/dive-be/php-enum-utils)[ Packagist](https://packagist.org/packages/dive-be/php-enum-utils)[ Docs](https://github.com/dive-be/php-enum-utils)[ RSS](/packages/dive-be-php-enum-utils/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (7)Dependencies (1)Versions (8)Used By (1)

🛠 Native enum utilities you always need
=======================================

[](#-native-enum-utilities-you-always-need)

[![Latest Version on Packagist](https://camo.githubusercontent.com/59e1719c01b904327c9ec06379d24d30eb02ef3562d2a006a9462f186de18329/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646976652d62652f7068702d656e756d2d7574696c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dive-be/php-enum-utils)

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

- [Arrayable](#arrayable-backed-enums-only)
- [Assertable](#assertable)
- [Comparable](#comparable)
- [NameListable](#namelistable)
- [ValueListable](#valuelistable-backed-enums-only)
- [WithUtilities](#withutilities-backed-enums-only)

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

[](#installation)

You can install the package via composer:

```
composer require dive-be/php-enum-utils
```

Usage
-----

[](#usage)

Assume the following `string` backed enum:

```
enum Role: string
{
    use \Dive\Enum\Arrayable;
    use \Dive\Enum\Assertable;
    use \Dive\Enum\Comparable;
    use \Dive\Enum\NameListable;
    use \Dive\Enum\ValueListable;

    case Administrator = 'admin';
    case Auditor = 'audit';
    case Moderator = 'mod';
}
```

### Arrayable (backed enums only)

[](#arrayable-backed-enums-only)

Allows you to retrieve a key-value pair of names and values:

```
Role::toArray(); // ['Administrator' => 'admin', 'Auditor' => 'audit', 'Moderator' => 'mod']
```

### Assertable

[](#assertable)

> This relies on the enum names being in PascalCase, which follows [Larry Garfield's RFC](https://wiki.php.net/rfc/enumerations).

Allows you to make assertions on enum instances using predicate functions:

```
$role = Role::Moderator;

$role->isAuditor(); // false
$role->isModerator(); // true
```

### Comparable

[](#comparable)

Allows you to compare enums. Mostly useful when providing backed values:

```
$role = Role::Administrator;

$role->equals('admin'); // true
$role->equals(Role::Administrator); // true
$role->equals('mod'); // false
$role->equals(Role::Moderator); // false

$role->equalsAny(['admin', 'mod', 'audit']); // true
$role->equalsAny([Role::Administrator, Role::Auditor]); // true
$role->equalsAny([Role::Moderator, 'audit']); // false
```

### NameListable

[](#namelistable)

Allows you to retrieve a list of the enum names:

```
Role::toNames(); // ['Administrator', 'Auditor', 'Moderator']
```

### ValueListable (backed enums only)

[](#valuelistable-backed-enums-only)

Allows you to retrieve a list of the enum values:

```
Role::toValues(); // ['admin', 'audit', 'mod']
```

### WithUtilities (backed enums only)

[](#withutilities-backed-enums-only)

Aggregator trait for all of the aforementioned utilities.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Muhammed Sari](https://github.com/mabdullahsari)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance75

Regular maintenance activity

Popularity43

Moderate usage in the ecosystem

Community8

Small or concentrated contributor base

Maturity71

Established project with proven stability

 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 ~226 days

Recently: every ~250 days

Total

7

Last Release

137d ago

PHP version history (4 changes)1.0.0PHP ^8.1

1.3.0PHP ~8.3

1.4.0PHP ~8.4

1.5.0PHP ~8.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/59749?v=4)[Artem Loenko](/maintainers/dive)[@dive](https://github.com/dive)

---

Top Contributors

[![mabdullahsari](https://avatars.githubusercontent.com/u/24608797?v=4)](https://github.com/mabdullahsari "mabdullahsari (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dive-be-php-enum-utils/health.svg)

```
[![Health](https://phpackages.com/badges/dive-be-php-enum-utils/health.svg)](https://phpackages.com/packages/dive-be-php-enum-utils)
```

###  Alternatives

[firegento/magesetup2

MageSetup provides the necessary configuration (system config, tax, agreements, etc. for a national market.

121340.5k1](/packages/firegento-magesetup2)[sixlive/nova-text-copy-field

Laravel Nova text field with click to copy support

69717.8k2](/packages/sixlive-nova-text-copy-field)

PHPackages © 2026

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