Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: stub DataMapperInterface #418

Open
wants to merge 3 commits into
base: 2.0.x
Choose a base branch
from

Conversation

roerbakei
Copy link

  • Ensure TData of FormInterface is provided.
  • Set TData on mixed since we don't know the type of the child forms.
  • Add template for DataMapperInterface.

I've set TData of FormInterface to mixed since each child form can have a different type.

refs: #417

wietse added 3 commits December 4, 2024 11:53
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
Comment on lines +11 to +21
* @param TViewData $viewData
* @param \Traversable<mixed, FormInterface<mixed>> $forms
*/
public function mapDataToForms(mixed $viewData, \Traversable $forms): void;

/**
* @param \Traversable<mixed, FormInterface<mixed>> $forms
* @param TViewData $viewData
* @param-out TViewData $viewData
*/
public function mapFormsToData(\Traversable $forms, mixed &$viewData): void;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's stated in the docs ( https://symfony.com/doc/current/form/data_mappers.html#creating-a-data-mapper ), the following logic is needed:

// there is no data yet, so nothing to prepopulate
if (null === $viewData) {
    return;
}

This, as it seems that mapDataToForms is called before the data is avaialble. Which will mean that $viewData will be null at that time.


Thus I propose the following change:

Suggested change
* @param TViewData $viewData
* @param \Traversable<mixed, FormInterface<mixed>> $forms
*/
public function mapDataToForms(mixed $viewData, \Traversable $forms): void;
/**
* @param \Traversable<mixed, FormInterface<mixed>> $forms
* @param TViewData $viewData
* @param-out TViewData $viewData
*/
public function mapFormsToData(\Traversable $forms, mixed &$viewData): void;
* @param TViewData|null $viewData
* @param \Traversable<mixed, FormInterface<mixed>> $forms
*/
public function mapDataToForms(mixed $viewData, \Traversable $forms): void;
/**
* @param \Traversable<mixed, FormInterface<mixed>> $forms
* @param TViewData|null $viewData
* @param-out TViewData $viewData
*/
public function mapFormsToData(\Traversable $forms, mixed &$viewData): void;

For example, the stub file for the FormTypeInterface also has a generic type, but also has it defined nullable when it's being passed to it's buildForm method.

@ondrejmirtes
Copy link
Member

There are two different PRs with this stub: #422

  1. Both have the same mistake of not registering the stub.
  2. Both are slightly different so you should agree first how it should look like.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants