diff options
| author | 2023-12-18 17:59:16 +0100 | |
|---|---|---|
| committer | 2023-12-18 17:59:16 +0100 | |
| commit | a80a5f48a16e7d232168a7aaa68e9a1804235ce1 (patch) | |
| tree | a515b88592629dea7e83b96e26e2452d3f98a98e /cli | |
| parent | 6bb45a87268157aab961a6a4a728d9a9bbe043b0 (diff) | |
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
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/_cli.php | 9 | ||||
| -rw-r--r-- | cli/_update-or-create-user.php | 2 | ||||
| -rwxr-xr-x | cli/actualize-user.php | 4 | ||||
| -rwxr-xr-x | cli/create-user.php | 2 | ||||
| -rwxr-xr-x | cli/db-optimize.php | 2 | ||||
| -rwxr-xr-x | cli/delete-user.php | 6 | ||||
| -rwxr-xr-x | cli/do-install.php | 4 | ||||
| -rwxr-xr-x | cli/export-opml-for-user.php | 2 | ||||
| -rwxr-xr-x | cli/export-sqlite-for-user.php | 2 | ||||
| -rwxr-xr-x | cli/export-zip-for-user.php | 2 | ||||
| -rw-r--r-- | cli/i18n/I18nData.php | 2 | ||||
| -rw-r--r-- | cli/i18n/I18nValue.php | 2 | ||||
| -rwxr-xr-x | cli/import-for-user.php | 2 | ||||
| -rwxr-xr-x | cli/import-sqlite-for-user.php | 2 | ||||
| -rwxr-xr-x | cli/list-users.php | 6 | ||||
| -rwxr-xr-x | cli/reconfigure.php | 67 | ||||
| -rwxr-xr-x | cli/user-info.php | 12 |
17 files changed, 84 insertions, 44 deletions
diff --git a/cli/_cli.php b/cli/_cli.php index eb2152082..91fa8de36 100644 --- a/cli/_cli.php +++ b/cli/_cli.php @@ -35,11 +35,12 @@ function cliInitUser(string $username): string { fail('FreshRSS error: user not found: ' . $username . "\n"); } - if (!FreshRSS_Context::initUser($username)) { + FreshRSS_Context::initUser($username); + if (!FreshRSS_Context::hasUserConf()) { fail('FreshRSS error: invalid configuration for user: ' . $username . "\n"); } - $ext_list = FreshRSS_Context::$user_conf->extensions_enabled; + $ext_list = FreshRSS_Context::userConf()->extensions_enabled; Minz_ExtensionManager::enableByList($ext_list, 'user'); return $username; @@ -80,10 +81,10 @@ function performRequirementCheck(string $databaseType): void { */ function getLongOptions(array $options, string $regex): array { $longOptions = array_filter($options, static function (string $a) use ($regex) { - return preg_match($regex, $a); + return preg_match($regex, $a) === 1; }); return array_map(static function (string $a) use ($regex) { - return preg_replace($regex, '', $a); + return preg_replace($regex, '', $a) ?? ''; }, $longOptions); } diff --git a/cli/_update-or-create-user.php b/cli/_update-or-create-user.php index 69e6ce589..385bbd549 100644 --- a/cli/_update-or-create-user.php +++ b/cli/_update-or-create-user.php @@ -2,7 +2,7 @@ declare(strict_types=1); require(__DIR__ . '/_cli.php'); -performRequirementCheck(FreshRSS_Context::$system_conf->db['type'] ?? ''); +performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); $params = array( 'user:', diff --git a/cli/actualize-user.php b/cli/actualize-user.php index 870eda9b2..99b48116d 100755 --- a/cli/actualize-user.php +++ b/cli/actualize-user.php @@ -3,7 +3,7 @@ declare(strict_types=1); require(__DIR__ . '/_cli.php'); -performRequirementCheck(FreshRSS_Context::$system_conf->db['type'] ?? ''); +performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); $params = array( 'user:', @@ -17,7 +17,7 @@ if (!validateOptions($argv, $params) || empty($options['user']) || !is_string($o $username = cliInitUser($options['user']); -Minz_ExtensionManager::callHook('freshrss_user_maintenance'); +Minz_ExtensionManager::callHookVoid('freshrss_user_maintenance'); fwrite(STDERR, 'FreshRSS actualizing user “' . $username . "”…\n"); diff --git a/cli/create-user.php b/cli/create-user.php index 286befe85..c360a88a5 100755 --- a/cli/create-user.php +++ b/cli/create-user.php @@ -38,7 +38,7 @@ if (!empty($options['api_password'])) { } } -invalidateHttpCache(FreshRSS_Context::$system_conf->default_user); +invalidateHttpCache(FreshRSS_Context::systemConf()->default_user); echo 'ℹ️ Remember to refresh the feeds of the user: ', $username , "\t", './cli/actualize-user.php --user ', $username, "\n"; diff --git a/cli/db-optimize.php b/cli/db-optimize.php index 2561e7cb2..82f545420 100755 --- a/cli/db-optimize.php +++ b/cli/db-optimize.php @@ -3,7 +3,7 @@ declare(strict_types=1); require(__DIR__ . '/_cli.php'); -performRequirementCheck(FreshRSS_Context::$system_conf->db['type'] ?? ''); +performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); $params = array( 'user:', diff --git a/cli/delete-user.php b/cli/delete-user.php index 2ad84b7dc..d8d3033cc 100755 --- a/cli/delete-user.php +++ b/cli/delete-user.php @@ -3,7 +3,7 @@ declare(strict_types=1); require(__DIR__ . '/_cli.php'); -performRequirementCheck(FreshRSS_Context::$system_conf->db['type'] ?? ''); +performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); $params = array( 'user:', @@ -24,7 +24,7 @@ if (!preg_grep("/^$username$/i", $usernames)) { fail('FreshRSS error: username not found “' . $username . '”'); } -if (strcasecmp($username, FreshRSS_Context::$system_conf->default_user) === 0) { +if (strcasecmp($username, FreshRSS_Context::systemConf()->default_user) === 0) { fail('FreshRSS error: default user must not be deleted: “' . $username . '”'); } @@ -32,6 +32,6 @@ echo 'FreshRSS deleting user “', $username, "”…\n"; $ok = FreshRSS_user_Controller::deleteUser($username); -invalidateHttpCache(FreshRSS_Context::$system_conf->default_user); +invalidateHttpCache(FreshRSS_Context::systemConf()->default_user); done($ok); diff --git a/cli/do-install.php b/cli/do-install.php index 1b391a458..c69d5f081 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -44,7 +44,7 @@ fwrite(STDERR, 'FreshRSS install…' . "\n"); $config = array( 'salt' => generateSalt(), - 'db' => FreshRSS_Context::$system_conf->db, + 'db' => FreshRSS_Context::systemConf()->db, ); $customConfigPath = DATA_PATH . '/config.custom.php'; @@ -62,7 +62,7 @@ foreach ($params as $param) { } } -if ((!empty($config['base_url'])) && Minz_Request::serverIsPublic($config['base_url'])) { +if ((!empty($config['base_url'])) && is_string($config['base_url']) && Minz_Request::serverIsPublic($config['base_url'])) { $config['pubsubhubbub_enabled'] = true; } diff --git a/cli/export-opml-for-user.php b/cli/export-opml-for-user.php index a28bddced..51beb12f3 100755 --- a/cli/export-opml-for-user.php +++ b/cli/export-opml-for-user.php @@ -3,7 +3,7 @@ declare(strict_types=1); require(__DIR__ . '/_cli.php'); -performRequirementCheck(FreshRSS_Context::$system_conf->db['type'] ?? ''); +performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); $params = array( 'user:', diff --git a/cli/export-sqlite-for-user.php b/cli/export-sqlite-for-user.php index e1dc83987..ee8e183f6 100755 --- a/cli/export-sqlite-for-user.php +++ b/cli/export-sqlite-for-user.php @@ -3,7 +3,7 @@ declare(strict_types=1); require(__DIR__ . '/_cli.php'); -performRequirementCheck(FreshRSS_Context::$system_conf->db['type'] ?? ''); +performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); $params = [ 'user:', diff --git a/cli/export-zip-for-user.php b/cli/export-zip-for-user.php index dedcb6c11..5458784bf 100755 --- a/cli/export-zip-for-user.php +++ b/cli/export-zip-for-user.php @@ -3,7 +3,7 @@ declare(strict_types=1); require(__DIR__ . '/_cli.php'); -performRequirementCheck(FreshRSS_Context::$system_conf->db['type'] ?? ''); +performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); $params = array( 'user:', diff --git a/cli/i18n/I18nData.php b/cli/i18n/I18nData.php index 6e87e1d7e..f6bc7fb5d 100644 --- a/cli/i18n/I18nData.php +++ b/cli/i18n/I18nData.php @@ -330,7 +330,7 @@ class I18nData { } private function getFilenamePrefix(string $key): string { - return preg_replace('/\..*/', '.php', $key); + return preg_replace('/\..*/', '.php', $key) ?? ''; } } diff --git a/cli/i18n/I18nValue.php b/cli/i18n/I18nValue.php index 22317e1ae..88d0ea494 100644 --- a/cli/i18n/I18nValue.php +++ b/cli/i18n/I18nValue.php @@ -21,7 +21,7 @@ class I18nValue { } $data = explode(' -> ', $data); - $this->value = array_shift($data); + $this->value = (string)(array_shift($data) ?? ''); if (count($data) === 0) { return; } diff --git a/cli/import-for-user.php b/cli/import-for-user.php index 212be7653..b4731b13b 100755 --- a/cli/import-for-user.php +++ b/cli/import-for-user.php @@ -3,7 +3,7 @@ declare(strict_types=1); require(__DIR__ . '/_cli.php'); -performRequirementCheck(FreshRSS_Context::$system_conf->db['type'] ?? ''); +performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); $params = array( 'user:', diff --git a/cli/import-sqlite-for-user.php b/cli/import-sqlite-for-user.php index 62a9d86c4..b61a73523 100755 --- a/cli/import-sqlite-for-user.php +++ b/cli/import-sqlite-for-user.php @@ -3,7 +3,7 @@ declare(strict_types=1); require(__DIR__ . '/_cli.php'); -performRequirementCheck(FreshRSS_Context::$system_conf->db['type'] ?? ''); +performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? ''); $params = [ 'user:', diff --git a/cli/list-users.php b/cli/list-users.php index 276239b25..f9e63f4f6 100755 --- a/cli/list-users.php +++ b/cli/list-users.php @@ -5,9 +5,9 @@ require(__DIR__ . '/_cli.php'); $users = listUsers(); sort($users); -if (FreshRSS_Context::$system_conf->default_user !== '' - && in_array(FreshRSS_Context::$system_conf->default_user, $users, true)) { - array_unshift($users, FreshRSS_Context::$system_conf->default_user); +if (FreshRSS_Context::systemConf()->default_user !== '' + && in_array(FreshRSS_Context::systemConf()->default_user, $users, true)) { + array_unshift($users, FreshRSS_Context::systemConf()->default_user); $users = array_unique($users); } diff --git a/cli/reconfigure.php b/cli/reconfigure.php index 7d502a17a..84cb42d60 100755 --- a/cli/reconfigure.php +++ b/cli/reconfigure.php @@ -41,10 +41,56 @@ fwrite(STDERR, 'Reconfiguring FreshRSS…' . "\n"); foreach ($params as $param) { $param = rtrim($param, ':'); if (isset($options[$param])) { - FreshRSS_Context::$system_conf->$param = $options[$param] === false ? true : $options[$param]; + switch ($param) { + case 'allow_anonymous_refresh': + FreshRSS_Context::systemConf()->allow_anonymous_refresh = true; + break; + case 'allow_anonymous': + FreshRSS_Context::systemConf()->allow_anonymous = true; + break; + case 'allow_robots': + FreshRSS_Context::systemConf()->allow_robots = true; + break; + case 'api_enabled': + FreshRSS_Context::systemConf()->api_enabled = true; + break; + case 'auth_type': + if (in_array($options[$param], ['form', 'http_auth', 'none'], true)) { + FreshRSS_Context::systemConf()->auth_type = $options[$param]; + } else { + fail('FreshRSS invalid authentication method! auth_type must be one of { form, http_auth, none }'); + } + break; + case 'base_url': + FreshRSS_Context::systemConf()->base_url = $options[$param]; + break; + case 'default_user': + if (FreshRSS_user_Controller::checkUsername($options[$param])) { + FreshRSS_Context::systemConf()->default_user = $options[$param]; + } else { + fail('FreshRSS invalid default username! default_user must be ASCII alphanumeric'); + } + break; + case 'disable_update': + FreshRSS_Context::systemConf()->disable_update = true; + break; + case 'environment': + if (in_array($options[$param], ['development', 'production', 'silent'], true)) { + FreshRSS_Context::systemConf()->environment = $options[$param]; + } else { + fail('FreshRSS invalid environment! environment must be one of { development, production, silent }'); + } + break; + case 'language': + FreshRSS_Context::systemConf()->language = $options[$param]; + break; + case 'title': + FreshRSS_Context::systemConf()->title = $options[$param]; + break; + } } } -$db = FreshRSS_Context::$system_conf->db; +$db = FreshRSS_Context::systemConf()->db; foreach ($dBparams as $dBparam) { $dBparam = rtrim($dBparam, ':'); if (isset($options[$dBparam])) { @@ -52,19 +98,10 @@ foreach ($dBparams as $dBparam) { $db[$param] = $options[$dBparam]; } } -FreshRSS_Context::$system_conf->db = $db; +/** @var array{'type':string,'host':string,'user':string,'password':string,'base':string,'prefix':string, + * 'connection_uri_params':string,'pdo_options':array<int,int|string|bool>} $db */ +FreshRSS_Context::systemConf()->db = $db; -if (!FreshRSS_user_Controller::checkUsername(FreshRSS_Context::$system_conf->default_user)) { - fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . - FreshRSS_Context::$system_conf->default_user); -} - -if (isset(FreshRSS_Context::$system_conf->auth_type) && - !in_array(FreshRSS_Context::$system_conf->auth_type, ['form', 'http_auth', 'none'], true)) { - fail('FreshRSS invalid authentication method (auth_type must be one of { form, http_auth, none }: ' - . FreshRSS_Context::$system_conf->auth_type); -} - -FreshRSS_Context::$system_conf->save(); +FreshRSS_Context::systemConf()->save(); done(); diff --git a/cli/user-info.php b/cli/user-info.php index f24f81078..fbf60482a 100755 --- a/cli/user-info.php +++ b/cli/user-info.php @@ -19,8 +19,10 @@ if (!validateOptions($argv, $params)) { if (empty($options['user'])) { $users = listUsers(); } elseif (is_array($options['user'])) { + /** @var array<string> $users */ $users = $options['user']; } else { + /** @var array<string> $users */ $users = array($options['user']); } @@ -67,10 +69,10 @@ foreach ($users as $username) { $feedList = $feedDAO->listFeedsIds(); $data = array( - 'default' => $username === FreshRSS_Context::$system_conf->default_user ? '*' : '', + 'default' => $username === FreshRSS_Context::systemConf()->default_user ? '*' : '', 'user' => $username, - 'admin' => FreshRSS_Context::$user_conf->is_admin ? '*' : '', - 'enabled' => FreshRSS_Context::$user_conf->enabled ? '*' : '', + 'admin' => FreshRSS_Context::userConf()->is_admin ? '*' : '', + 'enabled' => FreshRSS_Context::userConf()->enabled ? '*' : '', 'last_user_activity' => FreshRSS_UserDAO::mtime($username), 'database_size' => $databaseDAO->size(), 'categories' => $catDAO->count(), @@ -79,8 +81,8 @@ foreach ($users as $username) { 'unreads' => (int)$nbEntries['unread'], 'favourites' => (int)$nbFavorites['all'], 'tags' => $tagDAO->count(), - 'lang' => FreshRSS_Context::$user_conf->language, - 'mail_login' => FreshRSS_Context::$user_conf->mail_login, + 'lang' => FreshRSS_Context::userConf()->language, + 'mail_login' => FreshRSS_Context::userConf()->mail_login, ); if (isset($options['h'])) { //Human format $data['last_user_activity'] = date('c', $data['last_user_activity']); |
