aboutsummaryrefslogtreecommitdiff
path: root/app/Utils/feverUtil.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Utils/feverUtil.php')
-rw-r--r--app/Utils/feverUtil.php38
1 files changed, 16 insertions, 22 deletions
diff --git a/app/Utils/feverUtil.php b/app/Utils/feverUtil.php
index a7d21dacb..0e4b712ce 100644
--- a/app/Utils/feverUtil.php
+++ b/app/Utils/feverUtil.php
@@ -1,19 +1,19 @@
<?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);
}
- $ok = is_writable(self::FEVER_PATH);
+ $ok = touch(self::FEVER_PATH . '/index.html'); // is_writable() is not reliable for a folder on NFS
if (!$ok) {
Minz_Log::error("Could not save Fever API credentials. The directory does not have write access.");
}
@@ -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;