Skip to content

Commit 161098d

Browse files
authored
Makes HasFactory generic (#39171)
1 parent 40e6536 commit 161098d

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait HasFactory
99
*
1010
* @param callable|array|int|null $count
1111
* @param callable|array $state
12-
* @return \Illuminate\Database\Eloquent\Factories\Factory
12+
* @return \Illuminate\Database\Eloquent\Factories\Factory<static>
1313
*/
1414
public static function factory($count = null, $state = [])
1515
{
@@ -23,7 +23,7 @@ public static function factory($count = null, $state = [])
2323
/**
2424
* Create a new factory instance for the model.
2525
*
26-
* @return \Illuminate\Database\Eloquent\Factories\Factory
26+
* @return \Illuminate\Database\Eloquent\Factories\Factory<static>
2727
*/
2828
protected static function newFactory()
2929
{

types/Autoload.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
use Illuminate\Database\Eloquent\Factories\HasFactory;
4+
use Illuminate\Foundation\Auth\User as Authenticatable;
5+
6+
class User extends Authenticatable
7+
{
8+
use HasFactory;
9+
}

types/Database/Eloquent/Collection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
<?php
22

3-
use Illuminate\Foundation\Auth\User as Authenticatable;
43
use function PHPStan\Testing\assertType;
54

6-
class User extends Authenticatable
7-
{
8-
}
9-
105
$collection = User::all();
116
assertType('Illuminate\Database\Eloquent\Collection<int, User>', $collection);
127

types/Database/Eloquent/Factories/Factory.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
<?php
22

33
use Illuminate\Database\Eloquent\Factories\Factory;
4-
use Illuminate\Foundation\Auth\User as Authenticatable;
54
use function PHPStan\Testing\assertType;
65

7-
class User extends Authenticatable
8-
{
9-
}
10-
116
/**
127
* @extends Illuminate\Database\Eloquent\Factories\Factory<User>
138
*/

types/Database/Eloquent/Model.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
use function PHPStan\Testing\assertType;
4+
5+
$factory = User::factory();
6+
assertType('Illuminate\Database\Eloquent\Factories\Factory<User>', $factory);

types/Support/Collection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<?php
22

33
use Illuminate\Contracts\Support\Arrayable;
4-
use Illuminate\Foundation\Auth\User as Authenticatable;
54
use Illuminate\Support\Collection;
65
use function PHPStan\Testing\assertType;
76

8-
class User extends Authenticatable
9-
{
10-
}
11-
127
$collection = collect([new User]);
138
/** @var Arrayable<int, User> $arrayable */
149
$arrayable = [];

0 commit comments

Comments
 (0)