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

Parsing enum array not working #585

Open
stayallive opened this issue Dec 22, 2024 · 0 comments
Open

Parsing enum array not working #585

stayallive opened this issue Dec 22, 2024 · 0 comments

Comments

@stayallive
Copy link

Hey there, I am trying to parse a array of integers to a array of integer backed enums like so:

enum SomeEnum: int
{
    case SOME_VALUE  = 1;
    case OTHER_VALUE = 2;
}

class ExampleObject
{
    public function __construct(
        /** @var \SomeEnum[] */
        public array $enumArray,
    ) {}
}

(new \CuyZ\Valinor\MapperBuilder())
    ->mapper()
    ->map(
        ExampleObject::class,
        ['enumArray' => [1, 2]],
    );

In this test I get:

Fatal error: Uncaught TypeError: CuyZ\Valinor\Type\Parser\GenericCheckerParser::parse(): Argument #1 ($raw) must be of type string, null given, called in vendor/cuyz/valinor/src/Definition/Repository/Reflection/TypeResolver/ClassParentTypeResolver.php on line 47 and defined in vendor/cuyz/valinor/src/Type/Parser/GenericCheckerParser.php:30

However in my application it fails differently:

Attempt to read property "name" on false {"exception":"[object] (ErrorException(code: 0): Attempt to read property \"name\" on false at vendor/cuyz/valinor/src/Definition/Repository/Reflection/TypeResolver/ClassParentTypeResolver.php:39)

I was unable to get a minimal case for this error mode in a minimal way but showing it here in case it's helpful.

From a little debugging (on the second error) I ended up in ReflectionClassDefinitionRepository@typeResolver where there is a while loop looping while $type->className() !== $target->name however these are for me something like SomeEnum and \SomeEnum respectively (notice the leading \) which seemed odd to me. I did quadruple check it was not a type on my side 👀

Maybe I am doing something wrong or incorrect here, but from my perspective something is not right 😅 I have been trying to dig around but it's a pretty complex codebase so I was unable to devise some fix or better understanding at this time.

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