Skip to content

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
wants to merge 3 commits into
base: 2.0.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions stubs/Symfony/Component/Form/DataMapperInterface.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Symfony\Component\Form;

/**
* @template TViewData
*/
interface DataMapperInterface
{
/**
* @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;
Comment on lines +11 to +21
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.

}
Loading