diff options
| author | 2023-04-05 23:26:38 +0200 | |
|---|---|---|
| committer | 2023-04-05 23:26:38 +0200 | |
| commit | 2118448133e327294ad2b69ed8736bc29879103d (patch) | |
| tree | 00c003056dedbd8e3554801d6493a25641a260a5 /app | |
| parent | 4f078958b5603900592e14f9f3189bbebfc81bab (diff) | |
PHPStan level 6 for more files (#5264)
7 more files passing (see phpstan-next.txt)
Diffstat (limited to 'app')
| -rw-r--r-- | app/Controllers/authController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/updateController.php | 15 | ||||
| -rw-r--r-- | app/Models/Auth.php | 22 | ||||
| -rw-r--r-- | app/Models/FormAuth.php | 9 |
4 files changed, 27 insertions, 21 deletions
diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php index 30fd705f5..81043bcf7 100644 --- a/app/Controllers/authController.php +++ b/app/Controllers/authController.php @@ -162,7 +162,7 @@ class FreshRSS_auth_Controller extends FreshRSS_ActionController { // All is good, go back to the original request or the index. $url = Minz_Url::unserialize(Minz_Request::param('original_request')); - if ($url === null) { + if (empty($url)) { $url = [ 'c' => 'index', 'a' => 'index' ]; } Minz_Request::good(_t('feedback.auth.login.success'), $url); diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index 82ccd20c9..742806ba3 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -4,14 +4,14 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { const LASTUPDATEFILE = 'last_update.txt'; - public static function isGit() { + public static function isGit(): bool { return is_dir(FRESHRSS_PATH . '/.git/'); } /** * Automatic change to the new name of edge branch since FreshRSS 1.18.0. */ - public static function migrateToGitEdge() { + public static function migrateToGitEdge(): bool { $errorMessage = 'Error during git checkout to edge branch. Please change branch manually!'; if (!is_writable(FRESHRSS_PATH . '/.git/config')) { @@ -44,7 +44,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { return true; } - public static function hasGitUpdate() { + public static function hasGitUpdate(): bool { $cwd = getcwd(); chdir(FRESHRSS_PATH); $output = array(); @@ -66,6 +66,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { strpos($line, '[behind') !== false || strpos($line, '[ahead') !== false || strpos($line, '[gone') !== false; } + /** @return string|true */ public static function gitPull() { $cwd = getcwd(); chdir(FRESHRSS_PATH); @@ -109,7 +110,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { } } - public function indexAction() { + public function indexAction(): void { FreshRSS_View::prependTitle(_t('admin.update.title') . ' · '); if (file_exists(UPDATE_FILENAME)) { @@ -135,7 +136,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { } } - public function checkAction() { + public function checkAction(): void { $this->view->_path('update/index.phtml'); if (file_exists(UPDATE_FILENAME)) { @@ -216,7 +217,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { } } - public function applyAction() { + public function applyAction(): void { if (FreshRSS_Context::$system_conf->disable_update || !file_exists(UPDATE_FILENAME) || !touch(FRESHRSS_PATH . '/index.html')) { Minz_Request::forward(array('c' => 'update'), true); } @@ -278,7 +279,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { /** * This action displays information about installation. */ - public function checkInstallAction() { + public function checkInstallAction(): void { FreshRSS_View::prependTitle(_t('admin.check_install.title') . ' · '); $this->view->status_php = check_install_php(); diff --git a/app/Models/Auth.php b/app/Models/Auth.php index 65e761fb8..ccf244033 100644 --- a/app/Models/Auth.php +++ b/app/Models/Auth.php @@ -9,12 +9,13 @@ class FreshRSS_Auth { */ const DEFAULT_COOKIE_DURATION = 7776000; + /** @var bool */ private static $login_ok = false; /** * This method initializes authentication system. */ - public static function init() { + public static function init(): bool { if (isset($_SESSION['REMOTE_USER']) && $_SESSION['REMOTE_USER'] !== httpAuthUser()) { //HTTP REMOTE_USER has changed self::removeAccess(); @@ -47,9 +48,9 @@ class FreshRSS_Auth { * Required session parameters are also set in this method (such as * currentUser). * - * @return boolean true if user can be connected, false else. + * @return bool true if user can be connected, false otherwise. */ - private static function accessControl() { + private static function accessControl(): bool { $auth_type = FreshRSS_Context::$system_conf->auth_type; switch ($auth_type) { case 'form': @@ -100,7 +101,7 @@ class FreshRSS_Auth { /** * Gives access to the current user. */ - public static function giveAccess() { + public static function giveAccess(): bool { FreshRSS_Context::initUser(); if (FreshRSS_Context::$user_conf == null) { self::$login_ok = false; @@ -136,7 +137,7 @@ class FreshRSS_Auth { * @param string $scope general (default) or admin * @return boolean true if user has corresponding access, false else. */ - public static function hasAccess($scope = 'general') { + public static function hasAccess($scope = 'general'): bool { if (FreshRSS_Context::$user_conf == null) { return false; } @@ -159,7 +160,7 @@ class FreshRSS_Auth { /** * Removes all accesses for the current user. */ - public static function removeAccess() { + public static function removeAccess(): void { self::$login_ok = false; Minz_Session::_params([ 'loginOk' => false, @@ -200,18 +201,18 @@ class FreshRSS_Auth { /** * Return if authentication is enabled on this instance of FRSS. */ - public static function accessNeedsLogin() { + public static function accessNeedsLogin(): bool { return FreshRSS_Context::$system_conf->auth_type !== 'none'; } /** * Return if authentication requires a PHP action. */ - public static function accessNeedsAction() { + public static function accessNeedsAction(): bool { return FreshRSS_Context::$system_conf->auth_type === 'form'; } - public static function csrfToken() { + public static function csrfToken(): string { $csrf = Minz_Session::param('csrf'); if ($csrf == '') { $salt = FreshRSS_Context::$system_conf->salt; @@ -220,7 +221,8 @@ class FreshRSS_Auth { } return $csrf; } - public static function isCsrfOk($token = null) { + + public static function isCsrfOk(?string $token = null): bool { $csrf = Minz_Session::param('csrf'); if ($token === null) { $token = $_POST['_csrf'] ?? ''; diff --git a/app/Models/FormAuth.php b/app/Models/FormAuth.php index 653eba04b..476daba53 100644 --- a/app/Models/FormAuth.php +++ b/app/Models/FormAuth.php @@ -13,7 +13,8 @@ class FreshRSS_FormAuth { return password_verify($nonce . $hash, $challenge); } - public static function getCredentialsFromCookie() { + /** @return array<string> */ + public static function getCredentialsFromCookie(): array { $token = Minz_Session::getLongTermCookie('FreshRSS_login'); if (!ctype_alnum($token)) { return array(); @@ -36,6 +37,7 @@ class FreshRSS_FormAuth { return []; } + /** @return string|false */ private static function renewCookie(string $token) { $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; if (touch($token_file)) { @@ -48,6 +50,7 @@ class FreshRSS_FormAuth { return false; } + /** @return string|false */ public static function makeCookie(string $username, string $password_hash) { do { $token = sha1(FreshRSS_Context::$system_conf->salt . $username . uniqid('' . mt_rand(), true)); @@ -61,7 +64,7 @@ class FreshRSS_FormAuth { return self::renewCookie($token); } - public static function deleteCookie() { + public static function deleteCookie(): void { $token = Minz_Session::getLongTermCookie('FreshRSS_login'); if (ctype_alnum($token)) { Minz_Session::deleteLongTermCookie('FreshRSS_login'); @@ -73,7 +76,7 @@ class FreshRSS_FormAuth { } } - public static function purgeTokens() { + public static function purgeTokens(): void { $limits = FreshRSS_Context::$system_conf->limits; $cookie_duration = empty($limits['cookie_duration']) ? FreshRSS_Auth::DEFAULT_COOKIE_DURATION : $limits['cookie_duration']; $oldest = time() - $cookie_duration; |
