Skip to content

Commit 414e244

Browse files
committed
Correct types on factory state() method
1 parent 89e43ae commit 414e244

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Illuminate/Database/Eloquent/Factories/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ protected function expandAttributes(array $definition)
469469
/**
470470
* Add a new state transformation to the model definition.
471471
*
472-
* @param (callable(array<string, mixed>): array<string, mixed>)|array<string, mixed> $state
472+
* @param (callable(array<string, mixed>, \Illuminate\Database\Eloquent\Model|null=): array<string, mixed>)|array<string, mixed> $state
473473
* @return static
474474
*/
475475
public function state($state)

types/Database/Eloquent/Factories/Factory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,15 @@ public function definition()
141141
}));
142142

143143
assertType('UserFactory', $factory->state(['string' => 'string']));
144-
assertType('UserFactory', $factory->state(function () {
144+
assertType('UserFactory', $factory->state(function ($attributes) {
145+
assertType('array<string, mixed>', $attributes);
146+
147+
return ['string' => 'string'];
148+
}));
149+
assertType('UserFactory', $factory->state(function ($attributes, $model) {
150+
assertType('array<string, mixed>', $attributes);
151+
assertType('Illuminate\Database\Eloquent\Model|null', $model);
152+
145153
return ['string' => 'string'];
146154
}));
147155

0 commit comments

Comments
 (0)