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: added stub for DataMapperInterface #422

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

Closed
JefvdA wants to merge 1 commit into phpstan:2.0.x from JefvdA:417-add-stub-for-data-mapper-interface
Closed

feat: added stub for DataMapperInterface #422

JefvdA wants to merge 1 commit into phpstan:2.0.x from JefvdA:417-add-stub-for-data-mapper-interface

Conversation

@JefvdA
Copy link

@JefvdA JefvdA commented Jan 9, 2025
edited
Loading

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: #417 
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.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

This is not sufficient. The stub has to be registered in extension.neon - stubFiles. Also because it's introducing generics, we need to add it to skipCheckGenericClasses like it was done here

skipCheckGenericClasses:
- Symfony\Component\Form\AbstractType
- Symfony\Component\Form\FormBuilderInterface
- Symfony\Component\Form\FormConfigBuilderInterface
- Symfony\Component\Form\FormConfigInterface
- Symfony\Component\Form\FormInterface
- Symfony\Component\Form\FormTypeExtensionInterface
- Symfony\Component\Form\FormTypeInterface
- Symfony\Component\OptionsResolver\Options
- Symfony\Component\Security\Core\Authorization\Voter\Voter
- Symfony\Component\Security\Core\User\PasswordUpgraderInterface

Copy link
Member

There are two different PRs with this stub: #418

  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.

/**
* @param \Traversable<mixed, FormInterface<mixed>> $forms
* @param TViewData|null $viewData
* @param-out TViewData $viewData
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong. there is no guarantee that the reference argument is replaced by a non-null value by the end of the method (and actually, the 3 core implementations of the interface have cases where the data will be null in the output)

@JefvdA JefvdA closed this by deleting the head repository May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes requested changes

+1 more reviewer

@stof stof stof 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 によって変換されたページ (->オリジナル) /