File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 19
19
use CodeIgniter \Shield \Entities \User ;
20
20
use CodeIgniter \Shield \Entities \UserIdentity ;
21
21
use CodeIgniter \Shield \Exceptions \InvalidArgumentException ;
22
+ use CodeIgniter \Shield \Exceptions \LogicException ;
22
23
use CodeIgniter \Shield \Exceptions \ValidationException ;
23
24
use Faker \Generator ;
24
25
@@ -164,7 +165,9 @@ public function addToDefaultGroup(User $user): void
164
165
165
166
public function fake (Generator &$ faker ): User
166
167
{
167
- return new User ([
168
+ $ this ->checkReturnType ();
169
+
170
+ return new $ this ->returnType ([
168
171
'username ' => $ faker ->unique ()->userName (),
169
172
'active ' => true ,
170
173
]);
@@ -226,7 +229,9 @@ public function findByCredentials(array $credentials): ?User
226
229
$ password_hash = $ data ['password_hash ' ];
227
230
unset($ data ['password_hash ' ]);
228
231
229
- $ user = new User ($ data );
232
+ $ this ->checkReturnType ();
233
+
234
+ $ user = new $ this ->returnType ($ data );
230
235
$ user ->email = $ email ;
231
236
$ user ->password_hash = $ password_hash ;
232
237
$ user ->syncOriginal ();
@@ -383,4 +388,11 @@ public function updateActiveDate(User $user): void
383
388
->where ('id ' , $ user ->id )
384
389
->update ();
385
390
}
391
+
392
+ private function checkReturnType (): void
393
+ {
394
+ if (! is_a ($ this ->returnType , User::class, true )) {
395
+ throw new LogicException ('Return type must be a subclass of ' . User::class);
396
+ }
397
+ }
386
398
}
You can’t perform that action at this time.
0 commit comments