Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: stub DataMapperInterface #418

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

Open
roerbakei wants to merge 3 commits into phpstan:2.0.x
base: 2.0.x
Choose a base branch
Loading
from roerbakei:stub/data-mapper-interface

Conversation

@roerbakei
Copy link

@roerbakei roerbakei commented 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 DataMapperInterface.

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

refs: #417

JefvdA and mmarton reacted with thumbs up emoji
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.

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.

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

Reviewers

1 more reviewer

@JefvdA JefvdA JefvdA left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /