From ea06b37a47492e27bf4c915397413c19aa108314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 16 Nov 2026 11:44:31 +0100 Subject: [PATCH] refactor(BaseEnum): improve cache handling and type annotations Enhanced type annotations for cache variables and improved readability of the toLabels, toValues, and getCustomDefinitions methods. --- shared/Enums/BaseEnum.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/shared/Enums/BaseEnum.php b/shared/Enums/BaseEnum.php index 453796bc..61ad7172 100644 --- a/shared/Enums/BaseEnum.php +++ b/shared/Enums/BaseEnum.php @@ -36,12 +36,14 @@ trait BaseEnum */ public static function toLabels(): array { + /** @var array|null $cache */ static $cache = null; if ($cache !== null) { return $cache; } + /** @var array|null $labels */ $labels = defined(self::class . '::' . self::LABELS_CONSTANT_NAME) ? constant(self::class . '::' . self::LABELS_CONSTANT_NAME) : null; @@ -62,17 +64,21 @@ trait BaseEnum */ public static function toValues(): array { + /** @var array|null $cache */ static $cache = null; if ($cache !== null) { return $cache; } - return $cache = array_column( + /** @var array $values */ + $values = array_column( self::cases(), 'value', 'name' ); + + return $cache = $values; } /** @@ -136,13 +142,15 @@ trait BaseEnum */ private static function getCustomDefinitions(): array { + /** @var array>|null $cache */ static $cache = null; if ($cache !== null) { return $cache; } - $names = array_column(self::cases(), 'name', 'name'); + $names = array_column(self::cases(), 'name', 'name'); + /** @var array> $filteredConstants */ $filteredConstants = []; foreach ((new \ReflectionClass(self::class))->getConstants() as $key => $constant) { @@ -151,6 +159,7 @@ trait BaseEnum } if (! empty(array_intersect_key($constant, $names))) { + /** @var array $constant */ $filteredConstants[$key] = $constant; } }