Skip to content

Commit 177808c

Browse files
committed
refactor: add return type
1 parent a77d351 commit 177808c

32 files changed

+166
-180
lines changed

src/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function routes(RouteCollection &$routes, array $config = []): void
102102
{
103103
$authRoutes = config('AuthRoutes')->routes;
104104

105-
$routes->group('/', ['namespace' => 'CodeIgniter\Shield\Controllers'], static function (RouteCollection $routes) use ($authRoutes, $config) {
105+
$routes->group('/', ['namespace' => 'CodeIgniter\Shield\Controllers'], static function (RouteCollection $routes) use ($authRoutes, $config): void {
106106
foreach ($authRoutes as $name => $row) {
107107
if (! isset($config['except']) || (isset($config['except']) && ! in_array($name, $config['except'], true))) {
108108
foreach ($row as $params) {

src/Authentication/Actions/Email2FA.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function afterLogin(User $user): void
115115
$this->createIdentity($user);
116116
}
117117

118-
private function createIdentity(User $user)
118+
private function createIdentity(User $user): void
119119
{
120120
/** @var UserIdentityModel $identityModel */
121121
$identityModel = model(UserIdentityModel::class);

src/Authentication/AuthenticationException.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,17 @@ public static function forNoEntityProvided(): self
3535
/**
3636
* Fires when no minimumPasswordLength has been set
3737
* in the Auth config file.
38-
*
39-
* @return self
4038
*/
41-
public static function forUnsetPasswordLength()
39+
public static function forUnsetPasswordLength(): self
4240
{
4341
return new self(lang('Auth.unsetPasswordLength'), 500);
4442
}
4543

4644
/**
4745
* When the cURL request (to Have I Been Pwned) in PwnedValidator
4846
* throws a HTTPException it is re-thrown as this one
49-
*
50-
* @return self
5147
*/
52-
public static function forHIBPCurlFail(HTTPException $e)
48+
public static function forHIBPCurlFail(HTTPException $e): self
5349
{
5450
return new self($e->getMessage(), $e->getCode(), $e);
5551
}

src/Authentication/Authenticators/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ private function hashValidator(string $validator): string
810810
return hash('sha256', $validator);
811811
}
812812

813-
private function refreshRememberMeToken(stdClass $token)
813+
private function refreshRememberMeToken(stdClass $token): void
814814
{
815815
// Update validator.
816816
$validator = bin2hex(random_bytes(20));

src/Authentication/Passwords/NothingPersonalValidator.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ public function check(string $password, ?User $user = null): Result
4949
*
5050
* isNotPersonal() returns true if no personal information can be found, or false
5151
* if such info is found.
52-
*
53-
* @return bool
5452
*/
55-
protected function isNotPersonal(string $password, ?User $user)
53+
protected function isNotPersonal(string $password, ?User $user): bool
5654
{
5755
$userName = \strtolower($user->username);
5856
$email = \strtolower($user->email);
@@ -150,10 +148,8 @@ protected function isNotPersonal(string $password, ?User $user)
150148
*
151149
* A $maxSimilarity value of 0 (zero) returns true without making a comparison.
152150
* In other words, 0 (zero) turns off similarity testing.
153-
*
154-
* @return bool
155151
*/
156-
protected function isNotSimilar(string $password, ?User $user)
152+
protected function isNotSimilar(string $password, ?User $user): bool
157153
{
158154
$maxSimilarity = (float) $this->config->maxSimilarity;
159155
// sanity checking - working range 1-100, 0 is off
@@ -183,12 +179,8 @@ protected function isNotSimilar(string $password, ?User $user)
183179
*
184180
* Replaces all non-word characters and underscores in $str with a space.
185181
* Then it explodes that result using the space for a delimiter.
186-
*
187-
* @param string $str
188-
*
189-
* @return array
190182
*/
191-
protected function strip_explode($str)
183+
protected function strip_explode(string $str): array
192184
{
193185
$stripped = \preg_replace('/[\W_]+/', ' ', $str);
194186
$parts = \explode(' ', \trim($stripped));

src/Models/RememberModel.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ public function rememberUser(User $user, string $selector, string $hashedValidat
4242

4343
/**
4444
* Returns the remember-me token info for a given selector.
45-
*
46-
* @return stdClass|null
4745
*/
48-
public function getRememberToken(string $selector)
46+
public function getRememberToken(string $selector): ?stdClass
4947
{
5048
return $this->where('selector', $selector)
5149
->get()

tests/Authentication/AccessTokenTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
*/
1111
final class AccessTokenTest extends DatabaseTestCase
1212
{
13-
public function testCanNoScopes()
13+
public function testCanNoScopes(): void
1414
{
1515
$token = new AccessToken();
1616

1717
$this->assertFalse($token->can('foo'));
1818
}
1919

20-
public function testCanWildcard()
20+
public function testCanWildcard(): void
2121
{
2222
$token = new AccessToken([
2323
'extra' => ['*'],
@@ -27,7 +27,7 @@ public function testCanWildcard()
2727
$this->assertTrue($token->can('bar'));
2828
}
2929

30-
public function testCanSuccess()
30+
public function testCanSuccess(): void
3131
{
3232
$token = new AccessToken([
3333
'extra' => ['foo'],
@@ -37,14 +37,14 @@ public function testCanSuccess()
3737
$this->assertFalse($token->can('bar'));
3838
}
3939

40-
public function testCantNoScopes()
40+
public function testCantNoScopes(): void
4141
{
4242
$token = new AccessToken();
4343

4444
$this->assertTrue($token->cant('foo'));
4545
}
4646

47-
public function testCantWildcard()
47+
public function testCantWildcard(): void
4848
{
4949
$token = new AccessToken([
5050
'extra' => ['*'],
@@ -54,7 +54,7 @@ public function testCantWildcard()
5454
$this->assertFalse($token->cant('bar'));
5555
}
5656

57-
public function testCantSuccess()
57+
public function testCantSuccess(): void
5858
{
5959
$token = new AccessToken([
6060
'extra' => ['foo'],

tests/Authentication/AuthHelperTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,35 @@ protected function setUp(): void
3131
$this->setPrivateProperty(auth(), 'alias', null);
3232
}
3333

34-
public function testAuthReturnsDefaultAuthenticator()
34+
public function testAuthReturnsDefaultAuthenticator(): void
3535
{
3636
$authenticatorClassname = config('Auth')->authenticators[config('Auth')->defaultAuthenticator];
3737

3838
$this->assertInstanceOf($authenticatorClassname, auth()->getAuthenticator());
3939
}
4040

41-
public function testAuthReturnsSpecifiedAuthenticator()
41+
public function testAuthReturnsSpecifiedAuthenticator(): void
4242
{
4343
$authenticatorClassname = config('Auth')->authenticators['tokens'];
4444

4545
$this->assertInstanceOf($authenticatorClassname, auth('tokens')->getAuthenticator());
4646
}
4747

48-
public function testAuthThrowsWithInvalidAuthenticator()
48+
public function testAuthThrowsWithInvalidAuthenticator(): void
4949
{
5050
$this->expectException(AuthenticationException::class);
5151
$this->expectExceptionMessage(lang('Auth.unknownAuthenticator', ['foo']));
5252

5353
auth('foo')->user();
5454
}
5555

56-
public function testUserIdReturnsNull()
56+
public function testUserIdReturnsNull(): void
5757
{
5858
$this->assertFalse(auth()->loggedIn());
5959
$this->assertNull(user_id());
6060
}
6161

62-
public function testUserIdReturnsId()
62+
public function testUserIdReturnsId(): void
6363
{
6464
$user = fake(UserModel::class, ['id' => 1]);
6565
$this->setPrivateProperty(auth()->getAuthenticator(), 'user', $user);

tests/Authentication/AuthenticationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ protected function setUp(): void
2525
$this->auth->setProvider(new UserModel());
2626
}
2727

28-
public function testThrowsOnUnknownAuthenticator()
28+
public function testThrowsOnUnknownAuthenticator(): void
2929
{
3030
$this->expectException(AuthenticationException::class);
3131
$this->expectExceptionMessage(lang('Auth.unknownAuthenticator', ['foo']));
3232

3333
$this->auth->factory('foo');
3434
}
3535

36-
public function testFactoryLoadsDefault()
36+
public function testFactoryLoadsDefault(): void
3737
{
3838
$shield1 = $this->auth->factory();
3939
$shield2 = $this->auth->factory('session');

tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function setUp(): void
3737
Services::injectMock('events', new MockEvents());
3838
}
3939

40-
public function testLogin()
40+
public function testLogin(): void
4141
{
4242
$user = fake(UserModel::class);
4343

@@ -48,7 +48,7 @@ public function testLogin()
4848
$this->assertSame($user->id, $this->auth->getUser()->id);
4949
}
5050

51-
public function testLogout()
51+
public function testLogout(): void
5252
{
5353
// this one's a little odd since it's stateless, but roll with it...
5454
$user = fake(UserModel::class);
@@ -60,7 +60,7 @@ public function testLogout()
6060
$this->assertNull($this->auth->getUser());
6161
}
6262

63-
public function testLoginByIdNoToken()
63+
public function testLoginByIdNoToken(): void
6464
{
6565
$user = fake(UserModel::class);
6666

@@ -72,7 +72,7 @@ public function testLoginByIdNoToken()
7272
$this->assertNull($this->auth->getUser()->currentAccessToken());
7373
}
7474

75-
public function testLoginByIdWithToken()
75+
public function testLoginByIdWithToken(): void
7676
{
7777
/** @var User $user */
7878
$user = fake(UserModel::class);
@@ -87,7 +87,7 @@ public function testLoginByIdWithToken()
8787
$this->assertSame($token->id, $this->auth->getUser()->currentAccessToken()->id);
8888
}
8989

90-
public function testLoginByIdWithMultipleTokens()
90+
public function testLoginByIdWithMultipleTokens(): void
9191
{
9292
/** @var User $user */
9393
$user = fake(UserModel::class);
@@ -103,15 +103,15 @@ public function testLoginByIdWithMultipleTokens()
103103
$this->assertSame($token1->id, $this->auth->getUser()->currentAccessToken()->id);
104104
}
105105

106-
public function testCheckNoToken()
106+
public function testCheckNoToken(): void
107107
{
108108
$result = $this->auth->check([]);
109109

110110
$this->assertFalse($result->isOK());
111111
$this->assertSame(lang('Auth.noToken'), $result->reason());
112112
}
113113

114-
public function testCheckBadToken()
114+
public function testCheckBadToken(): void
115115
{
116116
$result = $this->auth->check(['token' => 'abc123']);
117117

@@ -135,7 +135,7 @@ public function testCheckOldToken()
135135
$this->assertSame(lang('Auth.oldToken'), $result->reason());
136136
}
137137

138-
public function testCheckSuccess()
138+
public function testCheckSuccess(): void
139139
{
140140
/** @var User $user */
141141
$user = fake(UserModel::class);
@@ -157,7 +157,7 @@ public function testCheckSuccess()
157157
$this->assertNotEmpty($updatedToken->last_used_at);
158158
}
159159

160-
public function testAttemptCannotFindUser()
160+
public function testAttemptCannotFindUser(): void
161161
{
162162
$result = $this->auth->attempt([
163163
'token' => 'abc123',
@@ -175,7 +175,7 @@ public function testAttemptCannotFindUser()
175175
]);
176176
}
177177

178-
public function testAttemptSuccess()
178+
public function testAttemptSuccess(): void
179179
{
180180
/** @var User $user */
181181
$user = fake(UserModel::class);
@@ -203,7 +203,7 @@ public function testAttemptSuccess()
203203
]);
204204
}
205205

206-
protected function setRequestHeader(string $token)
206+
protected function setRequestHeader(string $token): void
207207
{
208208
$request = service('request');
209209
$request->setHeader('Authorization', 'Bearer ' . $token);

0 commit comments

Comments
 (0)