Skip to content

FormInterface::getErrors could have a dynamic return extension #166

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

Closed
VincentLanglet opened this issue May 30, 2021 · 9 comments · Fixed by #228
Closed

FormInterface::getErrors could have a dynamic return extension #166

VincentLanglet opened this issue May 30, 2021 · 9 comments · Fixed by #228

Comments

@VincentLanglet
Copy link
Contributor

VincentLanglet commented May 30, 2021

Currently, its return type is a FormErrorIterator with inside
Symfony\Component\Form\FormError|Symfony\Component\Form\FormErrorIterator

The phpdoc is

/**
     * Returns the errors of this form.
     *
     * @param bool $deep    Whether to include errors of child forms as well
     * @param bool $flatten Whether to flatten the list of errors in case
     *                      $deep is set to true
     *
     * @return FormErrorIterator An iterator over the {@link FormError}
     *                           instances that where added to this form
     */
    public function getErrors(bool $deep = false, bool $flatten = true);

So I would say it's always an iterator on Symfony\Component\Form\FormError, except if the parameter true, false are provided.

@mitelg
Copy link
Contributor

mitelg commented Jan 3, 2022

I also just stumbled upon that and would love to see that, too 😊 👍

@VincentLanglet
Copy link
Contributor Author

I also just stumbled upon that and would love to see that, too 😊 👍

This shouldn't be too hard to implement ; do you want to make a try ? @mitelg

@mitelg
Copy link
Contributor

mitelg commented Jan 4, 2022

If you can hint me where to start and maybe even an example where I can take things from, I would like to give it a try 😁

@VincentLanglet
Copy link
Contributor Author

https://github.com/phpstan/phpstan-symfony/blob/master/src/Type/Symfony/RequestDynamicReturnTypeExtension.php
can be a good example.

You'll have to implement your own logic inside getTypeFromMethodCall, but check like (new ConstantBooleanType(true))->isSuperTypeOf($argType) will be the same

@mitelg
Copy link
Contributor

mitelg commented Jan 4, 2022

I tried to start and currently I am stuck at defining the new return type. I think i need to return new ObjectType(FormErrorIterator::class) in the getTypeFromMethodCall but how do I define the generic type?

@VincentLanglet
Copy link
Contributor Author

@ondrejmirtes
Copy link
Member

Documentation is here: https://phpstan.org/developing-extensions/dynamic-return-type-extensions

@ondrejmirtes
Copy link
Member

Fixed by #228

@github-actions
Copy link

github-actions bot commented Feb 9, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants