Skip to content

Commit 34806e5

Browse files
authored
create checkreturnType method
1 parent f9d5dd1 commit 34806e5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Models/UserModel.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
use CodeIgniter\Shield\Entities\User;
2020
use CodeIgniter\Shield\Entities\UserIdentity;
2121
use CodeIgniter\Shield\Exceptions\InvalidArgumentException;
22+
use CodeIgniter\Shield\Exceptions\LogicException;
2223
use CodeIgniter\Shield\Exceptions\ValidationException;
2324
use Faker\Generator;
24-
use LogicException;
2525

2626
/**
2727
* @phpstan-consistent-constructor
@@ -165,9 +165,7 @@ public function addToDefaultGroup(User $user): void
165165

166166
public function fake(Generator &$faker): User
167167
{
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();
171169

172170
return new $this->returnType([
173171
'username' => $faker->unique()->userName(),
@@ -231,9 +229,7 @@ public function findByCredentials(array $credentials): ?User
231229
$password_hash = $data['password_hash'];
232230
unset($data['password_hash']);
233231

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();
237233

238234
$user = new $this->returnType($data);
239235
$user->email = $email;
@@ -392,4 +388,11 @@ public function updateActiveDate(User $user): void
392388
->where('id', $user->id)
393389
->update();
394390
}
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+
}
395398
}

0 commit comments

Comments
 (0)