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

Allow multiple object builders with same argument names but different types #377

Open
AndrolGenhald opened this issue Apr 25, 2023 · 0 comments · May be fixed by #488
Open

Allow multiple object builders with same argument names but different types #377

AndrolGenhald opened this issue Apr 25, 2023 · 0 comments · May be fixed by #488

Comments

@AndrolGenhald
Copy link
Contributor

The following code currently fails for both list items with a SeveralObjectBuildersFound exception from FilteredObjectBuilder. Since the types don't overlap there shouldn't be any ambiguity, so I expected this to work. I suppose this might actually be a bit difficult since if FilteredObjectBuilder filters based on argument types it would no longer show the same error for an incorrect type, it would instead throw a CannotFindObjectBuilder exception.

<?php

include "vendor/autoload.php";

class Foo
{
    public function __construct(public int $value) {}
}

class Bar
{
    public function __construct(public string $value) {}
}

var_dump(
    (new CuyZ\Valinor\MapperBuilder())
        ->mapper()
        ->map("list<Foo|Bar>", ["foobar", 123])
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant