From 09368e7cf5395ad4f9d93867b63e22a458f702c1 Mon Sep 17 00:00:00 2001 From: J0WI Date: Wed, 14 Apr 2021 17:05:19 +0200 Subject: [PATCH] 2FA backupcodes: add strict typing Signed-off-by: J0WI --- apps/twofactor_backupcodes/appinfo/routes.php | 3 +++ apps/twofactor_backupcodes/lib/Activity/Provider.php | 5 ++++- .../lib/Controller/SettingsController.php | 5 ++++- apps/twofactor_backupcodes/lib/Db/BackupCode.php | 3 +++ .../lib/Db/BackupCodeMapper.php | 9 ++++++--- .../lib/Migration/Version1002Date20170607104347.php | 3 +++ .../lib/Migration/Version1002Date20170607113030.php | 3 +++ .../lib/Migration/Version1002Date20170919123342.php | 3 +++ .../lib/Migration/Version1002Date20170926101419.php | 3 +++ .../lib/Service/BackupCodeStorage.php | 12 ++++++++---- apps/twofactor_backupcodes/templates/challenge.php | 3 +++ apps/twofactor_backupcodes/templates/personal.php | 2 ++ .../tests/Db/BackupCodeMapperTest.php | 3 +++ .../tests/Service/BackupCodeStorageTest.php | 3 +++ .../tests/Unit/Activity/ProviderTest.php | 3 +++ .../tests/Unit/Controller/SettingsControllerTest.php | 3 +++ .../tests/Unit/Provider/BackupCodesProviderTest.php | 3 +++ .../tests/Unit/Service/BackupCodeStorageTest.php | 3 +++ 18 files changed, 63 insertions(+), 9 deletions(-) diff --git a/apps/twofactor_backupcodes/appinfo/routes.php b/apps/twofactor_backupcodes/appinfo/routes.php index 8adc9c3901e..243ffb1d1f8 100644 --- a/apps/twofactor_backupcodes/appinfo/routes.php +++ b/apps/twofactor_backupcodes/appinfo/routes.php @@ -1,4 +1,7 @@ * @@ -53,7 +56,7 @@ class Provider implements IProvider { $this->l10n = $l10n; } - public function parse($language, IEvent $event, IEvent $previousEvent = null) { + public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { if ($event->getApp() !== 'twofactor_backupcodes') { throw new InvalidArgumentException(); } diff --git a/apps/twofactor_backupcodes/lib/Controller/SettingsController.php b/apps/twofactor_backupcodes/lib/Controller/SettingsController.php index 04ec2e19e95..432a89bd25a 100644 --- a/apps/twofactor_backupcodes/lib/Controller/SettingsController.php +++ b/apps/twofactor_backupcodes/lib/Controller/SettingsController.php @@ -1,4 +1,7 @@ userSession->getUser(); $codes = $this->storage->createCodes($user); return new JSONResponse([ diff --git a/apps/twofactor_backupcodes/lib/Db/BackupCode.php b/apps/twofactor_backupcodes/lib/Db/BackupCode.php index 8b173890e3c..645c246ec6d 100644 --- a/apps/twofactor_backupcodes/lib/Db/BackupCode.php +++ b/apps/twofactor_backupcodes/lib/Db/BackupCode.php @@ -1,4 +1,7 @@ db->getQueryBuilder(); @@ -56,14 +59,14 @@ class BackupCodeMapper extends QBMapper { /** * @param IUser $user */ - public function deleteCodes(IUser $user) { + public function deleteCodes(IUser $user): void { $this->deleteCodesByUserId($user->getUID()); } /** * @param string $uid */ - public function deleteCodesByUserId($uid) { + public function deleteCodesByUserId(string $uid): void { /* @var IQueryBuilder $qb */ $qb = $this->db->getQueryBuilder(); diff --git a/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607104347.php b/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607104347.php index 68f0d5b3421..ffbb8023007 100644 --- a/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607104347.php +++ b/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607104347.php @@ -1,4 +1,7 @@ * diff --git a/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607113030.php b/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607113030.php index 771c74853d1..cfd76fefd00 100644 --- a/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607113030.php +++ b/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607113030.php @@ -1,4 +1,7 @@ * diff --git a/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170919123342.php b/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170919123342.php index dc42ad2545c..97863583ad2 100644 --- a/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170919123342.php +++ b/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170919123342.php @@ -1,4 +1,7 @@ * diff --git a/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170926101419.php b/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170926101419.php index f8df9e69844..12854f6ff0b 100644 --- a/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170926101419.php +++ b/apps/twofactor_backupcodes/lib/Migration/Version1002Date20170926101419.php @@ -1,4 +1,7 @@ mapper->getBackupCodes($user); return count($codes) > 0; } @@ -99,7 +103,7 @@ class BackupCodeStorage { * @param IUser $user * @return array */ - public function getBackupCodesState(IUser $user) { + public function getBackupCodesState(IUser $user): array { $codes = $this->mapper->getBackupCodes($user); $total = count($codes); $used = 0; @@ -120,7 +124,7 @@ class BackupCodeStorage { * @param string $code * @return bool */ - public function validateCode(IUser $user, $code) { + public function validateCode(IUser $user, string $code): bool { $dbCodes = $this->mapper->getBackupCodes($user); foreach ($dbCodes as $dbCode) { diff --git a/apps/twofactor_backupcodes/templates/challenge.php b/apps/twofactor_backupcodes/templates/challenge.php index d269fb4b47e..e4792c8256a 100644 --- a/apps/twofactor_backupcodes/templates/challenge.php +++ b/apps/twofactor_backupcodes/templates/challenge.php @@ -1,4 +1,7 @@ diff --git a/apps/twofactor_backupcodes/templates/personal.php b/apps/twofactor_backupcodes/templates/personal.php index c57a589a26a..12def69bbed 100644 --- a/apps/twofactor_backupcodes/templates/personal.php +++ b/apps/twofactor_backupcodes/templates/personal.php @@ -1,5 +1,7 @@ diff --git a/apps/twofactor_backupcodes/tests/Db/BackupCodeMapperTest.php b/apps/twofactor_backupcodes/tests/Db/BackupCodeMapperTest.php index 17155c266de..5617138f7b1 100644 --- a/apps/twofactor_backupcodes/tests/Db/BackupCodeMapperTest.php +++ b/apps/twofactor_backupcodes/tests/Db/BackupCodeMapperTest.php @@ -1,4 +1,7 @@ * diff --git a/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php b/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php index fc085472529..a9cb7b8b2dd 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Controller/SettingsControllerTest.php @@ -1,4 +1,7 @@