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

Missing stub file for Symfony Form DataMapperInterface #417

Open
roerbakei opened this issue Dec 4, 2024 · 0 comments
Open

Missing stub file for Symfony Form DataMapperInterface #417

roerbakei opened this issue Dec 4, 2024 · 0 comments

Comments

@roerbakei
Copy link

Bug Report / Feature Request

When implementing the Symfony Form DataMapperInterface it will currently throw the following error:

Method  MyApp\FormType::mapDataToForms()  
         has parameter $forms with generic interface                                                                               
         Symfony\Component\Form\FormInterface but does not specify its types:                                                      
         TData     

When fixing this by defining TData for the FormInterface in the class that implements the DataMapperInterface, the type will be different from the interface resulting in an error:

   /**
    * @param Traversable<FormInterface<mixed>> $forms
    */
   public function mapDataToForms(mixed $viewData, Traversable $forms): void

Note: I've typed TData of FormInterface to mixed since $forms stands for the child forms of the form which is using the data mapper and so can have multiple types.

Parameter #2 $forms (Traversable<mixed,                                                                                   
         Symfony\Component\Form\FormInterface<mixed>>) of method                                                                   
         MyApp\FormType::mapDataToForms()  
         should be contravariant with parameter $forms (Traversable<mixed,                                                         
         Symfony\Component\Form\FormInterface>) of method                                                                          
         Symfony\Component\Form\DataMapperInterface::mapDataToForms()           

Unless I'm missing something it looks that a stub for Symfony Form DataMapperInterface is not provided yet.

roerbakei pushed a commit to roerbakei/phpstan-symfony that referenced this issue Dec 4, 2024
Ensure TData of FormInterface is provided
Set TData on mixed since we don't know the type of the child forms
Add template for  in DataMapperInterface

refs: phpstan#417
roerbakei pushed a commit to roerbakei/phpstan-symfony that referenced this issue Dec 4, 2024
roerbakei pushed a commit to roerbakei/phpstan-symfony that referenced this issue Dec 4, 2024
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