diff options
| author | 2023-02-03 14:35:59 +0100 | |
|---|---|---|
| committer | 2023-02-03 14:35:59 +0100 | |
| commit | 40aa8b9264f1918cb48a0e2f6fc00455181a004a (patch) | |
| tree | 9168cc99a75a6e2efc84bbc46c3e604bf7511a1c /app/Utils/feverUtil.php | |
| parent | 9b5de54a9c96110b42f71681aa635e2e2c3b8756 (diff) | |
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 <sanchezluc+freshrss@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'app/Utils/feverUtil.php')
| -rw-r--r-- | app/Utils/feverUtil.php | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/app/Utils/feverUtil.php b/app/Utils/feverUtil.php index 277230ec2..0e4b712ce 100644 --- a/app/Utils/feverUtil.php +++ b/app/Utils/feverUtil.php @@ -1,14 +1,14 @@ <?php class FreshRSS_fever_Util { - const FEVER_PATH = DATA_PATH . '/fever'; + private const FEVER_PATH = DATA_PATH . '/fever'; /** * Make sure the fever path exists and is writable. * - * @return boolean true if the path is writable, else false. + * @return bool true if the path is writable, false otherwise. */ - public static function checkFeverPath() { + public static function checkFeverPath(): bool { if (!file_exists(self::FEVER_PATH)) { @mkdir(self::FEVER_PATH, 0770, true); } @@ -22,25 +22,21 @@ class FreshRSS_fever_Util { /** * Return the corresponding path for a fever key. - * - * @param string $feverKey - * @return string */ - public static function getKeyPath($feverKey) { + public static function getKeyPath(string $feverKey): string { + if (FreshRSS_Context::$system_conf === null) { + throw new FreshRSS_Context_Exception('System configuration not initialised!'); + } $salt = sha1(FreshRSS_Context::$system_conf->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; |
