From f3760f138dcbaf7a2190336a0378cf1b2190c9f5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 17 Apr 2023 08:30:21 +0200 Subject: Complete PHPStan Level 6 (#5305) * Complete PHPStan Level 6 Fix https://github.com/FreshRSS/FreshRSS/issues/4112 And initiate PHPStan Level 7 * PHPStan Level 6 for tests * Use phpstan/phpstan-phpunit * Update to PHPStan version 1.10 * Fix mixed bug * Fix mixed return bug * Fix paginator bug * Fix FreshRSS_UserConfiguration * A couple more Minz_Configuration bug fixes * A few trivial PHPStan Level 7 fixes * A few more simple PHPStan Level 7 * More files passing PHPStan Level 7 Add interface to replace removed class from https://github.com/FreshRSS/FreshRSS/pull/5251 * A few more PHPStan Level 7 preparations * A few last details --- app/install.php | 88 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 40 deletions(-) (limited to 'app/install.php') diff --git a/app/install.php b/app/install.php index b43aa81bb..599fd9863 100644 --- a/app/install.php +++ b/app/install.php @@ -18,7 +18,11 @@ if (STEP === 2 && isset($_POST['type'])) { Minz_Session::_param('bd_type', $_POST['type']); } -function param($key, $default = false) { +/** + * @param mixed $default + * @return mixed + */ +function param(string $key, $default = false) { if (isset($_POST[$key])) { return $_POST[$key]; } else { @@ -27,7 +31,7 @@ function param($key, $default = false) { } // gestion internationalisation -function initTranslate() { +function initTranslate(): void { Minz_Translate::init(); $available_languages = Minz_Translate::availableLanguages(); @@ -42,14 +46,14 @@ function initTranslate() { Minz_Translate::reset(Minz_Session::param('language')); } -function get_best_language() { +function get_best_language(): string { $accept = empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? '' : $_SERVER['HTTP_ACCEPT_LANGUAGE']; return strtolower(substr($accept, 0, 2)); } /*** SAUVEGARDES ***/ -function saveLanguage() { +function saveLanguage(): bool { if (!empty($_POST)) { if (!isset($_POST['language'])) { return false; @@ -60,9 +64,10 @@ function saveLanguage() { header('Location: index.php?step=1'); } + return true; } -function saveStep1() { +function saveStep1(): void { if (isset($_POST['freshrss-keep-install']) && $_POST['freshrss-keep-install'] === '1') { // We want to keep our previous installation of FreshRSS @@ -79,12 +84,12 @@ function saveStep1() { 'auth_type' => FreshRSS_Context::$system_conf->auth_type, 'default_user' => Minz_User::name(), 'passwordHash' => FreshRSS_Context::$user_conf->passwordHash, - 'bd_type' => FreshRSS_Context::$system_conf->db['type'], - 'bd_host' => FreshRSS_Context::$system_conf->db['host'], - 'bd_user' => FreshRSS_Context::$system_conf->db['user'], - 'bd_password' => FreshRSS_Context::$system_conf->db['password'], - 'bd_base' => FreshRSS_Context::$system_conf->db['base'], - 'bd_prefix' => FreshRSS_Context::$system_conf->db['prefix'], + 'bd_type' => FreshRSS_Context::$system_conf->db['type'] ?? '', + 'bd_host' => FreshRSS_Context::$system_conf->db['host'] ?? '', + 'bd_user' => FreshRSS_Context::$system_conf->db['user'] ?? '', + 'bd_password' => FreshRSS_Context::$system_conf->db['password'] ?? '', + 'bd_base' => FreshRSS_Context::$system_conf->db['base'] ?? '', + 'bd_prefix' => FreshRSS_Context::$system_conf->db['prefix'] ?? '', 'bd_error' => false, ]); @@ -92,7 +97,7 @@ function saveStep1() { } } -function saveStep2() { +function saveStep2(): void { if (!empty($_POST)) { if (Minz_Session::param('bd_type') === 'sqlite') { Minz_Session::_params([ @@ -190,9 +195,9 @@ function saveStep2() { invalidateHttpCache(); } -function saveStep3() { +function saveStep3(): bool { if (!empty($_POST)) { - $system_default_config = Minz_Configuration::get('default_system'); + $system_default_config = FreshRSS_SystemConfiguration::get('default_system'); Minz_Session::_params([ 'title' => $system_default_config->title, 'auth_type' => param('auth_type', 'form'), @@ -242,10 +247,11 @@ function saveStep3() { header('Location: index.php?step=4'); } + return true; } /*** VÉRIFICATIONS ***/ -function checkStep() { +function checkStep(): void { $s0 = checkStep0(); $s1 = checkRequirements(); $s2 = checkStep2(); @@ -262,7 +268,8 @@ function checkStep() { Minz_Session::_param('actualize_feeds', true); } -function checkStep0() { +/** @return array */ +function checkStep0(): array { $languages = Minz_Translate::availableLanguages(); $language = Minz_Session::param('language') != '' && in_array(Minz_Session::param('language'), $languages); $sessionWorking = Minz_Session::param('sessionWorking') === 'ok'; @@ -274,7 +281,7 @@ function checkStep0() { ); } -function freshrss_already_installed() { +function freshrss_already_installed(): bool { $conf_path = join_path(DATA_PATH, 'config.php'); if (!file_exists($conf_path)) { return false; @@ -300,7 +307,8 @@ function freshrss_already_installed() { return true; } -function checkStep2() { +/** @return array */ +function checkStep2(): array { $conf = is_writable(join_path(DATA_PATH, 'config.php')); $bd = Minz_Session::param('bd_type') != ''; @@ -314,7 +322,8 @@ function checkStep2() { ]; } -function checkStep3() { +/** @return array */ +function checkStep3(): array { $conf = Minz_Session::param('default_user') != ''; $form = Minz_Session::param('auth_type') != ''; @@ -335,7 +344,7 @@ function checkStep3() { /*** AFFICHAGE ***/ -function printStep0() { +function printStep0(): void { $actual = Minz_Translate::language(); $languages = Minz_Translate::availableLanguages(); $s0 = checkStep0(); @@ -373,7 +382,8 @@ function printStep0() { $messageParams */ +function printStep1Template(string $key, string $value, array $messageParams = []): void { if ('ok' === $value) { $message = _t("install.check.{$key}.ok", ...$messageParams); ?>

@@ -408,14 +420,10 @@ function printStep1() {

@@ -509,7 +517,7 @@ function printStep2() {
+ isset($_SESSION['bd_host']) ? $_SESSION['bd_host'] : ($system_default_config->db['host'] ?? '') ?>" tabindex="2" />
@@ -544,7 +552,7 @@ function printStep2() {
+ isset($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : ($system_default_config->db['prefix'] ?? '') ?>" tabindex="7" />
@@ -562,11 +570,11 @@ function printStep2() { @@ -628,7 +636,7 @@ function printStep3() {

@@ -639,7 +647,7 @@ function printStep4() {

@@ -676,7 +684,7 @@ case 5: } ?> -