Skip to content

Add stub for AbstractType #317

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
wants to merge 1 commit into from
Closed

Add stub for AbstractType #317

wants to merge 1 commit into from

Conversation

gndk
Copy link

@gndk gndk commented Dec 18, 2022

This PR adds stubs for Symfony\Component\Form\AbstractType and Symfony\Component\Form\AbstractTypeExtension.

After upgrading to Psalm 5, it requires @template-extends AbstractType<int> annotation when extending AbstractType, but currently phpstan complains about this.

Adding these stubs creates parity with psalm/psalm-plugin-symfony regarding those classes.

Co-authored-by: Farhad Safarov <[email protected]>
@gndk gndk changed the title Add stub for Symfony AbstractType Add stub for AbstractType Dec 18, 2022
@stof
Copy link
Contributor

stof commented Dec 19, 2022

what is expected to be represented by that template type ?

@gndk
Copy link
Author

gndk commented Dec 19, 2022

The stubs in the psalm plugin were originally added in this PR psalm/psalm-plugin-symfony#138, with some discussion here psalm/psalm-plugin-symfony#60.

@gndk
Copy link
Author

gndk commented Dec 19, 2022

There is also discussion around this current issue after upgrading to psalm 5 here psalm/psalm-plugin-symfony#294

Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

Those stubs are useless for PHPStan and even more they will just add more pain for PHPStan-Symfony user because it will require to fill a template

/**
 * @extends AbstractType<ICanWriteEverythingIWant>
 */
class MyType extends AbstractType
{
}

With no benefit at all.

@stof Those stubs were added to psalm-symfony with only one benefit, this one:
https://github.com/psalm/psalm-plugin-symfony/blob/4.x/src/Stubs/common/Component/Form/FormView.stubphp#L16
but the syntax array{value: ?T, attr: array<array-key, mixed>}&array<string, mixed>
is not supported by PHPStan.

So there is absolutely no reason to add such template.

Also the symfony-core was not really into those generics symfony/symfony#40783 (comment)

If you want to use both psalm and phpstan, I assume you can write

/** 
 * @psalm-param FormView<Foo>
 * @phpstan-param FormView
 */

@gndk gndk closed this Dec 22, 2022
@gndk gndk deleted the abstracttype-stub branch December 22, 2022 16:02
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.

3 participants