Skip to content
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

[10.x] Fix Factory::afterCreating callable argument type #52335

Merged
merged 1 commit into from
Aug 1, 2024
Merged

[10.x] Fix Factory::afterCreating callable argument type #52335

merged 1 commit into from
Aug 1, 2024

Conversation

villfa
Copy link
Contributor

@villfa villfa commented Jul 31, 2024

The callback passed as an argument to afterCreating() is always invoked with 2 parameters, the 2nd parameter being the parent model (see callAfterCreating()).

Before this change, PHPStan could raise this kind of error:

 Parameter #1 $callback of method Illuminate\Database\Eloquent\Factories\Factory<Illuminate\Database\Eloquent\Model>::afterCreating() expects Closure(Illuminate\Database\Eloquent\Model): mixed, Closure(App\Models\MyModel, mixed): void given.  
 🪪  argument.type                                                                                                                                                                                                                                  
 💡 Parameter #2 $parent of passed callable is required but accepting callable does not have that parameter. It will be called without it. 

Here're some reproducers:

@taylorotwell taylorotwell merged commit db768e4 into laravel:10.x Aug 1, 2024
24 checks passed
@villfa villfa deleted the fix/factory-after-creating branch August 1, 2024 13:30
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.

2 participants