Closed kissifrot closed 1 year ago
Hi, please show an example of a class that uses AbstractType
. What's the advantage of AbstractType being generic?
To be honest I'm not sure about this specific addition, but it sems it raises issues such as the one described in https://github.com/psalm/psalm-plugin-symfony/issues/295#issuecomment-1359526555
An example class would be:
// ...
use Symfony\Component\Form\AbstractType;
class UserBookType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title', TextType::class, ['trim' => true])
//
->add('save', SubmitType::class)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => UserBookCreateDTO::class,
]);
}
}
To then be used in symfony's AbstractController
:
// ...
$userBookDTO = new UserBookCreateDTO();
$form = $this->createForm(UserBookType::class, $userBookDTO);
$form->handleRequest($request);
// ...
There already was a PR opened for this https://github.com/phpstan/phpstan-symfony/pull/317
And I explained that the stub/generics is currently useless for PHPStan https://github.com/phpstan/phpstan-symfony/pull/317#pullrequestreview-1227793157
The solution is maybe to write
/**
* @psalm-extends AbstractType<Foo>
* @phpstan-extends AbstractType
*/
That suggestion isn't going to work. Please before you suggest something, check it with phpstan.org/try.
The solution is https://phpstan.org/user-guide/ignoring-errors
That suggestion isn't going to work. Please before you suggest something, check it with phpstan.org/try.
Indeed, it works for param/return type but not for extends https://phpstan.org/r/767eb0ad-18ea-47a1-a204-f027169c5fa3
Dunno if it's worth enough for a feature request...
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
This PR looks promising https://github.com/phpstan/phpstan-symfony/pull/337
Hello,
I'm having issues with cross-usage of psalm and phpstan for form type classes extending
AbstractType
:/** @extends AbstractType<mixed> */
(or similar ^^) is needed to avoid gettingMissingTemplate
errorsAbstractType
is not genericI'm a bit lost in this situation, as I guess suppressing psalm's
MissingTemplate
errors is not the good thing to do 😅