1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2025-12-12 22:14:04 +00:00

Extend functionality to work with pure enums (#6)

* Extend functionality to work with pure enums

* Code review changes

Altered `::values()` to act like `::names()` for backed enums, code style fixes, general cleanups
This commit is contained in:
Samuel Levy 2022-03-24 06:42:35 +10:00 committed by GitHub
parent 20fa78c2b1
commit 0c87357a6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 109 additions and 16 deletions

View file

@ -4,11 +4,17 @@ declare(strict_types=1);
namespace ArchTech\Enums;
use BackedEnum;
trait Options
{
/** Get an associative array of [case name => case value]. */
public static function options(): array
{
return array_column(static::cases(), 'value', 'name');
$cases = static::cases();
return isset($cases[0]) && $cases[0] instanceof BackedEnum
? array_column($cases, 'value', 'name')
: array_column($cases, 'name');
}
}