14
14
use Illuminate \Support \Traits \Macroable ;
15
15
use Throwable ;
16
16
17
+ /**
18
+ * @template TModel of \Illuminate\Database\Eloquent\Model
19
+ */
17
20
abstract class Factory
18
21
{
19
22
use ForwardsCalls, Macroable {
@@ -23,7 +26,7 @@ abstract class Factory
23
26
/**
24
27
* The name of the factory's corresponding model.
25
28
*
26
- * @var string
29
+ * @var class- string<\Illuminate\Database\Eloquent\Model|TModel>
27
30
*/
28
31
protected $ model ;
29
32
@@ -137,14 +140,14 @@ public function __construct($count = null,
137
140
/**
138
141
* Define the model's default state.
139
142
*
140
- * @return array
143
+ * @return array<string, mixed>
141
144
*/
142
145
abstract public function definition ();
143
146
144
147
/**
145
148
* Get a new factory instance for the given attributes.
146
149
*
147
- * @param callable|array $attributes
150
+ * @param ( callable(): array<string, mixed>) |array<string, mixed> $attributes
148
151
* @return static
149
152
*/
150
153
public static function new ($ attributes = [])
@@ -176,9 +179,9 @@ public function configure()
176
179
/**
177
180
* Get the raw attributes generated by the factory.
178
181
*
179
- * @param array $attributes
182
+ * @param array<string, mixed> $attributes
180
183
* @param \Illuminate\Database\Eloquent\Model|null $parent
181
- * @return array
184
+ * @return array<int|string, mixed>
182
185
*/
183
186
public function raw ($ attributes = [], ?Model $ parent = null )
184
187
{
@@ -194,8 +197,8 @@ public function raw($attributes = [], ?Model $parent = null)
194
197
/**
195
198
* Create a single model and persist it to the database.
196
199
*
197
- * @param array $attributes
198
- * @return \Illuminate\Database\Eloquent\Model
200
+ * @param array<string, mixed> $attributes
201
+ * @return \Illuminate\Database\Eloquent\Model|TModel
199
202
*/
200
203
public function createOne ($ attributes = [])
201
204
{
@@ -205,8 +208,8 @@ public function createOne($attributes = [])
205
208
/**
206
209
* Create a single model and persist it to the database.
207
210
*
208
- * @param array $attributes
209
- * @return \Illuminate\Database\Eloquent\Model
211
+ * @param array<string, mixed> $attributes
212
+ * @return \Illuminate\Database\Eloquent\Model|TModel
210
213
*/
211
214
public function createOneQuietly ($ attributes = [])
212
215
{
@@ -216,8 +219,8 @@ public function createOneQuietly($attributes = [])
216
219
/**
217
220
* Create a collection of models and persist them to the database.
218
221
*
219
- * @param iterable $records
220
- * @return \Illuminate\Database\Eloquent\Collection
222
+ * @param iterable<int, array<string, mixed>> $records
223
+ * @return \Illuminate\Database\Eloquent\Collection<int, \Illuminate\Database\Eloquent\Model|TModel>
221
224
*/
222
225
public function createMany (iterable $ records )
223
226
{
@@ -231,8 +234,8 @@ public function createMany(iterable $records)
231
234
/**
232
235
* Create a collection of models and persist them to the database.
233
236
*
234
- * @param iterable $records
235
- * @return \Illuminate\Database\Eloquent\Collection
237
+ * @param iterable<int, array<string, mixed>> $records
238
+ * @return \Illuminate\Database\Eloquent\Collection<int, \Illuminate\Database\Eloquent\Model|TModel>
236
239
*/
237
240
public function createManyQuietly (iterable $ records )
238
241
{
@@ -244,9 +247,9 @@ public function createManyQuietly(iterable $records)
244
247
/**
245
248
* Create a collection of models and persist them to the database.
246
249
*
247
- * @param array $attributes
250
+ * @param array<string, mixed> $attributes
248
251
* @param \Illuminate\Database\Eloquent\Model|null $parent
249
- * @return \Illuminate\Database\Eloquent\Collection| \Illuminate\Database\Eloquent\Model
252
+ * @return \Illuminate\Database\Eloquent\Collection<int, \Illuminate\Database\Eloquent\Model|TModel>| \Illuminate\Database\Eloquent\Model|TModel
250
253
*/
251
254
public function create ($ attributes = [], ?Model $ parent = null )
252
255
{
@@ -272,9 +275,9 @@ public function create($attributes = [], ?Model $parent = null)
272
275
/**
273
276
* Create a collection of models and persist them to the database.
274
277
*
275
- * @param array $attributes
278
+ * @param array<string, mixed> $attributes
276
279
* @param \Illuminate\Database\Eloquent\Model|null $parent
277
- * @return \Illuminate\Database\Eloquent\Collection| \Illuminate\Database\Eloquent\Model
280
+ * @return \Illuminate\Database\Eloquent\Collection<int, \Illuminate\Database\Eloquent\Model|TModel>| \Illuminate\Database\Eloquent\Model|TModel
278
281
*/
279
282
public function createQuietly ($ attributes = [], ?Model $ parent = null )
280
283
{
@@ -286,9 +289,9 @@ public function createQuietly($attributes = [], ?Model $parent = null)
286
289
/**
287
290
* Create a callback that persists a model in the database when invoked.
288
291
*
289
- * @param array $attributes
292
+ * @param array<string, mixed> $attributes
290
293
* @param \Illuminate\Database\Eloquent\Model|null $parent
291
- * @return \Closure
294
+ * @return \Closure(): (\Illuminate\Database\Eloquent\Collection<int, \Illuminate\Database\Eloquent\Model|TModel>|\Illuminate\Database\Eloquent\Model|TModel)
292
295
*/
293
296
public function lazy (array $ attributes = [], ?Model $ parent = null )
294
297
{
@@ -334,8 +337,8 @@ protected function createChildren(Model $model)
334
337
/**
335
338
* Make a single instance of the model.
336
339
*
337
- * @param callable|array $attributes
338
- * @return \Illuminate\Database\Eloquent\Model
340
+ * @param ( callable(): array<string, mixed>) |array<string, mixed> $attributes
341
+ * @return \Illuminate\Database\Eloquent\Model|TModel
339
342
*/
340
343
public function makeOne ($ attributes = [])
341
344
{
@@ -345,9 +348,9 @@ public function makeOne($attributes = [])
345
348
/**
346
349
* Create a collection of models.
347
350
*
348
- * @param array $attributes
351
+ * @param array<string, mixed> $attributes
349
352
* @param \Illuminate\Database\Eloquent\Model|null $parent
350
- * @return \Illuminate\Database\Eloquent\Collection| \Illuminate\Database\Eloquent\Model
353
+ * @return \Illuminate\Database\Eloquent\Collection<int, \Illuminate\Database\Eloquent\Model|TModel>| \Illuminate\Database\Eloquent\Model|TModel
351
354
*/
352
355
public function make ($ attributes = [], ?Model $ parent = null )
353
356
{
@@ -465,7 +468,7 @@ protected function expandAttributes(array $definition)
465
468
/**
466
469
* Add a new state transformation to the model definition.
467
470
*
468
- * @param callable|array $state
471
+ * @param ( callable(): array<string, mixed>) |array<string, mixed> $state
469
472
* @return static
470
473
*/
471
474
public function state ($ state )
@@ -523,7 +526,7 @@ protected function guessRelationship(string $related)
523
526
* Define an attached relationship for the model.
524
527
*
525
528
* @param \Illuminate\Database\Eloquent\Factories\Factory|\Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model $factory
526
- * @param callable|array $pivot
529
+ * @param ( callable(): array<string, mixed>) |array<string, mixed> $pivot
527
530
* @param string|null $relationship
528
531
* @return static
529
532
*/
@@ -562,7 +565,7 @@ public function for($factory, $relationship = null)
562
565
/**
563
566
* Add a new "after making" callback to the model definition.
564
567
*
565
- * @param \Closure $callback
568
+ * @param \Closure(\Illuminate\Database\Eloquent\Model|TModel): mixed $callback
566
569
* @return static
567
570
*/
568
571
public function afterMaking (Closure $ callback )
@@ -573,7 +576,7 @@ public function afterMaking(Closure $callback)
573
576
/**
574
577
* Add a new "after creating" callback to the model definition.
575
578
*
576
- * @param \Closure $callback
579
+ * @param \Closure(\Illuminate\Database\Eloquent\Model|TModel): mixed $callback
577
580
* @return static
578
581
*/
579
582
public function afterCreating (Closure $ callback )
@@ -656,8 +659,8 @@ protected function newInstance(array $arguments = [])
656
659
/**
657
660
* Get a new model instance.
658
661
*
659
- * @param array $attributes
660
- * @return \Illuminate\Database\Eloquent\Model
662
+ * @param array<string, mixed> $attributes
663
+ * @return \Illuminate\Database\Eloquent\Model|TModel
661
664
*/
662
665
public function newModel (array $ attributes = [])
663
666
{
@@ -669,7 +672,7 @@ public function newModel(array $attributes = [])
669
672
/**
670
673
* Get the name of the model that is generated by the factory.
671
674
*
672
- * @return string
675
+ * @return class- string<\Illuminate\Database\Eloquent\Model|TModel>
673
676
*/
674
677
public function modelName ()
675
678
{
@@ -689,7 +692,7 @@ public function modelName()
689
692
/**
690
693
* Specify the callback that should be invoked to guess model names based on factory names.
691
694
*
692
- * @param callable $callback
695
+ * @param callable(): class-string<\Illuminate\Database\Eloquent\Model|TModel> $callback
693
696
* @return void
694
697
*/
695
698
public static function guessModelNamesUsing (callable $ callback )
@@ -711,8 +714,8 @@ public static function useNamespace(string $namespace)
711
714
/**
712
715
* Get a new factory instance for the given model name.
713
716
*
714
- * @param string $modelName
715
- * @return static
717
+ * @param class- string<\Illuminate\Database\Eloquent\Model> $modelName
718
+ * @return \Illuminate\Database\Eloquent\Factories\Factory
716
719
*/
717
720
public static function factoryForModel (string $ modelName )
718
721
{
@@ -724,7 +727,7 @@ public static function factoryForModel(string $modelName)
724
727
/**
725
728
* Specify the callback that should be invoked to guess factory names based on dynamic relationship names.
726
729
*
727
- * @param callable $callback
730
+ * @param callable(): class-string<\Illuminate\Database\Eloquent\Model|TModel> $callback
728
731
* @return void
729
732
*/
730
733
public static function guessFactoryNamesUsing (callable $ callback )
@@ -745,8 +748,8 @@ protected function withFaker()
745
748
/**
746
749
* Get the factory name for the given model name.
747
750
*
748
- * @param string $modelName
749
- * @return string
751
+ * @param class- string<\Illuminate\Database\Eloquent\Model> $modelName
752
+ * @return class- string<\Illuminate\Database\Eloquent\Factories\Factory>
750
753
*/
751
754
public static function resolveFactoryName (string $ modelName )
752
755
{
0 commit comments