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

Abandoned → [premier/enum](/?search=premier%2Fenum)Library[Utility &amp; Helpers](/categories/utility)

grachevko/enum
==============

PHP Enum implementation

2.2(4y ago)54.8kMITPHPPHP &gt;=7.3

Since Feb 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/grachevko/Enum)[ Packagist](https://packagist.org/packages/grachevko/enum)[ RSS](/packages/grachevko-enum/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (8)Versions (31)Used By (0)

PHP Enum implementation
=======================

[](#php-enum-implementation)

[![Latest Stable Version](https://camo.githubusercontent.com/a8d1f998e653d3276b17d29ec4697227ceb4fb2d2e02d295303b149897d9f3de/68747470733a2f2f706f7365722e707567782e6f72672f7072656d6965722f656e756d2f762f737461626c65)](https://packagist.org/packages/premier/enum)[![Total Downloads](https://camo.githubusercontent.com/a917d03b81601b62c0a3cd5c2fe6b6dee4d108c3da43cb33449aa4e13b6ccbf5/68747470733a2f2f706f7365722e707567782e6f72672f7072656d6965722f656e756d2f646f776e6c6f616473)](https://packagist.org/packages/premier/enum)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b1b6f14e2a89c3b163ac2ff24116308898336e3d99c2b3e023f18343f1be8648/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f677261636865766b6f2f456e756d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/grachevko/Enum/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/20bd108d740253def34712728038aa2aa8fb4ebd8228b9a4517d5c28a668623d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f677261636865766b6f2f456e756d2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/grachevko/Enum/?branch=master)[![Build Status](https://camo.githubusercontent.com/cdebd2826d2bba017cb7e7a1f5ea437d4a90d3ccbe62c77df4a1f626b7153ab1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f677261636865766b6f2f456e756d2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/grachevko/Enum/build-status/master)[![SensioLabsInsight](https://camo.githubusercontent.com/f5bcbd81c82a441b3286cb02a3156b0a4e9682bd5c595061368a14a9e198f8ad/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f39626330666531622d386231302d343462392d396137312d3538313963653763636165662f6269672e706e67)](https://insight.sensiolabs.com/projects/9bc0fe1b-8b10-44b9-9a71-5819ce7ccaef)

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

[](#installation)

```
composer require premier/enum

```

Usage
-----

[](#usage)

```
namespace Premier\Enum;

/**
 * @method static DriveWheel front()
 * @method static DriveWheel rear()
 * @method static DriveWheel allDrive()
 * @method static DriveWheel fromCode(string $code)
 * @method bool   isFront()
 * @method bool   isRear()
 * @method bool   isAllDrive()
 * @method string toCode()
 */
final class DriveWheel extends Enum
{
    private const FRONT = 1;
    private const REAR = 2;
    private const ALL_DRIVE = 3;

    protected static $code = [
        self::FRONT => 'FWD',
        self::REAR => 'RWD',
        self::ALL_DRIVE => 'AWD',
    ];
}

// New instance
$drive = DriveWheel::create(1);
// or
$drive = DriveWheel::front();
// or
$drive = DriveWheel::fromCode('FWD');
// or
$drive = DriveWheel::from('code', 'FWD');

// Array instances
DriveWheel::all(); // [DriveWheel::front(), DriveWheel::rear(), DriveWheel::allDrive()]
DriveWheel::all(['FWD', 'RWD'], $reverse = false, $property = 'code'); // [DriveWheel::front(), DriveWheel::rear()]
DriveWheel::all([1, 2], $reverse = true); // [DriveWheel::allDrive()]

// Methods
$drive->toId();    // 1
$drive->to('id');  // 1
(string) $drive;   // '1'

$drive->toName(); // 'front'

$drive->toCode();   // 'FWD'
$drive->to('code'); // 'FWD'

$drive->isFront(); // true
$drive->isRear();  // false

$drive->eq(DriveWheel::front()); // false
$drive->eq(DriveWheel::rear());  // false
```

Design
------

[](#design)

- All constants MUST be private
- All constants MUST be type of integer
- All properties MUST NOT be public
- All properties MUST be static
- Properties MUST contain values for all defined constants

Doctrine
--------

[](#doctrine)

This lib distributed with Type class for Doctrine to easy configure each Enum as Doctrine Type.

```
Premier\Enum\Doctrine\EnumType::register(Premier\Enum\Gender::class, 'gender_enum', $property = 'id');

class Entity
{
    /**
    * @var Gender
    *
    * @ORM\Column(type="gender_enum")
    */
    public $gender;
}
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

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

Recently: every ~202 days

Total

30

Last Release

1561d ago

Major Versions

v0.14.3 → v1.02019-10-28

v1.4 → v2.0.02019-12-19

PHP version history (3 changes)0.1PHP &gt;=7

0.3PHP &gt;=7.1

v0.14PHP &gt;=7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8628465?v=4)[Konstantin Grachev](/maintainers/grachevko)[@grachevko](https://github.com/grachevko)

---

Top Contributors

[![grachevko](https://avatars.githubusercontent.com/u/8628465?v=4)](https://github.com/grachevko "grachevko (90 commits)")

---

Tags

doctrine-enumenumphpenum

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[myclabs/php-enum

PHP Enum implementation

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

PHP 7.1 enum implementation

379146.0M11](/packages/dasprid-enum)[spatie/enum

PHP Enums

84429.1M68](/packages/spatie-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

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

Laravel Enum support

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

Consistence - consistent approach and additions to PHP's functionality

1831.1M18](/packages/consistence-consistence)

PHPackages © 2026

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