N°9144 Fix static analysis issues (#885)

* N°9144 Fix static analysis issues with phpstan
* up to level 1 for all setup files
* up to level 5 for all wizardsteps
This commit is contained in:
Timmy38
2026-04-23 14:08:22 +02:00
committed by GitHub
parent fc2cb86122
commit d0ddb35f8d
27 changed files with 71 additions and 72 deletions

View File

@@ -44,7 +44,7 @@ class WizStepAdminAccount extends WizardStep
return new WizardState(WizStepInstallMiscParams::class);
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$sAdminUser = $this->oWizard->GetParameter('admin_user', 'admin');
$sAdminPwd = $this->oWizard->GetParameter('admin_pwd', '');

View File

@@ -51,7 +51,7 @@ class WizStepDBParams extends WizardStep
return new WizardState(WizStepAdminAccount::class);
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$oPage->add('<h2>Configuration of the database connection:</h2>');
$sDBServer = $this->oWizard->GetParameter('db_server', '');

View File

@@ -64,7 +64,7 @@ class WizStepDataAudit extends WizStepInstall
return false;
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$aInstallParams = $this->BuildConfig();

View File

@@ -69,11 +69,11 @@ class WizStepDetectedInfo extends WizardStep
}
/**
* @param WebPage $oPage
* @param \SetupPage $oPage
*
* @throws Exception
*/
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$oPage->add_style(
<<<EOF

View File

@@ -39,7 +39,7 @@ class WizStepDone extends WizardStep
return new WizardState('');
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
// Check if there are some manual steps required:
$aManualSteps = [];
@@ -102,9 +102,9 @@ class WizStepDone extends WizardStep
$sSetupTokenFile = APPROOT.'data/.setup';
$sSetupToken = bin2hex(random_bytes(12));
file_put_contents($sSetupTokenFile, $sSetupToken);
$sIframeUrl .= "&setup_token=$sSetupToken";
if ($sIframeUrl != '') {
if (mb_strlen($sIframeUrl) > 0) {
$sIframeUrl .= "&setup_token=$sSetupToken";
$oPage->add('<iframe id="fresh_content" frameborder="0" scrolling="auto" src="'.$sIframeUrl.'"></iframe>');
$oPage->add_script("

View File

@@ -70,7 +70,7 @@ class WizStepInstall extends AbstractWizStepInstall
$oPage->add("<div class=\"message message-error ibo-is-html-content\" style=\"display:none;\" id=\"setup_error\"></div>");
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$aInstallParams = $this->BuildConfig();
$this->AddProgressBar($oPage, 'Progress of the installation');

View File

@@ -44,7 +44,7 @@ class WizStepInstallMiscParams extends AbstractWizStepMiscParams
return new WizardState(WizStepModulesChoice::class, 'start_install');
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$sDefaultLanguage = $this->oWizard->GetParameter('default_language', $this->oWizard->GetParameter('admin_language'));
$sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot(true));

View File

@@ -62,7 +62,7 @@ class WizStepInstallOrUpgrade extends WizardStep
return new WizardState($sNextStep);
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$sInstallMode = $this->oWizard->GetParameter('install_mode', '');
$sDBServer = $this->oWizard->GetParameter('db_server', '');
@@ -121,8 +121,7 @@ HTML
$sDBName,
$sDBPrefix,
$sTlsEnabled,
$sTlsCA,
null
$sTlsCA
);
$sAuthentToken = $this->oWizard->GetParameter('authent', '');

View File

@@ -60,9 +60,9 @@ class WizStepLicense extends WizardStep
}
/**
* @param WebPage $oPage
* @param \SetupPage $oPage
*/
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$aLicenses = SetupUtils::GetLicenses();
$oPage->add_style(

View File

@@ -145,7 +145,7 @@ class WizStepModulesChoice extends WizardStep
throw new Exception('Internal error: invalid step "'.$index.'" for the choice of modules.');
} elseif ($bMoveForward) {
if ($this->GetStepInfo(1 + $index) != null) {
return new WizardState(WizStepModulesChoice::class, (1 + $index));
return new WizardState(WizStepModulesChoice::class, (string)($index +1));
} else {
// Exiting this step of the wizard, let's convert the selection into a list of modules
$aModules = [];
@@ -173,10 +173,10 @@ class WizStepModulesChoice extends WizardStep
}
//Unused when going backward
return new WizardState(WizStepModulesChoice::class, ($index - 1));
return new WizardState(WizStepModulesChoice::class, (string)($index - 1));
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$this->DisplayStep($oPage);
}
@@ -390,14 +390,12 @@ EOF
}
if (isset($aChoice['sub_options'])) {
$aScores[$sChoiceId] = array_merge($aScores[$sChoiceId], $this->GuessDefaultsFromModules($aChoice['sub_options'], $aDefaults, $sChoiceId));
$aScores[$sChoiceId] = array_merge($aScores[$sChoiceId], $this->GuessDefaultsFromModules($aChoice['sub_options'], $aDefaults, $aModules, $sChoiceId));
}
$index++;
}
$aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : [];
$sChoiceName = null;
$sChoiceIdNone = null;
foreach ($aAlternatives as $index => $aChoice) {
$sChoiceId = $sParentId.self::$SEP.$index;
$aScores[$sChoiceId] = [];
@@ -413,7 +411,6 @@ EOF
$aScores[$sChoiceId] = $this->GuessDefaultsFromModules($aChoice['sub_options'], $aDefaults, $aModules, $sChoiceId);
}
}
$index++;
}
$iMaxScore = 0;
@@ -517,7 +514,7 @@ EOF
foreach ($aChoice['modules'] as $sModuleId) {
$bSelected = true;
if (isset($aModuleInfo[$sModuleId])) {
// Test if module has 'auto_select'
/** @var array $aCurrentModuleInfo */
$aCurrentModuleInfo = $aModuleInfo[$sModuleId];
if (isset($aCurrentModuleInfo['auto_select'])) {
// Check the module selection
@@ -760,9 +757,6 @@ EOF
foreach ($aAlternatives as $index => $aChoice) {
$sChoiceId = $sParentId.self::$SEP.$index;
if ($sChoiceName === null) {
$sChoiceName = $sChoiceId; // All radios share the same name
}
$bSelected = isset($aSelectedComponents[$sChoiceName]) && ($aSelectedComponents[$sChoiceName] === $sChoiceId);
if (!isset($aSelectedComponents[$sChoiceName]) && ($sChoiceIdNone !== null)) {
// No choice selected, select the "None" option

View File

@@ -65,7 +65,7 @@ class WizStepSummary extends AbstractWizStepInstall
return new WizardState(WizStepInstall::class);
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$aInstallParams = $this->BuildConfig();
@@ -100,7 +100,7 @@ class WizStepSummary extends AbstractWizStepInstall
$oPage->add('<div class="closed"><a class="title ibo-setup-summary-title" href="#" aria-label="Extensions to be uninstalled">Extensions to be uninstalled</a>');
$aExtensionsRemoved = json_decode($this->oWizard->GetParameter('removed_extensions'), true) ?? [];
$aExtensionsNotUninstallable = json_decode($this->oWizard->GetParameter('extensions_not_uninstallable'));
$aExtensionsNotUninstallable = json_decode($this->oWizard->GetParameter('extensions_not_uninstallable')) ?? [];
if (count($aExtensionsRemoved) > 0) {
$sExtensionsRemoved = '<ul>';
foreach ($aExtensionsRemoved as $sExtensionCode => $sLabel) {

View File

@@ -44,7 +44,7 @@ class WizStepUpgradeMiscParams extends AbstractWizStepMiscParams
return new WizardState(WizStepModulesChoice::class, 'start_upgrade');
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
$sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetAbsoluteUrlAppRoot(true)); //Preserve existing configuration (except for the str_replace based joker $SERVER_NAME$ which is lost)
$sDefaultGraphvizPath = (strtolower(substr(PHP_OS, 0, 3)) === 'win') ? 'C:\\Program Files\\Graphviz\\bin\\dot.exe' : '/usr/bin/dot';

View File

@@ -53,7 +53,7 @@ class WizStepWelcome extends WizardStep
return new WizardState(WizStepInstallOrUpgrade::class);
}
public function Display(WebPage $oPage)
public function Display(SetupPage $oPage): void
{
// Store the misc_options for the future...
$aMiscOptions = utils::ReadParam('option', [], false, 'raw_data');

View File

@@ -2,7 +2,7 @@
class WizardState
{
public function __construct($sNextStep, $sCurrentState = '')
public function __construct(string $sNextStep, string $sCurrentState = '')
{
$this->sNextStep = $sNextStep;
$this->sCurrentState = $sCurrentState;

View File

@@ -107,16 +107,19 @@ abstract class WizardStep
* The page can contain any number of "<input/>" fields, but no "<form>...</form>" tag
* The name of the input fields (and their id if one is supplied) MUST NOT start with "_"
* (this is reserved for the wizard's own parameters)
*
* @param \SetupPage $oPage
*
* @return void
*/
abstract public function Display(WebPage $oPage);
abstract public function Display(SetupPage $oPage): void;
/**
* Processes the page's parameters and (if moving forward) returns the next step/state to be displayed
* @param bool $bMoveForward True if the wizard is moving forward 'Next >>' button pressed, false otherwise
* @return hash array('class' => $sNextClass, 'state' => $sNextState)
* @return WizardState array('class' => $sNextClass, 'state' => $sNextState)
*/
abstract public function UpdateWizardStateAndGetNextStep($bMoveForward = true): WizardState;
abstract public function UpdateWizardStateAndGetNextStep(bool $bMoveForward = true): WizardState;
/**
* Returns the list of possible steps from this step forward
@@ -205,7 +208,7 @@ abstract class WizardStep
/**
* Overload this function to implement asynchronous action(s) (AJAX)
* @param string $sCode The code of the action (if several actions need to be distinguished)
* @param hash $aParameters The action's parameters name => value
* @param array $aParameters The action's parameters name => value
*/
public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
{