-
Notifications
You must be signed in to change notification settings - Fork 92
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
base: 2.0.x
Are you sure you want to change the base?
feat: added stub for DataMapperInterface #422
Conversation
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
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. |
There was a problem hiding this 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
phpstan-symfony/extension.neon
Lines 15 to 25 in dd1aaa7
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 |
There are two different PRs with this stub: #418
|
/** | ||
* @param \Traversable<mixed, FormInterface<mixed>> $forms | ||
* @param TViewData|null $viewData | ||
* @param-out TViewData $viewData |
There was a problem hiding this comment.
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)
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