PHPackages                             denismitr/enum - 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. denismitr/enum

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

denismitr/enum
==============

PHP Enum

v1.0(5y ago)11MITPHPPHP ^7.2CI failing

Since Jul 15Pushed 5y ago1 watchersCompare

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

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

PHP ENUMS
=========

[](#php-enums)

Install
-------

[](#install)

`composer require denismitr/enum`

Examples
--------

[](#examples)

### Create your enum

[](#create-your-enum)

```
use Denismitr\Enum\Enum;
/**
 * @method static OrderStatus PENDING
 * @method static OrderStatus COMPLETED
 * @method static OrderStatus CANCELED
 * @method static OrderStatus BEING_DELIVERED
 *
 * @method bool isPending()
 * @method bool isCompleted()
 * @method bool isCanceled()
 * @method bool isBeingDelivered()
 */
class OrderStatus extends Enum
{
    protected static function states(): array
    {
        return [
            'PENDING' => 1,
            'COMPLETED' => 2,
            'CANCELED' => 3,
            'BEING_DELIVERED' => 4,
        ];
    }
}
```

### Instantiate and use it

[](#instantiate-and-use-it)

```
$pending = OrderStatus::PENDING();

$this->assertInstanceOf(OrderStatus::class, $pending);
$this->assertEquals(1, $pending->value());
$this->assertEquals('PENDING', $pending->key());
$this->assertTrue($pending->isPending());
$this->assertFalse($pending->isCanceled());
```

### Instantiate from key

[](#instantiate-from-key)

```
$beingDelivered = OrderStatus::fromKey('BEING_DELIVERED');
```

### Instantiate from key

[](#instantiate-from-key-1)

```
$completed = OrderStatus::fromValue(2);
```

### Enumerate all

[](#enumerate-all)

```
OrderStatus::enumerate();
// [
//    'PENDING' => 1,
//    'COMPLETED' => 2,
//    'CANCELED' => 3,
//    'BEING_DELIVERED' => 4,
// ];
```

### Validate values and keys

[](#validate-values-and-keys)

```
OrderStatus::isValidKey('PENDING'); // true
OrderStatus::isValidValue(1); // true

OrderStatus::isValidKey('FOO'); // false
OrderStatus::isValidValue(5); // false
```

### Extract keys or values

[](#extract-keys-or-values)

```
// all keys
OrderStatus::keys(); // ['PENDING', 'COMPLETED', 'CANCELED', 'BEING_DELIVERED']
// all keys except except PENDING and CANCELED
OrderStatus::keys(OrderStatus::PENDING(), OrderStatus::CANCELED()); // ['COMPLETED', 'BEING_DELIVERED']

// all values
OrderStatus::values(); // [1,2,3,4]
// all values except PENDING and CANCELED
OrderStatus::values(OrderStatus::PENDING(), OrderStatus::CANCELED()); // [2,4]
```

Non associative states
----------------------

[](#non-associative-states)

```
/**
 * @method static IOTA PENDING
 * @method static IOTA READY
 * @method static IOTA FAILED
 *
 * @method bool isPending()
 * @method bool isReady()
 * @method bool isFailed()
 */
class Iota extends Enum
{
    protected static function states(): array
    {
        return ['PENDING', 'READY', 'FAILED'];
    }
}

$ready = Iota::READY();
$this->assertEquals(1, $ready->value());
$this->assertEquals('READY', $ready->key());

$pending = Iota::PENDING();
$this->assertEquals(0, $pending->value());
$this->assertEquals('PENDING', $pending->key());

$failed = Iota::FAILED();
$this->assertEquals(2, $failed->value());
$this->assertEquals('FAILED', $failed->key());

$this->assertEquals([
    'PENDING' => 0,
    'READY' => 1,
    'FAILED' => 2,
], Iota::enumerate());
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Total

2

Last Release

2082d ago

Major Versions

v0.1.0 → v1.02020-09-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d68ae5d5ca94f49a69f961a7825865d92247b09e276a25fcc6ad485d4c8c964?d=identicon)[denismitr](/maintainers/denismitr)

---

Top Contributors

[![denismitr](https://avatars.githubusercontent.com/u/16356446?v=4)](https://github.com/denismitr "denismitr (10 commits)")

---

Tags

enumenumerableenums

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/denismitr-enum/health.svg)

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

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

2.7k227.9M637](/packages/myclabs-php-enum)[spatie/enum

PHP Enums

84529.1M68](/packages/spatie-enum)[dasprid/enum

PHP 7.1 enum implementation

382146.0M11](/packages/dasprid-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49644.8M97](/packages/marc-mabe-php-enum)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[timeweb/phpstan-enum

Enum class reflection extension for PHPStan

443.2M21](/packages/timeweb-phpstan-enum)

PHPackages © 2026

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