diff --git a/lib/php-enum/src/Enum.php b/lib/php-enum/src/Enum.php index f5a59404a04..b8b93277e2c 100644 --- a/lib/php-enum/src/Enum.php +++ b/lib/php-enum/src/Enum.php @@ -37,6 +37,14 @@ abstract class Enum implements \JsonSerializable */ protected static $cache = []; + /** + * Cache of instances of the Enum class + * + * @var array + * @psalm-var array> + */ + protected static $instances = []; + /** * Creates a new value of some type * @@ -211,17 +219,20 @@ abstract class Enum implements \JsonSerializable * @param array $arguments * * @return static - * @psalm-pure * @throws \BadMethodCallException */ public static function __callStatic($name, $arguments) { - $array = static::toArray(); - if (isset($array[$name]) || \array_key_exists($name, $array)) { - return new static($array[$name]); + $class = static::class; + if (!isset(self::$instances[$class][$name])) { + $array = static::toArray(); + if (!isset($array[$name]) && !\array_key_exists($name, $array)) { + $message = "No static method or enum constant '$name' in class " . static::class; + throw new \BadMethodCallException($message); + } + return self::$instances[$class][$name] = new static($array[$name]); } - - throw new \BadMethodCallException("No static method or enum constant '$name' in class " . static::class); + return clone self::$instances[$class][$name]; } /** diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 15a443f114f..5ae5f2961fa 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -349,7 +349,7 @@ php-enum php-enum MIT - 1.7.6 + 1.7.7 http-message