|
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 | | -use LogicException; |
25 | 25 |
|
26 | 26 | /** |
27 | 27 | * @phpstan-consistent-constructor |
@@ -165,9 +165,7 @@ public function addToDefaultGroup(User $user): void |
165 | 165 |
|
166 | 166 | public function fake(Generator &$faker): User |
167 | 167 | { |
168 | | - if (! is_a($this->returnType, User::class, true)) { |
169 | | - throw new LogicException('Return type must be a subclass of ' . User::class); |
170 | | - } |
| 168 | + $this->checkReturnType(); |
171 | 169 |
|
172 | 170 | return new $this->returnType([ |
173 | 171 | 'username' => $faker->unique()->userName(), |
@@ -231,9 +229,7 @@ public function findByCredentials(array $credentials): ?User |
231 | 229 | $password_hash = $data['password_hash']; |
232 | 230 | unset($data['password_hash']); |
233 | 231 |
|
234 | | - if (! is_a($this->returnType, User::class, true)) { |
235 | | - throw new LogicException('Return type must be a subclass of ' . User::class); |
236 | | - } |
| 232 | + $this->checkReturnType(); |
237 | 233 |
|
238 | 234 | $user = new $this->returnType($data); |
239 | 235 | $user->email = $email; |
@@ -392,4 +388,11 @@ public function updateActiveDate(User $user): void |
392 | 388 | ->where('id', $user->id) |
393 | 389 | ->update(); |
394 | 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 | + } |
395 | 398 | } |
0 commit comments