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

ActiveLibrary

tkaratug/powered-enum
=====================

Some cool add-ons to PHP native enums.

0.0.1(3y ago)21901MITPHPPHP ^8.1

Since Oct 12Pushed 3y ago1 watchersCompare

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

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

Powered Enum
============

[](#powered-enum)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3f5f780561a2bba4b33abac81f2f8e4f495ab45ac4b47c84a8fb8a024c23f121/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746b6172617475672f706f77657265642d656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tkaratug/powered-enum)[![GitHub Tests Action Status](https://camo.githubusercontent.com/da4aa1b05ad136d39661c5a3766d421a072c6e4dbf79743eda5cde82a5ec193e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f746b6172617475672f706f77657265642d656e756d2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/tkaratug/powered-enum/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/c8f45c4cc84727aa4bdfd65eb528f51d55148825741364518340f48f1e988071/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746b6172617475672f706f77657265642d656e756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tkaratug/powered-enum)

This package offers a trait that contains some cool features for native PHP enums.

Requirements
------------

[](#requirements)

- PHP `8.1` or higher.

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

[](#installation)

```
composer require tkaratug/powered-enum
```

Declaration
-----------

[](#declaration)

All you need to do is use the `PoweredEnum` trait in your native PHP enums.

```
use Tkaratug\PoweredEnum\PoweredEnum;

enum MyEnum: int
{
    use PoweredEnum;

    case ONE    = 1;
    case TWO    = 2;
    case THREE  = 3;
}
```

Jump To
-------

[](#jump-to)

- [Methods](#Methods)
    - [is(), isNot()](#is-isnot)
- [Static Methods](#static-methods)
    - [hasName()](#hasname)
    - [hasValue()](#hasvalue)
    - [getNames()](#getnames)
    - [getValues()](#getvalues)
    - [toArray()](#toarray)
    - [getNamesExcept()](#getnamesexcept)
    - [getValuesExcept()](#getvalueexcept)
    - [toArrayExcept()](#toarrayexcept)
    - [getRandomName()](#getrandomname)
    - [getRandomValue()](#getrandomvalue)
    - [getRandomCase()](#getrandomcase)

---

Methods
-------

[](#methods)

### is(), isNot()

[](#is-isnot)

- You can check the equality of a case against any name by passing it to the `is()` and `isNot()` methods.

```
$myEnum = MyEnum::ONE;

$myEnum->is(MyEnum::ONE);      // true
$myEnum->is(MyEnum::TWO);      // false

$myEnum->isNot(MyEnum::ONE);   // false
$myEnum->isNot(MyEnum::TWO);   // true
```

---

Static Methods
--------------

[](#static-methods)

### hasName()

[](#hasname)

- You can check whether an enum has a case by given name via the `hasName()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
    case TWO = 2;
}

MyEnum::hasName('ONE');     // true
MyEnum::hasName('THREE');   // false
```

---

### hasValue()

[](#hasvalue)

- You can check whether an enum has a case by given value via the `hasValue()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
    case TWO = 2;
}

MyEnum::hasValue(1);   // true
MyEnum::hasValue(3);   // false
```

---

### getNames()

[](#getnames)

- You can get enum case names as an array by using the `getNames()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
    case TWO = 2;
}

MyEnum::getNames();   // ['ONE', 'TWO']
```

---

### getValues()

[](#getvalues)

- You can get enum case values as an array by using the `getValues()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
    case TWO = 2;
}

MyEnum::getValues();   // [1, 2]
```

---

### toArray()

[](#toarray)

- You can get a combined array of the enum cases as `value => name` by using the `toArray()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
    case TWO = 2;
}

MyEnum::toArray();   // [1 => 'ONE', 2 => 'TWO']
```

---

### getNamesExcept()

[](#getnamesexcept)

- You can get names of enum cases as an array except for given ones by using the `getNamesExcept()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
    case TWO = 2;
    case THREE = 3;
}

MyEnum::getNamesExcept([MyEnum::ONE]);   // ['TWO', 'THREE']
```

---

### getValuesExcept()

[](#getvaluesexcept)

- You can get values of enum cases as an array except for given ones by using the `getValuesExcept()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
    case TWO = 2;
    case THREE = 3;
}

MyEnum::getValuesExcept([MyEnum::ONE]);   // [2, 3]
```

---

### toArrayExcept()

[](#toarrayexcept)

- You can get a combined array of the enum cases as `value => name` except for given ones by using the `toArrayExcept()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
    case TWO = 2;
    case THREE = 3;
}

MyEnum::toArrayExcept([MyEnum::ONE]);   // [2 => 'TWO', 3 => 'THREE]
```

---

### getRandomName()

[](#getrandomname)

- You can get a random name of the enum cases by using the `getRandomName()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
}

MyEnum::getRandomName();   // ['ONE']
```

---

### getRandomValue()

[](#getrandomvalue)

- You can get a random value of the enum cases by using the `getRandomValue()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
}

MyEnum::getRandomValue();   // [1]
```

---

### getRandomCase()

[](#getrandomcase)

- You can get a random case of the enum by using the `getRandomCase()` method.

```
enum MyEnum: int {
    use PoweredEnum;

    case ONE = 1;
}

MyEnum::getRandomCase();   // MyEnum::ONE
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Turan Karatuğ](https://github.com/tkaratug)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

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

1311d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/50dc98a0c75a1aaba61d52bb073e1b0cbdb17f4d5ed4bd1c694c71784b088e16?d=identicon)[tkaratug](/maintainers/tkaratug)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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