fixed performances issue on toValues and toLabels

This commit is contained in:
Jérémy Munsch 2021-03-03 09:42:24 +01:00
parent 45a1ccd27f
commit a79173ec38
2 changed files with 15 additions and 6 deletions

View file

@ -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

View file

@ -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;
}
/**