From c6475c4c5b4c9a4029fb988bcff404f0c3d2042e Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 15 Aug 2022 08:41:34 +0900 Subject: [PATCH 1/6] refactor: add missing return types --- src/Authentication/Authenticators/Session.php | 4 ++-- src/Commands/Setup.php | 2 +- .../Authenticators/AccessTokenAuthenticatorTest.php | 2 +- tests/Controllers/MagicLinkTest.php | 4 ++-- tests/Unit/NothingPersonalValidatorTest.php | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Authentication/Authenticators/Session.php b/src/Authentication/Authenticators/Session.php index 1355d83ec..d2d2f5ee9 100644 --- a/src/Authentication/Authenticators/Session.php +++ b/src/Authentication/Authenticators/Session.php @@ -408,7 +408,7 @@ private function checkUserState(): void /** * Gets identities for action from database, and set session. */ - private function setAuthAction() + private function setAuthAction(): void { // Get identities for action $identities = $this->getIdentitiesForAction(); @@ -711,7 +711,7 @@ private function issueRememberMeToken(): void } } - private function removeRememberCookie() + private function removeRememberCookie(): void { /** @var Response $response */ $response = service('response'); diff --git a/src/Commands/Setup.php b/src/Commands/Setup.php index 7a38ff1e1..6ade052e8 100644 --- a/src/Commands/Setup.php +++ b/src/Commands/Setup.php @@ -247,7 +247,7 @@ private function setupHelper(): void $this->add($file, $check, $pattern, $replace); } - private function setupRoutes() + private function setupRoutes(): void { $file = 'Config/Routes.php'; diff --git a/tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php b/tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php index 2b449ff7d..11b5a36ca 100644 --- a/tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php +++ b/tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php @@ -121,7 +121,7 @@ public function testCheckBadToken(): void $this->assertSame(lang('Auth.badToken'), $result->reason()); } - public function testCheckOldToken() + public function testCheckOldToken(): void { /** @var User $user */ $user = fake(UserModel::class); diff --git a/tests/Controllers/MagicLinkTest.php b/tests/Controllers/MagicLinkTest.php index 1aa14ce81..7c60816cb 100644 --- a/tests/Controllers/MagicLinkTest.php +++ b/tests/Controllers/MagicLinkTest.php @@ -31,7 +31,7 @@ protected function setUp(): void Services::injectMock('routes', $routes); } - public function testAfterLoggedInNotAllowDisplayMagicLink() + public function testAfterLoggedInNotAllowDisplayMagicLink(): void { $this->user->createEmailIdentity([ 'email' => 'foo@example.com', @@ -47,7 +47,7 @@ public function testAfterLoggedInNotAllowDisplayMagicLink() $result->assertRedirectTo(config('Auth')->loginRedirect()); } - public function testShowValidateErrorsInMagicLink() + public function testShowValidateErrorsInMagicLink(): void { $result = $this->post('/login/magic-link', [ 'email' => 'foo@example', diff --git a/tests/Unit/NothingPersonalValidatorTest.php b/tests/Unit/NothingPersonalValidatorTest.php index 891da15ec..cbc6f80ce 100644 --- a/tests/Unit/NothingPersonalValidatorTest.php +++ b/tests/Unit/NothingPersonalValidatorTest.php @@ -152,7 +152,7 @@ public function testIsNotPersonalFalsePositivesCaughtByIsNotSimilar($password): $this->assertNotSame($isNotPersonal, $isNotSimilar); } - public function passwordProvider() + public function passwordProvider(): array { return [ ['JoeTheCaptain'], From 0971d40bec702cacc57abe36409955060023e994 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 15 Aug 2022 08:41:54 +0900 Subject: [PATCH 2/6] docs: add doc comments --- src/Models/UserIdentityModel.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Models/UserIdentityModel.php b/src/Models/UserIdentityModel.php index 38ffe85c9..4e82a904e 100644 --- a/src/Models/UserIdentityModel.php +++ b/src/Models/UserIdentityModel.php @@ -203,6 +203,8 @@ public function getIdentityBySecret(string $type, ?string $secret): ?UserIdentit } /** + * Returns all identities. + * * @return UserIdentity[] */ public function getIdentities(User $user): array @@ -220,6 +222,9 @@ public function getIdentitiesByUserIds(array $userIds): array return $this->whereIn('user_id', $userIds)->orderBy($this->primaryKey)->findAll(); } + /** + * Returns the first identity of the type. + */ public function getIdentityByType(User $user, string $type): ?UserIdentity { return $this->where('user_id', $user->id) @@ -229,6 +234,8 @@ public function getIdentityByType(User $user, string $type): ?UserIdentity } /** + * Returns all identities for the specific types. + * * @param string[] $types * * @return UserIdentity[] From f082905157f5909f094bd7b6fe53dbbee41dc658 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 15 Aug 2022 08:42:15 +0900 Subject: [PATCH 3/6] docs: fix typo in doc comment --- src/Models/UserModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/UserModel.php b/src/Models/UserModel.php index 3c8d24fe7..55f83e0f1 100644 --- a/src/Models/UserModel.php +++ b/src/Models/UserModel.php @@ -222,7 +222,7 @@ public function activate(User $user): void * * @throws ValidationException * - * @retrun true|int|string Insert ID if $returnID is true + * @return int|string|true Insert ID if $returnID is true */ public function insert($data = null, bool $returnID = true) { From a9e74669872d4b8d00c0123fb004f1bb005e0044 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 15 Aug 2022 14:34:19 +0900 Subject: [PATCH 4/6] chore: add void_return for cs-fixer --- .php-cs-fixer.dist.php | 1 + 1 file changed, 1 insertion(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 8eee8d3aa..2446c56f6 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -17,6 +17,7 @@ $overrides = [ 'declare_strict_types' => true, + 'void_return' => true, ]; $options = [ From 2cdf921e7349101d05ddd16efe9cfae1d6118f90 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 15 Aug 2022 14:35:22 +0900 Subject: [PATCH 5/6] refactor: add return type void --- src/Filters/AuthRates.php | 4 +--- src/Filters/ChainAuth.php | 4 +--- src/Filters/SessionAuth.php | 4 +--- src/Filters/TokenAuth.php | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Filters/AuthRates.php b/src/Filters/AuthRates.php index 5843bc4ba..85f93f11f 100644 --- a/src/Filters/AuthRates.php +++ b/src/Filters/AuthRates.php @@ -48,10 +48,8 @@ public function before(RequestInterface $request, $arguments = null) * * @param Response|ResponseInterface $response * @param array|null $arguments - * - * @return void */ - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void { // Nothing required } diff --git a/src/Filters/ChainAuth.php b/src/Filters/ChainAuth.php index 6922a36f2..d30e0e205 100644 --- a/src/Filters/ChainAuth.php +++ b/src/Filters/ChainAuth.php @@ -56,10 +56,8 @@ public function before(RequestInterface $request, $arguments = null) * * @param Response|ResponseInterface $response * @param array|null $arguments - * - * @return void */ - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void { // Nothing required } diff --git a/src/Filters/SessionAuth.php b/src/Filters/SessionAuth.php index 04907a196..ceed5f611 100644 --- a/src/Filters/SessionAuth.php +++ b/src/Filters/SessionAuth.php @@ -60,10 +60,8 @@ public function before(RequestInterface $request, $arguments = null) * * @param Response|ResponseInterface $response * @param array|null $arguments - * - * @return void */ - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void { } } diff --git a/src/Filters/TokenAuth.php b/src/Filters/TokenAuth.php index d910c177f..54ed21bcb 100644 --- a/src/Filters/TokenAuth.php +++ b/src/Filters/TokenAuth.php @@ -57,10 +57,8 @@ public function before(RequestInterface $request, $arguments = null) * * @param Response|ResponseInterface $response * @param array|null $arguments - * - * @return void */ - public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) + public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void { } } From 1de59056f4254021e8560249f05177e29e19f4af Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 15 Aug 2022 14:35:45 +0900 Subject: [PATCH 6/6] docs: add @return --- src/Authentication/Actions/EmailActivator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Authentication/Actions/EmailActivator.php b/src/Authentication/Actions/EmailActivator.php index 75de1606f..39d6529ae 100644 --- a/src/Authentication/Actions/EmailActivator.php +++ b/src/Authentication/Actions/EmailActivator.php @@ -7,6 +7,7 @@ use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\RedirectResponse; +use CodeIgniter\HTTP\Response; use CodeIgniter\Shield\Authentication\Authenticators\Session; use CodeIgniter\Shield\Entities\User; use CodeIgniter\Shield\Exceptions\LogicException; @@ -60,6 +61,8 @@ public function show(): string /** * This method is unused. + * + * @return Response|string */ public function handle(IncomingRequest $request) {