From a80a5f48a16e7d232168a7aaa68e9a1804235ce1 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 18 Dec 2023 17:59:16 +0100 Subject: Pass PHPStan level 8 (#5946) * Pass PHPStan level 8 And prepare for PHPStan level 9 https://phpstan.org/user-guide/rule-levels * Revert wrong replace in comment * Fix PHPStan level 8 * Update PHPStan and other dev dependencies * Remove obsolete comment * noVariableVariables and towards bleedingEdge https://github.com/phpstan/phpstan-strict-rules https://phpstan.org/blog/what-is-bleeding-edge * More bleedingEdge * A bit more PHPStan level 9 * More PHPStan level 9 * Prepare for booleansInConditions Ignore int and null * Revert wrong line * More fixes * Fix keep_max_n_unread * Stricter attribute functions * Stricter callHooks and more PHPStan level 9 * More typing * A tiny more --- app/Models/Auth.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'app/Models/Auth.php') diff --git a/app/Models/Auth.php b/app/Models/Auth.php index e5f7fc0b9..c66bb5016 100644 --- a/app/Models/Auth.php +++ b/app/Models/Auth.php @@ -24,7 +24,7 @@ class FreshRSS_Auth { self::$login_ok = Minz_Session::paramBoolean('loginOk'); $current_user = Minz_User::name(); if ($current_user === null) { - $current_user = FreshRSS_Context::$system_conf->default_user; + $current_user = FreshRSS_Context::systemConf()->default_user; Minz_Session::_params([ Minz_User::CURRENT_USER => $current_user, 'csrf' => false, @@ -51,7 +51,7 @@ class FreshRSS_Auth { * @return bool true if user can be connected, false otherwise. */ private static function accessControl(): bool { - $auth_type = FreshRSS_Context::$system_conf->auth_type; + $auth_type = FreshRSS_Context::systemConf()->auth_type; switch ($auth_type) { case 'form': $credentials = FreshRSS_FormAuth::getCredentialsFromCookie(); @@ -71,13 +71,13 @@ class FreshRSS_Auth { return false; } $login_ok = FreshRSS_UserDAO::exists($current_user); - if (!$login_ok && FreshRSS_Context::$system_conf->http_auth_auto_register) { + if (!$login_ok && FreshRSS_Context::systemConf()->http_auth_auto_register) { $email = null; - if (FreshRSS_Context::$system_conf->http_auth_auto_register_email_field !== '' && - isset($_SERVER[FreshRSS_Context::$system_conf->http_auth_auto_register_email_field])) { - $email = (string)$_SERVER[FreshRSS_Context::$system_conf->http_auth_auto_register_email_field]; + if (FreshRSS_Context::systemConf()->http_auth_auto_register_email_field !== '' && + isset($_SERVER[FreshRSS_Context::systemConf()->http_auth_auto_register_email_field])) { + $email = (string)$_SERVER[FreshRSS_Context::systemConf()->http_auth_auto_register_email_field]; } - $language = Minz_Translate::getLanguage(null, Minz_Request::getPreferredLanguages(), FreshRSS_Context::$system_conf->language); + $language = Minz_Translate::getLanguage(null, Minz_Request::getPreferredLanguages(), FreshRSS_Context::systemConf()->language); Minz_Translate::init($language); $login_ok = FreshRSS_user_Controller::createUser($current_user, $email, '', [ 'language' => $language, @@ -103,17 +103,17 @@ class FreshRSS_Auth { */ public static function giveAccess(): bool { FreshRSS_Context::initUser(); - if (FreshRSS_Context::$user_conf == null) { + if (!FreshRSS_Context::hasUserConf()) { self::$login_ok = false; return false; } - switch (FreshRSS_Context::$system_conf->auth_type) { + switch (FreshRSS_Context::systemConf()->auth_type) { case 'form': - self::$login_ok = Minz_Session::paramString('passwordHash') === FreshRSS_Context::$user_conf->passwordHash; + self::$login_ok = Minz_Session::paramString('passwordHash') === FreshRSS_Context::userConf()->passwordHash; break; case 'http_auth': - $current_user = Minz_User::name(); + $current_user = Minz_User::name() ?? ''; self::$login_ok = strcasecmp($current_user, httpAuthUser()) === 0; break; case 'none': @@ -138,12 +138,12 @@ class FreshRSS_Auth { * @return bool true if user has corresponding access, false else. */ public static function hasAccess(string $scope = 'general'): bool { - if (FreshRSS_Context::$user_conf == null) { + if (!FreshRSS_Context::hasUserConf()) { return false; } $currentUser = Minz_User::name(); - $isAdmin = FreshRSS_Context::$user_conf->is_admin; - $default_user = FreshRSS_Context::$system_conf->default_user; + $isAdmin = FreshRSS_Context::userConf()->is_admin; + $default_user = FreshRSS_Context::systemConf()->default_user; $ok = self::$login_ok; switch ($scope) { case 'general': @@ -180,11 +180,11 @@ class FreshRSS_Auth { } } if ($username == '') { - $username = FreshRSS_Context::$system_conf->default_user; + $username = FreshRSS_Context::systemConf()->default_user; } Minz_User::change($username); - switch (FreshRSS_Context::$system_conf->auth_type) { + switch (FreshRSS_Context::systemConf()->auth_type) { case 'form': Minz_Session::_param('passwordHash'); FreshRSS_FormAuth::deleteCookie(); @@ -202,20 +202,20 @@ class FreshRSS_Auth { * Return if authentication is enabled on this instance of FRSS. */ public static function accessNeedsLogin(): bool { - return FreshRSS_Context::$system_conf->auth_type !== 'none'; + return FreshRSS_Context::systemConf()->auth_type !== 'none'; } /** * Return if authentication requires a PHP action. */ public static function accessNeedsAction(): bool { - return FreshRSS_Context::$system_conf->auth_type === 'form'; + return FreshRSS_Context::systemConf()->auth_type === 'form'; } public static function csrfToken(): string { $csrf = Minz_Session::paramString('csrf'); if ($csrf == '') { - $salt = FreshRSS_Context::$system_conf->salt; + $salt = FreshRSS_Context::systemConf()->salt; $csrf = sha1($salt . uniqid('' . random_int(0, mt_getrandmax()), true)); Minz_Session::_param('csrf', $csrf); } -- cgit v1.2.3