BuilderHelpers::normalizeValue could normalize enum values
ondrejmirtes opened this issue · comments
Ondřej Mirtes commented
Enum values are objects. So in normalizeValue
they end up in throw new \LogicException('Invalid value')
.
Something like this code could be added at the end of the method to handle enum values as well:
if (is_object($defaultValue)) {
$className = get_class($defaultValue);
$isEnum = function_exists('enum_exists') && enum_exists($className, false);
if ($isEnum) {
return new Node\Expr\ClassConstFetch(
new FullyQualified($className),
new Node\Identifier($defaultValue->name)
));
}
}
Maybe there are other cases that need handling, but I'm not sure if we can go from "object value" to "Expr" safely for them too.