PHPackages                             freshp/php-enumeration - 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. freshp/php-enumeration

ActiveLibrary

freshp/php-enumeration
======================

This small package can represent a enumeration field. For example in a database or an api.

4.0.0(4y ago)033.5k↓16.7%MITPHPPHP ^7.4|^8.0

Since Nov 24Pushed 4y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (13)Used By (0)

[![Build Status](https://camo.githubusercontent.com/34a2df43993a5de241d9ac175cbd306ae3e19ef9862d1109f431a0979500e40e/68747470733a2f2f7472617669732d63692e6f72672f6672657368702f7068702d656e756d65726174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/freshp/php-enumeration)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/f6aef3ab55f4a575171172419fb20ada7452f61c3b8b53d8ae4d18e92111ec4d/68747470733a2f2f706f7365722e707567782e6f72672f6672657368702f7068702d656e756d65726174696f6e2f762f737461626c65)](https://packagist.org/packages/freshp/php-enumeration)[![Total Downloads](https://camo.githubusercontent.com/863ab18dcd5fdd2244620292012735f31bd8436fd188ad053b5ba2bd27da341a/68747470733a2f2f706f7365722e707567782e6f72672f6672657368702f7068702d656e756d65726174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/freshp/php-enumeration)

php-enumeration
===============

[](#php-enumeration)

This small package can represent a enumeration field. For example in a database or an api.

**Featureslist:**

- inspired and mostly used for MySQL enum-fields or API enum-fields
- it is a simple string representation
- no other values are allow besides the defined in the class
- simple usage and easy to read
- no features a enum do not have to deal with
- with a default fallback value which will be used if no matching value exists in const´s
    - you can harden this object by throwing an exception in the `getDefault`-method

Install
-------

[](#install)

Basic install via composer

```
composer require freshp/php-enumeration

```

Usage
-----

[](#usage)

Take a look in `tests/fixtures` to see a executable example.

Create a new object with:

1. public const´s which represent strings
2. implement the `getDefault`-method

### Create an enumeration object

[](#create-an-enumeration-object)

```
use FreshP\PhpEnumeration\Enum;

class EnumExample extends Enum
{
    public const TEST_CONSTANT = 'constant';
    public const TEST_DEFAULT = 'default';

    protected function getDefault(): string
    {
        return self::TEST_DEFAULT;
    }
}
```

use annotations for better ide support

```
use FreshP\PhpEnumeration\Enum;

/**
 * @method static self TEST_CONSTANT()
 * @method static self TEST_DEFAULT()
 */
class EnumExample extends Enum
...
```

make the data of the parent `toArray`-method public if you need to iterate over all options

```
class EnumExample extends Enum
{
...
    public static function listAllOptions(): array
    {
        return self::toArray();
    }
...
```

### Use the enumeration object

[](#use-the-enumeration-object)

1. create the object by static call

    ```
    $enum = EnumExample::TEST_CONSTANT();
    ```
2. create the object by normal initialization

    ```
    $enum = new EnumExample(EnumExample::TEST_CONSTANT);
    ```
3. create a default object (the value from the `getDefault`-method will be called)

    ```
    $enum = new EnumExample();
    ```
4. compare the object by using the `__toString`-method

    ```
    $enum->__toString() === EnumExample::TEST_CONSTANT
    ```

    or

    ```
    $enum->isEqual(EnumExample::TEST_CONSTANT())
    ```

Checks
------

[](#checks)

Run each command in the project root directory.

run all check with composer script

```
composer quickcheck

```

### Execute PHPUnit tests

[](#execute-phpunit-tests)

```
./vendor/bin/phpunit.phar --testdox

```

### Execute fix PHPCS problems

[](#execute-fix-phpcs-problems)

```
./vendor/bin/phpcbf.phar

```

### Execute PHPCS checks

[](#execute-phpcs-checks)

```
./vendor/bin/phpcs.phar

```

### Execute PHPSTAN checks

[](#execute-phpstan-checks)

```
./vendor/bin/phpstan.phar analyse -l max ./src

```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity75

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

Recently: every ~145 days

Total

12

Last Release

1741d ago

Major Versions

0.0.4 → 1.0.02018-07-17

1.0.1 → 2.0.02019-11-29

2.0.0 → 3.0.02020-01-07

3.2.0 → 4.0.02021-08-11

PHP version history (5 changes)0.0.1PHP &gt;=7.0

1.0.0PHP &gt;=7.2

2.0.0PHP ^7.3

3.0.0PHP ^7.4

3.2.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4762257?v=4)[Steve](/maintainers/freshp)[@freshp](https://github.com/freshp)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/freshp-php-enumeration/health.svg)

```
[![Health](https://phpackages.com/badges/freshp-php-enumeration/health.svg)](https://phpackages.com/packages/freshp-php-enumeration)
```

PHPackages © 2026

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