Skip to content

Commit 5259a70

Browse files
authored
Merge pull request #182 from kenjis/fix-Models-return-type
fix: Models return type
2 parents d1af18e + b37c2ab commit 5259a70

File tree

6 files changed

+43
-17
lines changed

6 files changed

+43
-17
lines changed

src/Authentication/Authenticators/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ public function login(User $user): void
604604
$this->completeLogin($user);
605605
}
606606

607-
private function issueRememberMeToken()
607+
private function issueRememberMeToken(): void
608608
{
609609
if ($this->shouldRemember && setting('Auth.sessionConfig')['allowRemembering']) {
610610
$this->rememberUser($this->user);

src/Authentication/Traits/HasAccessTokens.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ public function generateAccessToken(string $name, array $scopes = ['*']): Access
3737
/**
3838
* Delete any access tokens for the given raw token.
3939
*/
40-
public function revokeAccessToken(string $rawToken): bool
40+
public function revokeAccessToken(string $rawToken): void
4141
{
4242
/** @var UserIdentityModel $identityModel */
4343
$identityModel = model(UserIdentityModel::class);
4444

45-
return $identityModel->revokeAccessToken($this, $rawToken);
45+
$identityModel->revokeAccessToken($this, $rawToken);
4646
}
4747

4848
/**
4949
* Revokes all access tokens for this user.
5050
*/
51-
public function revokeAllAccessTokens(): bool
51+
public function revokeAllAccessTokens(): void
5252
{
5353
/** @var UserIdentityModel $identityModel */
5454
$identityModel = model(UserIdentityModel::class);
5555

56-
return $identityModel->revokeAllAccessTokens($this);
56+
$identityModel->revokeAllAccessTokens($this);
5757
}
5858

5959
/**

src/Models/GroupModel.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class GroupModel extends Model
99
{
10+
use CheckQueryReturnTrait;
11+
1012
protected $table = 'auth_groups_users';
1113
protected $primaryKey = 'id';
1214
protected $returnType = 'array';
@@ -37,9 +39,11 @@ public function getForUser(User $user): array
3739
*/
3840
public function deleteAll($userId): void
3941
{
40-
$this->builder()
42+
$return = $this->builder()
4143
->where('user_id', $userId)
4244
->delete();
45+
46+
$this->checkQueryReturn($return);
4347
}
4448

4549
/**
@@ -48,9 +52,11 @@ public function deleteAll($userId): void
4852
*/
4953
public function deleteNotIn($userId, $cache): void
5054
{
51-
$this->builder()
55+
$return = $this->builder()
5256
->where('user_id', $userId)
5357
->whereNotIn('group', $cache)
5458
->delete();
59+
60+
$this->checkQueryReturn($return);
5561
}
5662
}

src/Models/PermissionModel.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class PermissionModel extends Model
99
{
10+
use CheckQueryReturnTrait;
11+
1012
protected $table = 'auth_permissions_users';
1113
protected $primaryKey = 'id';
1214
protected $returnType = 'array';
@@ -37,9 +39,11 @@ public function getForUser(User $user): array
3739
*/
3840
public function deleteAll($userId): void
3941
{
40-
$this->builder()
42+
$return = $this->builder()
4143
->where('user_id', $userId)
4244
->delete();
45+
46+
$this->checkQueryReturn($return);
4347
}
4448

4549
/**
@@ -48,9 +52,11 @@ public function deleteAll($userId): void
4852
*/
4953
public function deleteNotIn($userId, $cache): void
5054
{
51-
$this->builder()
55+
$return = $this->builder()
5256
->where('user_id', $userId)
5357
->whereNotIn('permission', $cache)
5458
->delete();
59+
60+
$this->checkQueryReturn($return);
5561
}
5662
}

src/Models/UserIdentityModel.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ public function createEmailIdentity(User $user, array $credentials): void
5757
/** @var Passwords $passwords */
5858
$passwords = service('passwords');
5959

60-
$this->insert([
60+
$return = $this->insert([
6161
'user_id' => $user->id,
6262
'type' => 'email_password',
6363
'secret' => $credentials['email'],
6464
'secret2' => $passwords->hash($credentials['password']),
6565
]);
66+
67+
$this->checkQueryReturn($return);
6668
}
6769

6870
/**
@@ -116,14 +118,16 @@ public function generateAccessToken(User $user, string $name, array $scopes = ['
116118
{
117119
helper('text');
118120

119-
$this->insert([
121+
$return = $this->insert([
120122
'type' => 'access_token',
121123
'user_id' => $user->id,
122124
'name' => $name,
123125
'secret' => hash('sha256', $rawToken = random_string('crypto', 64)),
124126
'extra' => serialize($scopes),
125127
]);
126128

129+
$this->checkQueryReturn($return);
130+
127131
/** @var AccessToken $token */
128132
$token = $this
129133
->asObject(AccessToken::class)
@@ -243,35 +247,43 @@ public function touchIdentity(UserIdentity $identity): void
243247
{
244248
$identity->last_used_at = date('Y-m-d H:i:s');
245249

246-
$this->save($identity);
250+
$return = $this->save($identity);
251+
252+
$this->checkQueryReturn($return);
247253
}
248254

249255
public function deleteIdentitiesByType(User $user, string $type): void
250256
{
251-
$this->where('user_id', $user->id)
257+
$return = $this->where('user_id', $user->id)
252258
->where('type', $type)
253259
->delete();
260+
261+
$this->checkQueryReturn($return);
254262
}
255263

256264
/**
257265
* Delete any access tokens for the given raw token.
258266
*/
259-
public function revokeAccessToken(User $user, string $rawToken)
267+
public function revokeAccessToken(User $user, string $rawToken): void
260268
{
261-
return $this->where('user_id', $user->id)
269+
$return = $this->where('user_id', $user->id)
262270
->where('type', 'access_token')
263271
->where('secret', hash('sha256', $rawToken))
264272
->delete();
273+
274+
$this->checkQueryReturn($return);
265275
}
266276

267277
/**
268278
* Revokes all access tokens for this user.
269279
*/
270-
public function revokeAllAccessTokens(User $user)
280+
public function revokeAllAccessTokens(User $user): void
271281
{
272-
return $this->where('user_id', $user->id)
282+
$return = $this->where('user_id', $user->id)
273283
->where('type', 'access_token')
274284
->delete();
285+
286+
$this->checkQueryReturn($return);
275287
}
276288

277289
public function fake(Generator &$faker): UserIdentity

src/Models/UserModel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ public function activate(User $user): void
195195
* fields if they've been modified.
196196
*
197197
* @param array|User $data
198+
*
199+
* @TODO can't change the return type to void.
198200
*/
199201
public function save($data): bool
200202
{

0 commit comments

Comments
 (0)