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

@@ -152,9 +152,9 @@ try {
$sConfigFile = utils::GetConfigFilePath(ITOP_DEFAULT_ENV); $sConfigFile = utils::GetConfigFilePath(ITOP_DEFAULT_ENV);
if (file_exists($sConfigFile) && !is_writable($sConfigFile) && $oStep->RequiresWritableConfig()) { if (file_exists($sConfigFile) && !is_writable($sConfigFile) && $oStep->RequiresWritableConfig()) {
$sRelativePath = utils::GetConfigFilePathRelative(ITOP_DEFAULT_ENV); $sRelativePath = utils::GetConfigFilePathRelative(ITOP_DEFAULT_ENV);
$oPage->error("<b>Error:</b> the configuration file '".$sRelativePath."' already exists and cannot be overwritten."); $sErrorMsg = "<b>Error:</b> the configuration file '".$sRelativePath."' already exists and cannot be overwritten.";
$oPage->p("The wizard cannot modify the configuration file for you. If you want to upgrade ".ITOP_APPLICATION.", make sure that the file '<b>".$sRelativePath."</b>' can be modified by the web server."); $sErrorMsg .= "The wizard cannot modify the configuration file for you. If you want to upgrade ".ITOP_APPLICATION.", make sure that the file '<b>".$sRelativePath."</b>' can be modified by the web server.";
$oPage->output(); throw new Exception($sErrorMsg);
} else { } else {
$oStep->AsyncAction($oPage, $sActionCode, $aParams); $oStep->AsyncAction($oPage, $sActionCode, $aParams);
} }
@@ -180,9 +180,5 @@ try {
} }
if (function_exists('memory_get_peak_usage')) { if (function_exists('memory_get_peak_usage')) {
if ($sOperation == 'file') { SetupLog::Info("operation '$sOperation', peak memory usage. ".memory_get_peak_usage());
SetupLog::Info("loading file '$sFileName', peak memory usage. ".memory_get_peak_usage());
} else {
SetupLog::Info("operation '$sOperation', peak memory usage. ".memory_get_peak_usage());
}
} }

View File

@@ -136,7 +136,7 @@ class DBBackup
/** /**
* Create a normalized backup name, depending on the current date/time and Database * Create a normalized backup name, depending on the current date/time and Database
* *
* @param string sMySQLBinDir Name and path, eventually containing itop placeholders + time formatting specs * @param string $sMySQLBinDir Name and path, eventually containing itop placeholders + time formatting specs
*/ */
public function SetMySQLBinDir($sMySQLBinDir) public function SetMySQLBinDir($sMySQLBinDir)
{ {

View File

@@ -29,7 +29,7 @@ if (!class_exists('DOMDocument')) {
*/ */
class DOMDocument class DOMDocument
{ {
public function __construct() public function __construct(string $version = "1.0", string $encoding = "")
{ {
throw new Exception('The dom extension is not enabled'); throw new Exception('The dom extension is not enabled');
} }
@@ -45,7 +45,7 @@ if (!class_exists('DOMElement')) {
*/ */
class DOMElement class DOMElement
{ {
public function __construct() public function __construct(string $qualifiedName, ?string $value = null, string $namespace = "")
{ {
throw new Exception('The dom extension is not enabled'); throw new Exception('The dom extension is not enabled');
} }

View File

@@ -1562,13 +1562,6 @@ EOF;
foreach ($aStatesOrder as $sState => $foo) { foreach ($aStatesOrder as $sState => $foo) {
$oState = $aStates[$sState]; $oState = $aStates[$sState];
$oInitialStatePath = $oState->GetOptionalElement('initial_state_path'); $oInitialStatePath = $oState->GetOptionalElement('initial_state_path');
if ($oInitialStatePath) {
$aInitialStatePath = [];
foreach ($oInitialStatePath->getElementsByTagName('state_ref') as $oIntermediateState) {
$aInitialStatePath[] = "'".$oIntermediateState->GetText()."'";
}
$sInitialStatePath = 'Array('.implode(', ', $aInitialStatePath).')';
}
$sLifecycle .= " MetaModel::Init_DefineState(\n"; $sLifecycle .= " MetaModel::Init_DefineState(\n";
$sLifecycle .= " \"".$sState."\",\n"; $sLifecycle .= " \"".$sState."\",\n";
@@ -1597,6 +1590,11 @@ EOF;
$sLifecycle .= " ),\n"; $sLifecycle .= " ),\n";
if (!is_null($oInitialStatePath)) { if (!is_null($oInitialStatePath)) {
$aInitialStatePath = [];
foreach ($oInitialStatePath->getElementsByTagName('state_ref') as $oIntermediateState) {
$aInitialStatePath[] = "'".$oIntermediateState->GetText()."'";
}
$sInitialStatePath = 'Array('.implode(', ', $aInitialStatePath).')';
$sLifecycle .= " \"initial_state_path\" => $sInitialStatePath,\n"; $sLifecycle .= " \"initial_state_path\" => $sInitialStatePath,\n";
} }
$sLifecycle .= " )\n"; $sLifecycle .= " )\n";
@@ -2487,6 +2485,8 @@ EOF
// Generate SCSS declaration // Generate SCSS declaration
$sScss = ""; $sScss = "";
$sMainColorCssVariableName = null;
$sComplementaryColorCssVariableName = null;
if ($bHasAtLeastOneColor) { if ($bHasAtLeastOneColor) {
if ($bHasMainColor) { if ($bHasMainColor) {
$sMainColorScssVariableName = "\$$sCssRegularClass--main-color"; $sMainColorScssVariableName = "\$$sCssRegularClass--main-color";
@@ -2503,8 +2503,10 @@ EOF
$sCssAlternativeClassComplementaryColorDeclaration = "--ibo-complementary-color: #{{$sMainColorScssVariableName}};"; $sCssAlternativeClassComplementaryColorDeclaration = "--ibo-complementary-color: #{{$sMainColorScssVariableName}};";
} else { } else {
$sMainColorScssVariableDeclaration = null; $sMainColorScssVariableDeclaration = null;
$sMainColorCssVariableDeclaration = null;
$sCssRegularClassMainColorDeclaration = null; $sCssRegularClassMainColorDeclaration = null;
$sCssRegularClassMainColor100Declaration = null;
$sCssRegularClassMainColor900Declaration = null; $sCssRegularClassMainColor900Declaration = null;
$sCssAlternativeClassComplementaryColorDeclaration = null; $sCssAlternativeClassComplementaryColorDeclaration = null;
@@ -3358,6 +3360,7 @@ EOF;
clearstatcache(); clearstatcache();
$iDataXmlFileLastModified = 0; $iDataXmlFileLastModified = 0;
$sDataXmlProvidedPrecompiledFile = '';
if (!empty($sPrecompiledFileUri)) { if (!empty($sPrecompiledFileUri)) {
$sDataXmlProvidedPrecompiledFile = $sTempTargetDir.DIRECTORY_SEPARATOR.$sPrecompiledFileUri; $sDataXmlProvidedPrecompiledFile = $sTempTargetDir.DIRECTORY_SEPARATOR.$sPrecompiledFileUri;
$bDataXmlPrecompiledFileExists = file_exists($sDataXmlProvidedPrecompiledFile) ; $bDataXmlPrecompiledFileExists = file_exists($sDataXmlProvidedPrecompiledFile) ;
@@ -3371,7 +3374,6 @@ EOF;
APPROOT.DIRECTORY_SEPARATOR.'extensions/', APPROOT.DIRECTORY_SEPARATOR.'extensions/',
]; ];
$iDataXmlFileLastModified = 0;
foreach ($aDirToCheck as $sDir) { foreach ($aDirToCheck as $sDir) {
$sCurrentFile = $sDir.DIRECTORY_SEPARATOR.$sPrecompiledFileUri; $sCurrentFile = $sDir.DIRECTORY_SEPARATOR.$sPrecompiledFileUri;
if (is_file($sCurrentFile)) { if (is_file($sCurrentFile)) {

View File

@@ -73,7 +73,7 @@ class iTopExtension
public $bVisible; public $bVisible;
/** /**
* @var string[] * @var array
*/ */
public $aModules; public $aModules;
@@ -83,7 +83,7 @@ class iTopExtension
public $aModuleVersion; public $aModuleVersion;
/** /**
* @var string[] * @var array
*/ */
public $aModuleInfo; public $aModuleInfo;
@@ -94,7 +94,7 @@ class iTopExtension
/** /**
* *
* @var string[] * @var array
*/ */
public $aMissingDependencies; public $aMissingDependencies;
/** /**

View File

@@ -1288,7 +1288,7 @@ class ModelFactory
if ($bExcludeWorkspace) { if ($bExcludeWorkspace) {
$aModules = []; $aModules = [];
foreach (self::$aLoadedModules as $oModule) { foreach (self::$aLoadedModules as $oModule) {
if (!$oModule instanceof MFWorkspace) { if (!class_exists('MFWorkspace') || !$oModule instanceof MFWorkspace) {
$aModules[] = $oModule; $aModules[] = $oModule;
} }
} }

View File

@@ -34,7 +34,7 @@ class MissingDependencyException extends CoreException
{ {
/** /**
* @see \ModuleDiscovery::OrderModulesByDependencies property init * @see \ModuleDiscovery::OrderModulesByDependencies property init
* @var array<string, array<string>> * @var array<string, array<array>>
* module id as key * module id as key
* another array as value, containing : 'module' with module info, 'dependencies' with missing dependencies * another array as value, containing : 'module' with module info, 'dependencies' with missing dependencies
*/ */
@@ -410,6 +410,7 @@ class ModuleDiscovery
continue; continue;
} }
/** @var array|null $aCurrentModuleInfo */
$aCurrentModuleInfo = $oExtension->aModuleInfo[$sModuleName] ?? null; $aCurrentModuleInfo = $oExtension->aModuleInfo[$sModuleName] ?? null;
if (is_null($aCurrentModuleInfo)) { if (is_null($aCurrentModuleInfo)) {
SetupLog::Warning("Missing $sModuleName in ".$oExtension->sLabel.". it should not happen"); SetupLog::Warning("Missing $sModuleName in ".$oExtension->sLabel.". it should not happen");

View File

@@ -57,9 +57,8 @@ class ApplicationInstallSequencer extends StepSequencer
*/ */
public function ExecuteStep($sStep = '', $sInstallComment = null): array public function ExecuteStep($sStep = '', $sInstallComment = null): array
{ {
$fStart = microtime(true);
try { try {
$fStart = microtime(true);
/** /**
* @since 3.2.0 move the ContextTag init at the very beginning of the method * @since 3.2.0 move the ContextTag init at the very beginning of the method
* @noinspection PhpUnusedLocalVariableInspection * @noinspection PhpUnusedLocalVariableInspection

View File

@@ -33,9 +33,8 @@ class DataAuditSequencer extends StepSequencer
*/ */
public function ExecuteStep($sStep = '', $sInstallComment = null): array public function ExecuteStep($sStep = '', $sInstallComment = null): array
{ {
$fStart = microtime(true);
try { try {
$fStart = microtime(true);
/** /**
* @since 3.2.0 move the ContextTag init at the very beginning of the method * @since 3.2.0 move the ContextTag init at the very beginning of the method
* @noinspection PhpUnusedLocalVariableInspection * @noinspection PhpUnusedLocalVariableInspection

View File

@@ -58,7 +58,7 @@ class CheckResult
/** /**
* @param \CheckResult[] $aResults * @param \CheckResult[] $aResults
* @param string[] $aCheckResultSeverities list of CheckResult object severities to keep * @param array $aCheckResultSeverities list of CheckResult object severities to keep
* *
* @return \CheckResult[] only elements that have one of the passed severity * @return \CheckResult[] only elements that have one of the passed severity
* *
@@ -458,6 +458,7 @@ class SetupUtils
); );
$sPhpNextMinVersion = self::PHP_NEXT_MIN_VERSION; // mandatory before PHP 5.5 (arbitrary expressions), keeping compat because we're in the setup ! $sPhpNextMinVersion = self::PHP_NEXT_MIN_VERSION; // mandatory before PHP 5.5 (arbitrary expressions), keeping compat because we're in the setup !
// @phpstan-ignore empty.variable
if (!empty($sPhpNextMinVersion)) { if (!empty($sPhpNextMinVersion)) {
if (version_compare($sPhpVersion, self::PHP_NEXT_MIN_VERSION, '>=')) { if (version_compare($sPhpVersion, self::PHP_NEXT_MIN_VERSION, '>=')) {
$aResult[] = new CheckResult( $aResult[] = new CheckResult(
@@ -1351,6 +1352,7 @@ EOF
); );
$sMySqlNextMinVersion = self::MYSQL_NEXT_MIN_VERSION; // mandatory before PHP 5.5 (arbitrary expressions), keeping compat because we're in the setup ! $sMySqlNextMinVersion = self::MYSQL_NEXT_MIN_VERSION; // mandatory before PHP 5.5 (arbitrary expressions), keeping compat because we're in the setup !
// @phpstan-ignore empty.variable
if (!empty($sMySqlNextMinVersion)) { if (!empty($sMySqlNextMinVersion)) {
if (version_compare($sDBVersion, self::MYSQL_NEXT_MIN_VERSION, '>=')) { if (version_compare($sDBVersion, self::MYSQL_NEXT_MIN_VERSION, '>=')) {
$aResult['checks'][] = new CheckResult( $aResult['checks'][] = new CheckResult(
@@ -1675,8 +1677,8 @@ JS
* @param string $sSourceDir Relative path to the directory to check under $sBaseDir * @param string $sSourceDir Relative path to the directory to check under $sBaseDir
* @param $aManifest * @param $aManifest
* @param array $aExcludeNames * @param array $aExcludeNames
* @param Hash $aResult Used for recursion * @param array $aResult Used for recursion
* @return hash Hash array ('added' => array(), 'removed' => array(), 'modified' => array()) * @return array array ('added' => array(), 'removed' => array(), 'modified' => array())
* @internal param array $aDOMManifest Array of array('path' => relative_path 'size'=> iSize, 'md5' => sHexMD5) * @internal param array $aDOMManifest Array of array('path' => relative_path 'size'=> iSize, 'md5' => sHexMD5)
*/ */
public static function CheckDirAgainstManifest($sBaseDir, $sSourceDir, $aManifest, $aExcludeNames = ['.svn', '.git'], $aResult = null) public static function CheckDirAgainstManifest($sBaseDir, $sSourceDir, $aManifest, $aExcludeNames = ['.svn', '.git'], $aResult = null)
@@ -1801,7 +1803,7 @@ JS
/** /**
* @param string $sInstalledVersion * @param string $sInstalledVersion
* @param string $sSourceDir * @param string $sSourceDir
* @return bool|hash * @return bool|array
* @throws Exception * @throws Exception
*/ */
public static function CheckVersion($sInstalledVersion, $sSourceDir) public static function CheckVersion($sInstalledVersion, $sSourceDir)

View File

@@ -67,7 +67,7 @@ class WizardController
/** /**
* Removes information about the previous step from the stack * Removes information about the previous step from the stack
* @return hash Array('class' => , 'state' => ) * @return array{'class': string, 'state': string}
*/ */
protected function PopStep() protected function PopStep()
{ {
@@ -186,9 +186,12 @@ class WizardController
/** /**
* Displays the specified 'step' of the wizard * Displays the specified 'step' of the wizard
*
* @param WizardStep $oStep The 'step' to display * @param WizardStep $oStep The 'step' to display
*
* @throws \Exception
*/ */
protected function DisplayStep(WizardStep $oStep) protected function DisplayStep(WizardStep $oStep): void
{ {
SetupLog::Info("=== Setup screen: ".$oStep->GetTitle().' ('.get_class($oStep).')'); SetupLog::Info("=== Setup screen: ".$oStep->GetTitle().' ('.get_class($oStep).')');
$oPage = new SetupPage($oStep->GetTitle()); $oPage = new SetupPage($oStep->GetTitle());
@@ -313,7 +316,7 @@ on the page's parameters
* Provides information about the structure/workflow of the wizard by listing * Provides information about the structure/workflow of the wizard by listing
* the possible list of 'steps' and their dependencies * the possible list of 'steps' and their dependencies
* @param string $sStep Name of the class to start from (used for recursion) * @param string $sStep Name of the class to start from (used for recursion)
* @param hash $aAllSteps List of steps (used for recursion) * @param array $aAllSteps List of steps (used for recursion)
*/ */
public function DumpStructure($sStep = '', $aAllSteps = null) public function DumpStructure($sStep = '', $aAllSteps = null)
{ {

View File

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

View File

@@ -51,7 +51,7 @@ class WizStepDBParams extends WizardStep
return new WizardState(WizStepAdminAccount::class); 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>'); $oPage->add('<h2>Configuration of the database connection:</h2>');
$sDBServer = $this->oWizard->GetParameter('db_server', ''); $sDBServer = $this->oWizard->GetParameter('db_server', '');

View File

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

View File

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

View File

@@ -39,7 +39,7 @@ class WizStepDone extends WizardStep
return new WizardState(''); return new WizardState('');
} }
public function Display(WebPage $oPage) public function Display(SetupPage $oPage): void
{ {
// Check if there are some manual steps required: // Check if there are some manual steps required:
$aManualSteps = []; $aManualSteps = [];
@@ -102,9 +102,9 @@ class WizStepDone extends WizardStep
$sSetupTokenFile = APPROOT.'data/.setup'; $sSetupTokenFile = APPROOT.'data/.setup';
$sSetupToken = bin2hex(random_bytes(12)); $sSetupToken = bin2hex(random_bytes(12));
file_put_contents($sSetupTokenFile, $sSetupToken); 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('<iframe id="fresh_content" frameborder="0" scrolling="auto" src="'.$sIframeUrl.'"></iframe>');
$oPage->add_script(" $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>"); $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(); $aInstallParams = $this->BuildConfig();
$this->AddProgressBar($oPage, 'Progress of the installation'); $this->AddProgressBar($oPage, 'Progress of the installation');

View File

@@ -44,7 +44,7 @@ class WizStepInstallMiscParams extends AbstractWizStepMiscParams
return new WizardState(WizStepModulesChoice::class, 'start_install'); 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')); $sDefaultLanguage = $this->oWizard->GetParameter('default_language', $this->oWizard->GetParameter('admin_language'));
$sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot(true)); $sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot(true));

View File

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

View File

@@ -65,7 +65,7 @@ class WizStepSummary extends AbstractWizStepInstall
return new WizardState(WizStepInstall::class); return new WizardState(WizStepInstall::class);
} }
public function Display(WebPage $oPage) public function Display(SetupPage $oPage): void
{ {
$aInstallParams = $this->BuildConfig(); $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>'); $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) ?? []; $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) { if (count($aExtensionsRemoved) > 0) {
$sExtensionsRemoved = '<ul>'; $sExtensionsRemoved = '<ul>';
foreach ($aExtensionsRemoved as $sExtensionCode => $sLabel) { foreach ($aExtensionsRemoved as $sExtensionCode => $sLabel) {

View File

@@ -44,7 +44,7 @@ class WizStepUpgradeMiscParams extends AbstractWizStepMiscParams
return new WizardState(WizStepModulesChoice::class, 'start_upgrade'); 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) $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'; $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); return new WizardState(WizStepInstallOrUpgrade::class);
} }
public function Display(WebPage $oPage) public function Display(SetupPage $oPage): void
{ {
// Store the misc_options for the future... // Store the misc_options for the future...
$aMiscOptions = utils::ReadParam('option', [], false, 'raw_data'); $aMiscOptions = utils::ReadParam('option', [], false, 'raw_data');

View File

@@ -2,7 +2,7 @@
class WizardState class WizardState
{ {
public function __construct($sNextStep, $sCurrentState = '') public function __construct(string $sNextStep, string $sCurrentState = '')
{ {
$this->sNextStep = $sNextStep; $this->sNextStep = $sNextStep;
$this->sCurrentState = $sCurrentState; $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 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 "_" * 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) * (this is reserved for the wizard's own parameters)
*
* @param \SetupPage $oPage
*
* @return void * @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 * 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 * @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 * 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) * 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 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) public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
{ {

View File

@@ -37,4 +37,5 @@ parameters:
- ../../../env-toolkit (?) # Irrelevent as it will either already be in `env-production` or might be desynchronized from `env-production` (for local run only, not useful in the CI) - ../../../env-toolkit (?) # Irrelevent as it will either already be in `env-production` or might be desynchronized from `env-production` (for local run only, not useful in the CI)
- ../../../tests (?) # Exclude tests for now - ../../../tests (?) # Exclude tests for now
- ../../../toolkit (?) # Exlclude toolkit for now - ../../../toolkit (?) # Exclude toolkit for now
- ../../../setup/compat # Exclude fake DOMDocument & DOMElement declarations