From a44e2a0d0c35c63a94abfc482955c23d9d823e4a Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Mon, 14 Nov 2022 15:04:16 +0100 Subject: Add visibility (#4232) * Add visibility * Tab use * Update app/Models/Days.php Co-authored-by: Alexandre Alapetite --- app/Models/Days.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/Models/Days.php') diff --git a/app/Models/Days.php b/app/Models/Days.php index 2d770c30b..de98c5ec8 100644 --- a/app/Models/Days.php +++ b/app/Models/Days.php @@ -1,7 +1,7 @@ Date: Fri, 3 Feb 2023 14:35:59 +0100 Subject: Type hinting and doc (#5063) * Type hinting and doc * fix cs * Remove declare strict * Remove declare strict * Pass PHPStan level 9 Revert too boolean syntax * Minor wording * Fix revert typo --------- Co-authored-by: Luc Co-authored-by: Alexandre Alapetite --- app/Models/Days.php | 2 ++ app/Models/View.php | 1 + app/Utils/feverUtil.php | 36 +++++++++++++++--------------------- app/Utils/passwordUtil.php | 19 ++++++++----------- lib/lib_install.php | 2 -- 5 files changed, 26 insertions(+), 34 deletions(-) (limited to 'app/Models/Days.php') diff --git a/app/Models/Days.php b/app/Models/Days.php index de98c5ec8..d3f1ba075 100644 --- a/app/Models/Days.php +++ b/app/Models/Days.php @@ -1,5 +1,7 @@ salt); return self::FEVER_PATH . '/.key-' . $salt . '-' . $feverKey . '.txt'; } /** * Update the fever key of a user. - * - * @param string $username - * @param string $passwordPlain * @return string|false the Fever key, or false if the update failed */ - public static function updateKey($username, $passwordPlain) { - $ok = self::checkFeverPath(); - if (!$ok) { + public static function updateKey(string $username, string $passwordPlain) { + if (!self::checkFeverPath()) { return false; } @@ -48,22 +44,20 @@ class FreshRSS_fever_Util { $feverKey = strtolower(md5("{$username}:{$passwordPlain}")); $feverKeyPath = self::getKeyPath($feverKey); - $res = file_put_contents($feverKeyPath, $username); - if ($res !== false) { + $result = file_put_contents($feverKeyPath, $username); + if (is_int($result) && $result > 0) { return $feverKey; - } else { - Minz_Log::warning('Could not save Fever API credentials. Unknown error.', ADMIN_LOG); - return false; } + Minz_Log::warning('Could not save Fever API credentials. Unknown error.', ADMIN_LOG); + return false; } /** * Delete the Fever key of a user. * - * @param string $username - * @return boolean true if the deletion succeeded, else false. + * @return bool true if the deletion succeeded, else false. */ - public static function deleteKey($username) { + public static function deleteKey(string $username) { $userConfig = get_user_configuration($username); if ($userConfig === null) { return false; diff --git a/app/Utils/passwordUtil.php b/app/Utils/passwordUtil.php index cff97d2bc..0edead213 100644 --- a/app/Utils/passwordUtil.php +++ b/app/Utils/passwordUtil.php @@ -3,26 +3,25 @@ class FreshRSS_password_Util { // Will also have to be computed client side on mobile devices, // so do not use a too high cost - const BCRYPT_COST = 9; + public const BCRYPT_COST = 9; /** * Return a hash of a plain password, using BCRYPT - * - * @param string $passwordPlain - * @return string */ - public static function hash($passwordPlain) { + public static function hash(string $passwordPlain): string { $passwordHash = password_hash( $passwordPlain, PASSWORD_BCRYPT, array('cost' => self::BCRYPT_COST) ); - $passwordPlain = ''; // Compatibility with bcrypt.js $passwordHash = preg_replace('/^\$2[xy]\$/', '\$2a\$', $passwordHash); - return $passwordHash == '' ? '' : $passwordHash; + if ($passwordHash === '' || $passwordHash === null) { + return ''; + } + return $passwordHash; } /** @@ -30,11 +29,9 @@ class FreshRSS_password_Util { * * A valid password is a string of at least 7 characters. * - * @param string $password - * - * @return boolean True if the password is valid, false otherwise + * @return bool True if the password is valid, false otherwise */ - public static function check($password) { + public static function check(string $password): bool { return strlen($password) >= 7; } } diff --git a/lib/lib_install.php b/lib/lib_install.php index 0204c90c9..931de21a2 100644 --- a/lib/lib_install.php +++ b/lib/lib_install.php @@ -1,7 +1,5 @@