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

feat: added stub for DataMapperInterface #422

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from

Conversation

JefvdA
Copy link

@JefvdA JefvdA commented Jan 9, 2025

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

creds to @roerbakei ;)

refs: #417

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

creds to @roerbakei ;)

refs: phpstan#417
@Tomsgu
Copy link

Tomsgu commented Jan 16, 2025

This looks good to me. The only missing part is detecting if I pass a correct value when creating a form. Because currently I can pass anything I want.

$form = $this->createForm(SnippetType::class, $notAllowedObject); // type mismatch error
 /**
 * @template-implements DataMapperInterface<SnippetDto>
 */
class SnippetType extends AbstractType implements DataMapperInterface
{
    public function mapDataToForms(mixed $viewData, Traversable $forms): void
    {
        if ($viewData === null) {
            return;
        }

        // Does not make sense to do this check. But we still need to do it. Obvious error: 
        // Instanceof between SnippetDto and SnippetDto will always evaluate to true.
        // 🪪  instanceof.alwaysTrue
        
        //if (!$viewData instanceof SnippetDto) {
        //    throw new UnexpectedTypeException($viewData, SnippetDto::class);
        //}

        $forms = iterator_to_array($forms);
        // ...
    }
}

I am wondering if there is anything we can do about this.

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

Successfully merging this pull request may close these issues.

2 participants