From 241c221e4b34a5a9cfab6ddcb2d548c4f90b9353 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 12 Sep 2022 03:54:36 +0200 Subject: [PATCH] Changed: - added missing type-hints - added some missing `@return void` --- src/Security/TwoFactor/Model/RecoveryCode.php | 26 +++++++++++++------ .../TwoFactor/Repository/TrustedBrowser.php | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Security/TwoFactor/Model/RecoveryCode.php b/src/Security/TwoFactor/Model/RecoveryCode.php index 2669ae18e4..b3c197f98e 100644 --- a/src/Security/TwoFactor/Model/RecoveryCode.php +++ b/src/Security/TwoFactor/Model/RecoveryCode.php @@ -35,10 +35,11 @@ class RecoveryCode * Returns the number of code the provided users can still use to replace a TOTP code * * @param int $uid User ID + * * @return int * @throws \Exception */ - public static function countValidForUser($uid) + public static function countValidForUser(int $uid): int { return DBA::count('2fa_recovery_codes', ['uid' => $uid, 'used' => null]); } @@ -46,12 +47,13 @@ class RecoveryCode /** * Checks the provided code is available to use for login by the provided user * - * @param int $uid User ID + * @param int $uid User ID * @param string $code + * * @return bool * @throws \Exception */ - public static function existsForUser($uid, $code) + public static function existsForUser(int $uid, string $code): bool { return DBA::exists('2fa_recovery_codes', ['uid' => $uid, 'code' => $code, 'used' => null]); } @@ -60,10 +62,11 @@ class RecoveryCode * Returns a complete list of all recovery codes for the provided user, including the used status * * @param int $uid User ID + * * @return array * @throws \Exception */ - public static function getListForUser($uid) + public static function getListForUser(int $uid): array { $codesStmt = DBA::select('2fa_recovery_codes', ['code', 'used'], ['uid' => $uid]); @@ -76,10 +79,11 @@ class RecoveryCode * * @param int $uid User ID * @param string $code + * * @return bool * @throws \Exception */ - public static function markUsedForUser($uid, $code) + public static function markUsedForUser(int $uid, string $code): bool { DBA::update('2fa_recovery_codes', ['used' => DateTimeFormat::utcNow()], ['uid' => $uid, 'code' => $code, 'used' => null]); @@ -91,9 +95,11 @@ class RecoveryCode * Generates 12 codes constituted of 2 blocks of 6 characters separated by a dash. * * @param int $uid User ID + * @return void + * * @throws \Exception */ - public static function generateForUser($uid) + public static function generateForUser(int $uid) { $Random = (new Random())->pattern('[a-z0-9]'); @@ -120,9 +126,11 @@ class RecoveryCode * Deletes all the recovery codes for the provided user. * * @param int $uid User ID + * @return void + * * @throws \Exception */ - public static function deleteForUser($uid) + public static function deleteForUser(int $uid) { DBA::delete('2fa_recovery_codes', ['uid' => $uid]); } @@ -131,9 +139,11 @@ class RecoveryCode * Replaces the existing recovery codes for the provided user by a freshly generated set. * * @param int $uid User ID + * @return void + * * @throws \Exception */ - public static function regenerateForUser($uid) + public static function regenerateForUser(int $uid) { self::deleteForUser($uid); self::generateForUser($uid); diff --git a/src/Security/TwoFactor/Repository/TrustedBrowser.php b/src/Security/TwoFactor/Repository/TrustedBrowser.php index a261d92ca0..d913be3c9b 100644 --- a/src/Security/TwoFactor/Repository/TrustedBrowser.php +++ b/src/Security/TwoFactor/Repository/TrustedBrowser.php @@ -143,6 +143,7 @@ class TrustedBrowser /** * @param int $local_user + * * @return bool */ public function removeAllForUser(int $local_user): bool -- 2.39.5