From a79173ec38dbf0e3e9263e418812e0ab40d02110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 3 Mar 2021 09:42:24 +0100 Subject: [PATCH] fixed performances issue on toValues and toLabels --- changelog.md | 5 +++++ src/BaseEnum.php | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) 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; } /**