diff --git a/changelog.md b/changelog.md index c002ebe..3b0a473 100644 --- a/changelog.md +++ b/changelog.md @@ -26,3 +26,8 @@ All notable changes to `Enum` will be documented in this file. - toArray Method now returns an array of BaseEnums this is because php numeric string array indexes to int, this would break origin enum values + +## Version 0.1.1 + +### Fixed + - fixed performances issue on toValues and toLabels \ No newline at end of file diff --git a/src/BaseEnum.php b/src/BaseEnum.php index 9f6f517..617c8d1 100644 --- a/src/BaseEnum.php +++ b/src/BaseEnum.php @@ -44,9 +44,11 @@ abstract class BaseEnum implements JsonSerializable, UrlRoutable */ public static function toValues(): array { - return \array_map(function ($baseEnum) { - return $baseEnum->value; - }, static::toArray()); + $array = []; + foreach (static::resolveDefinition() as $definition) { + $array[] = $definition->value; + } + return $array; } /** @@ -54,9 +56,11 @@ abstract class BaseEnum implements JsonSerializable, UrlRoutable */ public static function toLabels(): array { - return \array_map(function ($baseEnum) { - return $baseEnum->label; - }, static::toArray()); + $array = []; + foreach (static::resolveDefinition() as $definition) { + $array[] = $definition->label; + } + return $array; } /**