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

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

commerceguys/enum
=================

A PHP 5.4+ enumeration library.

v1.0(11y ago)961.9M↓10.2%3[1 issues](https://github.com/commerceguys/enum/issues)[1 PRs](https://github.com/commerceguys/enum/pulls)7MITPHPPHP &gt;=5.4.0

Since Feb 27Pushed 10y ago6 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (7)

enum
====

[](#enum)

[![Build Status](https://camo.githubusercontent.com/92b49436cd6d04027c132ad9f70dfde8eb02d80722ff4b22465ca54884356a7b/68747470733a2f2f7472617669732d63692e6f72672f636f6d6d65726365677579732f656e756d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/commerceguys/enum)

A PHP 5.4+ enumeration library.

Class constants are frequently used to denote sets of allowed values. By grouping them in an enumeration class, we gain the ability to add helper methods, list all possible values and validate values against them.

A [commerceguys/addressing](https://github.com/commerceguys/addressing) example:

```
namespace CommerceGuys\Addressing\Enum;

use CommerceGuys\Enum\AbstractEnum;

/**
 * Enumerates available locality types.
 */
final class LocalityType extends AbstractEnum
{
    const CITY = 'city';
    const DISTRICT = 'district';

    // We can provide a getDefault() method here, or anything else.
}

LocalityType::getAll(); // ['CITY' => 'city', 'DISTRICT' => 'district']
LocalityType::getKey('city'); // 'CITY'
LocalityType::exists('city'); // true
LocalityType::assertExists('invalid value'); // InvalidArgumentException
LocalityType::assertAllExist(['district', 'invalid value']); // InvalidArgumentException
```

Meanwhile, on the AddressFormat:

```
// The AddressFormatInterface is now free of LOCALITY_TYPE_ constants.
class AdressFormat implements AddressFormatInterface
{
    public function setLocalityType($localityType)
    {
        LocalityType::assertExists($localityType);
        $this->localityType = $localityType;
    }
}
```

The reason why this library was made instead of reusing [myclabs/php-enum](https://github.com/myclabs/php-enum)was that we didn't want to allow enumerations to be instantiated.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

4098d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/621c34dbc1ad3ea00e09f6006aa9607d0046bf862182d59c66f1f18cb51c0f15?d=identicon)[bojanz](/maintainers/bojanz)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[zservices/query

Pacote para consultas em serviços do governo.

131.1k](/packages/zservices-query)

PHPackages © 2026

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