-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
V2 and phpstan #623
Comments
Hey @norkunas thank you for this report.
you're absolutely right, we're gonna find a solution! After some times scratching my head looking for an explanation, I think I've found the problem: It seems that PHPStan "lose" the inherited array definition if the return type is changed 🤷 I think as an easy fix, you could replace all return types from I've asked on PHPStan's GitHub if this is a bug or a feature 😅 and we'll see what to do... (maybe the solution would be to modify this return type with rector rules) |
ok so this is a bug in PHPStan... I think the simplest solution is to add return type |
But then if you don't return a callable, phpstan complains also and says to narrow type, this is included in issue description :) |
wow sorry, I haven't seen that big 🤦 here that's strange it did not occurred to me... is that coming from level 9? (I'm only using level 8 on my projects) I think we're stuck for now and I hate this 😬 I got plans to create a PHPStan extension for Foundry where we can fix this, but I don't know when I'll got enough time. (And I expect Psalm users to show up, with some related problems 🤷) |
Yup, max level/bleeding edge :)
I just added everywhere |
Hi, I'm not sure if I should open a new issue but since
I use the factory normally like this:
and the error I'm getting is
So Psalm doesn't expects me to put an array as an argument, and I'm not sure how to fix this or even if I can fix this. Can you help me on this matter please ? EDIT: I use Psalm 5.26.1 btw |
@svianney would you mind opening an issue related to your problem, please? |
I have another problem now that blocks from completely migrating to v2. And there is nothing about this in upgrade guide.
In a factory I have
protected function defaults(): array
and phpstan complains:If I add
/** @return array<mixed> */
abovedefaults
method, I get:if I update return typehint for
defaults
method to: array|callable
to be consistent withZenstruck\Foundry\Factory
, then I get:If I add
@phpstan-import-type Attributes from Factory
and/** @return Attributes */
, then I get:What's the way here to fix this? If return type is defined in the parent interface/class then it should be inferred, at least that works with any other part of the code in our app and phpstan doesn't complain, but now we are here 😑
Edit: ok found that it works if defining return type as
array<string, mixed>
, but that's just nonsense to add this to 100+ factories 😑The text was updated successfully, but these errors were encountered: