You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[PHPStan] improve FactoryCollection generics annotation with template-type #894
those FactoryCollection with proxies are kinda hard to deal with. We're open to any good idea to simplify this :)
By the way, the only use case to type hint with FactoryCollection is when dealing with data provider, but since Foundry 2.2 and PHPUnit 11.4, you can directly call YouFactory::createMany() in your data provider. you'll need to use the phpunit extension provided by Foundry. see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#phpunit-data-providers
this is very cool! I didn't even know template-type exists!
one thing I'd like, is that the current way of documenting factories still works. We've already introduced a BC break around this few months ago, and I would not want to introduce another one now...
do you think both fashions of documenting FactoryCollection could be compatible?
Tried a few ideas using Template default types from phpstan/phpstan#4801 but couldn't get any to work for both one and two template types specified. The hurdle here seems to be that the T to be removed is the first parameter. 😞
if at some point, you're willing to provide a PR with the changes with template-type and make the CI green that would be very nice, and we'll merge it in a future 3.x branch (but nothing hurry, this is planned for next November I think)
changed the title [-]PhpStan complains about PersistentProxyObjectFactory subtypes[/-][+][PHPStan] improve `FactoryCollection` generics annotation with `template-type`[/+]on May 6, 2025
we may release Foundry 3, along with Symfony 8 in november. This might be the good time to think a little bit more how we can improve Factory collection, as we may allow some breaking change at this time
Activity
nikophil commentedon May 5, 2025
fixed 😄
https://phpstan.org/r/441da82d-53cc-40ee-8b4e-4ff82b7988b6
those
FactoryCollectionwith proxies are kinda hard to deal with. We're open to any good idea to simplify this :)By the way, the only use case to type hint with
FactoryCollectionis when dealing with data provider, but since Foundry 2.2 and PHPUnit 11.4, you can directly callYouFactory::createMany()in your data provider. you'll need to use the phpunit extension provided by Foundry. see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#phpunit-data-providersedglev commentedon May 5, 2025
Thank you ❤️ The use case for type hints is with data providers.
edglev commentedon May 5, 2025
I've might have just found a way to simplify this - you can interpret the type from TFactory, example taken from here phpstan/phpstan#9053
https://phpstan.org/r/7a4e6c92-1d39-4470-860f-890d47aee32c
What do you think?
nikophil commentedon May 5, 2025
this is very cool! I didn't even know
template-typeexists!one thing I'd like, is that the current way of documenting factories still works. We've already introduced a BC break around this few months ago, and I would not want to introduce another one now...
do you think both fashions of documenting
FactoryCollectioncould be compatible?edglev commentedon May 5, 2025
I don't think so, best I can come up right now is to just leave the signature as is and ignore the
Thttps://phpstan.org/r/d7745a05-7be3-4425-b94f-6de8fb773d41Tried a few ideas using Template default types from phpstan/phpstan#4801 but couldn't get any to work for both one and two template types specified. The hurdle here seems to be that the
Tto be removed is the first parameter. 😞nikophil commentedon May 6, 2025
ok then, I'm sorry, but we're not going to integrate this now in Foundry
BUT this could be integrated to Foundry 3, that might land at the end of the year (as for Symfony 8.0)
BTW, there's some chances that we offer a rector set to migrate to Foundry 3, the same way we did for migration from 1 to 2
nikophil commentedon May 6, 2025
@edglev I'll keep this open 👍
if at some point, you're willing to provide a PR with the changes with
template-typeand make the CI green that would be very nice, and we'll merge it in a future3.xbranch (but nothing hurry, this is planned for next November I think)[-]PhpStan complains about PersistentProxyObjectFactory subtypes[/-][+][PHPStan] improve `FactoryCollection` generics annotation with `template-type`[/+]edglev commentedon May 6, 2025
Ah, sorry for closing this :D Sure, I'll make a PR sometime later
nikophil commentedon Jul 6, 2025
we may release Foundry 3, along with Symfony 8 in november. This might be the good time to think a little bit more how we can improve Factory collection, as we may allow some breaking change at this time