Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuilderHelpers::normalizeValue could normalize enum values #951

Open
ondrejmirtes opened this issue Oct 2, 2023 · 0 comments
Open

BuilderHelpers::normalizeValue could normalize enum values #951

ondrejmirtes opened this issue Oct 2, 2023 · 0 comments

Comments

@ondrejmirtes
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant