Skip to content

Commit ecd95a9

Browse files
committed
refactor: replace Authenticatable with User
1 parent 825a6e6 commit ecd95a9

File tree

7 files changed

+17
-21
lines changed

7 files changed

+17
-21
lines changed

src/Auth.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
/**
1414
* AuthenticatorInterface:
1515
*
16-
* @method Result attempt(array $credentials)
17-
* @method Result check(array $credentials)
18-
* @method Authenticatable|null getUser()
19-
* @method bool loggedIn()
20-
* @method bool login(Authenticatable $user)
21-
* @method void loginById($userId)
22-
* @method bool logout()
23-
* @method void recordActive()
16+
* @method Result attempt(array $credentials)
17+
* @method Result check(array $credentials)
18+
* @method User|null getUser()
19+
* @method bool loggedIn()
20+
* @method bool login(User $user)
21+
* @method void loginById($userId)
22+
* @method bool logout()
23+
* @method void recordActive()
2424
*
2525
* Authenticators\Session:
2626
* @method $this remember(bool $shouldRemember = true)

src/Authentication/Authenticators/AccessTokens.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use CodeIgniter\Shield\Authentication\AuthenticationException;
88
use CodeIgniter\Shield\Authentication\AuthenticatorInterface;
99
use CodeIgniter\Shield\Entities\User;
10-
use CodeIgniter\Shield\Interfaces\Authenticatable;
1110
use CodeIgniter\Shield\Interfaces\UserProvider;
1211
use CodeIgniter\Shield\Models\LoginModel;
1312
use CodeIgniter\Shield\Models\UserIdentityModel;
@@ -227,7 +226,7 @@ public function getBearerToken(): ?string
227226
*/
228227
public function recordActive(): void
229228
{
230-
if (! $this->user instanceof Authenticatable) {
229+
if (! $this->user instanceof User) {
231230
throw new InvalidArgumentException(self::class . '::recordActive() requires logged in user before calling.');
232231
}
233232

src/Authentication/Authenticators/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public function getUser(): ?User
290290
*/
291291
public function recordActive(): void
292292
{
293-
if (! $this->user instanceof Authenticatable) {
293+
if (! $this->user instanceof User) {
294294
throw new InvalidArgumentException(self::class . '::recordActive() requires logged in user before calling.');
295295
}
296296

src/Authentication/Traits/UserProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace CodeIgniter\Shield\Authentication\Traits;
44

55
use CodeIgniter\Shield\Entities\User;
6-
use CodeIgniter\Shield\Interfaces\Authenticatable;
76

87
/**
98
* Intended to be used with UserProvider (UserModel).
@@ -70,7 +69,7 @@ public function findByCredentials(array $credentials): ?User
7069
*
7170
* @param int|string $id
7271
*/
73-
public function findByRememberToken($id, string $token): ?Authenticatable
72+
public function findByRememberToken($id, string $token): ?User
7473
{
7574
return $this->where([
7675
'id' => $id,

src/Interfaces/UserProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public function findByCredentials(array $credentials): ?User;
2525
*
2626
* @param int|string $id
2727
*/
28-
public function findByRememberToken($id, string $token): ?Authenticatable;
28+
public function findByRememberToken($id, string $token): ?User;
2929

3030
/**
3131
* Given a User object, will update the record
3232
* in the database. This is often a User entity
3333
* that already has the correct values set.
3434
*/
35-
public function save(Authenticatable $data): bool;
35+
public function save(User $data): bool;
3636
}

src/Result.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace CodeIgniter\Shield;
44

55
use CodeIgniter\Shield\Entities\User;
6-
use CodeIgniter\Shield\Interfaces\Authenticatable;
76

87
class Result
98
{
@@ -19,13 +18,13 @@ class Result
1918
/**
2019
* Extra information.
2120
*
22-
* @var Authenticatable|string|null `Authenticatable` when successful. Suggestion strings when fails.
21+
* @var string|User|null `User` when successful. Suggestion strings when fails.
2322
*/
2423
protected $extraInfo;
2524

2625
/**
27-
* @phpstan-param array{success: bool, reason?: string|null, extraInfo?: string|Authenticatable} $details
28-
* @psalm-param array{success: bool, reason?: string|null, extraInfo?: string|Authenticatable} $details
26+
* @phpstan-param array{success: bool, reason?: string|null, extraInfo?: string|User} $details
27+
* @psalm-param array{success: bool, reason?: string|null, extraInfo?: string|User} $details
2928
*/
3029
public function __construct(array $details)
3130
{

src/Test/AuthenticationTesting.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace CodeIgniter\Shield\Test;
44

55
use CodeIgniter\Shield\Entities\User;
6-
use CodeIgniter\Shield\Interfaces\Authenticatable;
76

87
/**
98
* Trait AuthenticationTesting
@@ -17,7 +16,7 @@ trait AuthenticationTesting
1716
*
1817
* @return $this
1918
*/
20-
public function actingAs(Authenticatable $user): self
19+
public function actingAs(User $user): self
2120
{
2221
// Ensure the helper is loaded during tests.
2322
helper('auth');

0 commit comments

Comments
 (0)