From 149a9522f4c968972f2f5deb61befc6a82e6cdfc Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 3 Nov 2024 23:46:55 +0100 Subject: [PATCH] Fixup EnumPropertyAccessor::toEnum --- .../PropertyAccessors/EnumPropertyAccessor.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Mapping/PropertyAccessors/EnumPropertyAccessor.php b/src/Mapping/PropertyAccessors/EnumPropertyAccessor.php index 54024eb470..29ed7dc689 100644 --- a/src/Mapping/PropertyAccessors/EnumPropertyAccessor.php +++ b/src/Mapping/PropertyAccessors/EnumPropertyAccessor.php @@ -55,13 +55,25 @@ private function fromEnum($enum) } /** - * @param int|string|int[]|string[] $value + * @param BackedEnum|BackedEnum[]|int|string|int[]|string[] $value * - * @return ($value is int|string ? BackedEnum : BackedEnum[]) + * @return ($value is int|string|BackedEnum ? BackedEnum : BackedEnum[]) + * + * @psalm-suppress InvalidReturnStatement + * @psalm-suppress PossiblyInvalidArgument */ private function toEnum($value) { + if ($value instanceof BackedEnum) { + return $value; + } + if (is_array($value)) { + $v = reset($value); + if ($v instanceof BackedEnum) { + return $value; + } + return array_map([$this->enumType, 'from'], $value); }