aboutsummaryrefslogtreecommitdiff
path: root/app/install.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-04-17 08:30:21 +0200
committerGravatar GitHub <noreply@github.com> 2023-04-17 08:30:21 +0200
commitf3760f138dcbaf7a2190336a0378cf1b2190c9f5 (patch)
tree6fac8fbf9efd7aa74a8e3970ab70ccf85287b2cd /app/install.php
parent41fa4e746df8c2e2399ed753b4994ca85cb21358 (diff)
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
Diffstat (limited to 'app/install.php')
-rw-r--r--app/install.php88
1 files changed, 48 insertions, 40 deletions
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<string,string> */
+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<string,string> */
+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<string,string> */
+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() {
<?php
}
-function printStep1Template($key, $value, $messageParams = []) {
+/** @param array<string> $messageParams */
+function printStep1Template(string $key, string $value, array $messageParams = []): void {
if ('ok' === $value) {
$message = _t("install.check.{$key}.ok", ...$messageParams);
?><p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= $message ?></p><?php
@@ -383,10 +393,12 @@ function printStep1Template($key, $value, $messageParams = []) {
}
}
-function getProcessUsername() {
+function getProcessUsername(): string {
if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
- $processUser = posix_getpwuid(posix_geteuid());
- return $processUser['name'];
+ $processUser = posix_getpwuid(posix_geteuid()) ?: [];
+ if (!empty($processUser['name'])) {
+ return $processUser['name'];
+ }
}
if (function_exists('exec')) {
@@ -400,7 +412,7 @@ function getProcessUsername() {
}
// @todo refactor this view with the check_install action
-function printStep1() {
+function printStep1(): void {
$res = checkRequirements();
$processUsername = getProcessUsername();
?>
@@ -408,14 +420,10 @@ function printStep1() {
<noscript><p class="alert alert-warn"><span class="alert-head"><?= _t('gen.short.attention') ?></span> <?= _t('install.javascript_is_better') ?></p></noscript>
<?php
- if (function_exists('curl_version')) {
- $version = curl_version();
- } else {
- $version['version'] = '';
- }
+ $version = function_exists('curl_version') ? curl_version() : [];
printStep1Template('php', $res['php'], [PHP_VERSION, FRESHRSS_MIN_PHP_VERSION]);
printStep1Template('pdo', $res['pdo']);
- printStep1Template('curl', $res['curl'], [$version['version']]);
+ printStep1Template('curl', $res['curl'], [$version['version'] ?? '']);
printStep1Template('json', $res['json']);
printStep1Template('pcre', $res['pcre']);
printStep1Template('ctype', $res['ctype']);
@@ -466,8 +474,8 @@ function printStep1() {
<?php
}
-function printStep2() {
- $system_default_config = Minz_Configuration::get('default_system');
+function printStep2(): void {
+ $system_default_config = FreshRSS_SystemConfiguration::get('default_system');
$s2 = checkStep2();
if ($s2['all'] == 'ok') { ?>
<p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= _t('install.bdd.conf.ok') ?></p>
@@ -509,7 +517,7 @@ function printStep2() {
<label class="group-name" for="host"><?= _t('install.bdd.host') ?></label>
<div class="group-controls">
<input type="text" id="host" name="host" pattern="[0-9A-Z/a-z_.-]{1,64}(:[0-9]{2,5})?" value="<?=
- isset($_SESSION['bd_host']) ? $_SESSION['bd_host'] : $system_default_config->db['host'] ?>" tabindex="2" />
+ isset($_SESSION['bd_host']) ? $_SESSION['bd_host'] : ($system_default_config->db['host'] ?? '') ?>" tabindex="2" />
</div>
</div>
@@ -544,7 +552,7 @@ function printStep2() {
<label class="group-name" for="prefix"><?= _t('install.bdd.prefix') ?></label>
<div class="group-controls">
<input type="text" id="prefix" name="prefix" maxlength="16" pattern="[0-9A-Za-z_]{1,16}" value="<?=
- isset($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : $system_default_config->db['prefix'] ?>" tabindex="7" />
+ isset($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : ($system_default_config->db['prefix'] ?? '') ?>" tabindex="7" />
</div>
</div>
</div>
@@ -562,11 +570,11 @@ function printStep2() {
<?php
}
-function no_auth($auth_type) {
+function no_auth(string $auth_type): bool {
return !in_array($auth_type, array('form', 'http_auth', 'none'));
}
-function printStep3() {
+function printStep3(): void {
$auth_type = isset($_SESSION['auth_type']) ? $_SESSION['auth_type'] : '';
$s3 = checkStep3();
if ($s3['all'] == 'ok') { ?>
@@ -628,7 +636,7 @@ function printStep3() {
<?php
}
-function printStep4() {
+function printStep4(): void {
?>
<p class="alert alert-success"><span class="alert-head"><?= _t('install.congratulations') ?></span> <?= _t('install.ok') ?></p>
<div class="form-group form-actions">
@@ -639,7 +647,7 @@ function printStep4() {
<?php
}
-function printStep5() {
+function printStep5(): void {
?>
<p class="alert alert-error">
<span class="alert-head"><?= _t('gen.short.damn') ?></span>
@@ -676,7 +684,7 @@ case 5:
}
?>
<!DOCTYPE html>
-<html<?php
+<html <?php
if (_t('gen.dir') === 'rtl') {
echo ' dir="rtl" class="rtl"';
}