Skip to content

Missing stub file for Symfony Form DataMapperInterface #417

Open
@roerbakei

Description

@roerbakei

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.

Activity

added a commit that references this issue on Dec 4, 2024
mmarton

mmarton commented on Jan 6, 2025

@mmarton

I have the same issue

JefvdA

JefvdA commented on Jan 6, 2025

@JefvdA

@mmarton you can temporarly resolve your issue by using the stub file @roerbakei provided in his PR -> https://github.com/phpstan/phpstan-symfony/pull/418/files

PHPStan docs explain how to add local stub-files

JefvdA

JefvdA commented on Jan 9, 2025

@JefvdA

Created a PR with @roerbakei his suggested change ( adding the stub file for the DataItemMapperInterface ), but with a small tweak that fixes the feedback I gave ( #418 (comment) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Missing stub file for Symfony Form DataMapperInterface · Issue #417 · phpstan/phpstan-symfony