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

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

robier/enum
===========

PHP enums implementation

v1.0.0(2y ago)17.9kMITPHPPHP ^8.1CI failing

Since Apr 29Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (5)Used By (0)

Enums
-----

[](#enums)

This is yet another enum implementation in PHP.

When we did not have enums in PHP this library was trying to fix that. Now we have enums with PHP version 8.1 so there is no need for "yet another enum implementation". This library was changed to add "missing" features to already existing enums.

Supported features:

**Name****Trait****Description**Default\\Robier\\Enum\\HasDefaultAdds 2 new methods to the enum:
- `try(int|string $value, self $default): self`
- `tryName(string $name, self $default): self`Random\\Robier\\Enum\\HasRandomAdds 1 new method:
- `random(self ...$exclude): self`Boolean checks\\Robier\\Enum\\HasBooleanChecksAdds 1 new method and 2 methods for every case in enum.
New method is ´any(self ...$test):bool´ and other methods are magic. Let's say you have ADMIN\_USER case in enum, then new magic methods would be:
- `isAdminUser():bool`
- `notAdminUser():bool`All\\Robier\\Enum\\HasAllHave all already mentioned enum enhancements.When using "Boolean checks", you can easily create a doc blocks for magic functions so your IDE can be developer friendly.

```
$ vendor/bin/enum [FQN enum]
```

It will just generate all magic methods in stdout. It will not change actual files.

### Development

[](#development)

This project is dockerized. Before running tests you need to build a docker container by using provided script from the docker folder.

```
 $ docker/build
```

After the build is finished, you can run any command by using:

```
 $ docker/run %command%
```

for example:

```
 $ docker/run composer install
```

Additional tools for developing:

- `composer test` - runs all PHPUnit tests
- `XDEBUG_MODE=coverage composer test:coverage:html` - runs all PHPUnit tests and generates HTML report
- `composer test:infestation` - runs mutation tests and generates mutation score

Feel free to contribute.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% 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 ~1287 days

Total

2

Last Release

922d ago

Major Versions

v0.1 → v1.0.02023-11-08

PHP version history (2 changes)v0.1PHP ^7.2

v1.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3607521?v=4)[Robert](/maintainers/robier)[@robier](https://github.com/robier)

---

Top Contributors

[![robier](https://avatars.githubusercontent.com/u/3607521?v=4)](https://github.com/robier "robier (8 commits)")[![dvelopate](https://avatars.githubusercontent.com/u/30019439?v=4)](https://github.com/dvelopate "dvelopate (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[gregwar/formidable

Formidable, the pragmatic forms library

12062.2k1](/packages/gregwar-formidable)

PHPackages © 2026

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