Skip to content

Add createBuilder() and createNamedBuilder() to the FormFactoryInterface stub - #516

Merged
staabm merged 1 commit into
phpstan:2.1.xfrom
Amoifr:form-factory-builder-stubs
Oct 25, 2026
Merged

staabm merged 1 commit into
phpstan:2.1.xfrom
Amoifr:form-factory-builder-stubs

Conversation

@Amoifr

@Amoifr Amoifr commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Closes #445

The stub only declared create() and createNamed(), so the builder methods fell back to Symfony's own signature and returned a plain FormBuilderInterface, with mixed data. They now carry the same templates as their create*() counterparts and return FormBuilderInterface<TData> (or <null|TData> without data), so $builder->getData() and $builder->getForm() keep the data type of the form type.

One limit worth knowing: like create(), this only helps with a generic form type (AbstractType<Foo>). With the core FormType::class from the issue, TData stays mixed, exactly as create(FormType::class, new Foo()) does today.

createForProperty() and createBuilderForProperty() are left alone, since there is no form type to take the data type from.

@staabm
staabm requested a review from VincentLanglet October 25, 2026 08:46
@staabm

staabm commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

I am not a symfony expert. do these newly added method types hold across all supported symfony versions of phpstan-symfony?

//cc @SanderMuller

@VincentLanglet
VincentLanglet requested a review from staabm October 25, 2026 10:37
@SanderMuller

Copy link
Copy Markdown

Yes. I checked FormFactoryInterface in Symfony 3.4, 4.4, 5.4, 6.4, 7.3 and 8.0. createBuilder() and createNamedBuilder() exist in all of them with the same parameter names and a FormBuilderInterface return. Only the native types differ, which matches how the existing create() and createNamed() entries in this stub are written.

The new tests pass with lowest (symfony/form 5.4.0) and highest (6.4.48) dependencies, and fail without the stub change. I also checked the default FormType, a non-generic type and TextType: the data stays mixed, the same as create() today.

@staabm

staabm commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Thank you!

@staabm
staabm merged commit e218a49 into phpstan:2.1.x Oct 25, 2026
43 checks passed
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.

Missing method in stub Symfony Form FormFactoryInterface

4 participants