From 6b795c4a93bf2ed5b11dd269f1683cebb3b8c885 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 4 Sep 2024 14:13:25 +0200 Subject: [PATCH] update arrays to short syntax --- public_html/check-config.php | 6 ++-- .../deployment/classes/logger.class.php | 5 ++-- .../deployment/classes/project_gui.class.php | 16 +++++------ .../deployment/classes/vcs.git.class.php | 28 +++++++++---------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/public_html/check-config.php b/public_html/check-config.php index e271c632..2b1de42c 100644 --- a/public_html/check-config.php +++ b/public_html/check-config.php @@ -165,7 +165,7 @@ function checkCommands(array $aCommands): string $sOut=""; -$aErrors = array(); +$aErrors = []; include("../config/inc_projects_config.php"); if (!isset($aConfig) || !is_array($aConfig)) { // echo showerror("\$aConfig does not exist. The config was not included before including " . __FILE__ . " in the request/ script."); @@ -180,14 +180,14 @@ if (!isset($aConfig) || !is_array($aConfig)) { } $sOut.='<h2>Check subdirs of key dataDir</h2>'; - foreach (array($aConfig['dataDir'] . '/database', $aConfig['dataDir'] . '/projects', $aConfig['dataDir'] . '/sshkeys', ) as $sDir2Check) { + foreach ([$aConfig['dataDir'] . '/database', $aConfig['dataDir'] . '/projects', $aConfig['dataDir'] . '/sshkeys', ] as $sDir2Check) { $sOut.=checkdir($sDir2Check, 'dataDir + [subdir]'); } // ---------------------------------------------------------------------- $sOut.='<h2>Check keys</h2>'; // check required keys in the config - foreach (array('auth', 'build', 'lang', 'phases', 'projects', ) as $sKey) { + foreach (['auth', 'build', 'lang', 'phases', 'projects', ] as $sKey) { $sOut.="Key [$sKey] "; if (!array_key_exists($sKey, $aConfig)) { $sOut.="<span class=\"error\">failed</span> missing key [$sKey] in config<br>"; diff --git a/public_html/deployment/classes/logger.class.php b/public_html/deployment/classes/logger.class.php index 557cb7f5..3cd48d49 100644 --- a/public_html/deployment/classes/logger.class.php +++ b/public_html/deployment/classes/logger.class.php @@ -28,6 +28,7 @@ * 2022-12-15 make it compatible to PHP 8.2; add doc + comments * 2023-05-15 fix _getBar() - division by zero * 2024-07-12 php8 only: use variable types; update phpdocs + * 2024-09-04 fix short array syntax * ---------------------------------------------------------------------- */ class logger @@ -86,12 +87,12 @@ class logger if (!$this->bShowDebug) { return false; } - $this->aMessages[] = array( + $this->aMessages[] = [ 'time' => microtime(true), 'message' => $sMessage, 'level' => preg_replace('/[^a-z0-9\-\_]/', '', $sLevel), 'memory' => memory_get_usage() - ); + ]; return true; } diff --git a/public_html/deployment/classes/project_gui.class.php b/public_html/deployment/classes/project_gui.class.php index 64c13cbe..d6fef253 100644 --- a/public_html/deployment/classes/project_gui.class.php +++ b/public_html/deployment/classes/project_gui.class.php @@ -790,15 +790,15 @@ class projectgui extends project // ---------- Build plugins /* - $aPluginsBuild = array( - 'select' => array( + $aPluginsBuild = [ + 'select' => [ 'type' => 'checkbox', 'name' => 'build[enabled_build_plugins]', 'label' => t("build-plugins"), 'options' => [], - ), + ], // 'project-config' => '', - ); + ]; foreach (array_keys($this->getConfiguredPlugins('build')) as $sPluginName){ $sPluginFile=$this->_getPluginFilename('build', $sPluginName); @@ -809,20 +809,20 @@ class projectgui extends project include_once $this->_getPluginFilename('build', $sPluginName); $TmpRolloutPlugin = new $sMyClassname([]); echo "FOUND $sMyClassname<br>"; - $aPluginsBuild['select']['options'][$sPluginName]=array( + $aPluginsBuild['select']['options'][$sPluginName]=[ 'label' => $TmpRolloutPlugin->getName(), 'checked' => $bActive, // 'onclick' => '$(\'.'.$sMyDivClass.'\').hide(); $(\'.' . $sMyDivClassActive . '\').show();', - ); + ]; } catch (Exception $ex) { } } else { - $aRollout['project-select']['options'][$sPluginName]=array( + $aRollout['project-select']['options'][$sPluginName]=[ 'label' => 'not found: <span class="error">' . $sMyClassname . '</span>', 'checked' => false, 'disabled' => "disabled", - ); + ]; } diff --git a/public_html/deployment/classes/vcs.git.class.php b/public_html/deployment/classes/vcs.git.class.php index c0ae067c..0980c11c 100644 --- a/public_html/deployment/classes/vcs.git.class.php +++ b/public_html/deployment/classes/vcs.git.class.php @@ -89,8 +89,8 @@ class vcs implements iVcs public function setConfig(array $aRepoConfig = []): bool { // checks - // foreach (array("type", "url") as $key) { - foreach (array("type") as $key) { + // foreach (["type", "url"] as $key) { + foreach (["type"] as $key) { if (!isset($aRepoConfig[$key])) { die("ERROR: key $key does not exist in config <pre>" . print_r($aRepoConfig, true) . "</pre>"); } @@ -357,7 +357,7 @@ class vcs implements iVcs // $this->log(__FUNCTION__ . ' $sBranchKey = '.$sBranchKey); // $sMessage = $this->getCommitmessageByBranch($sName, $sRevision); - $aReturn[$sBranchKey] = array( + $aReturn[$sBranchKey] = [ // 'debug'=> $aTmp, 'revision' => $sRevision, 'name' => $sName, @@ -365,7 +365,7 @@ class vcs implements iVcs 'label' => $sType . ': ' . $sBranch, 'type' => $sType, // 'message' => $sMessage - ); + ]; } } $this->_aRemoteBranches = $aReturn; @@ -417,14 +417,14 @@ class vcs implements iVcs } $sMessage = $this->getCommitmessageByBranch(false, $bRefresh ? 'dummy_to_force_refresh' : false); if ($sMessage) { - $aReturn = array( + $aReturn = [ 'branch' => $this->_sCurrentBranch, 'shortname' => $this->_aRemoteBranches[$this->_sCurrentBranch]['shortname'], 'revision' => $this->_aRemoteBranches[$this->_sCurrentBranch]['revision'], 'type' => $this->_aRemoteBranches[$this->_sCurrentBranch]['type'], 'message' => $sMessage, '_data' => $this->_aRemoteBranches[$this->_sCurrentBranch], - ); + ]; } else { $aReturn = $this->getRevision(false); } @@ -488,16 +488,16 @@ class vcs implements iVcs * the return will fill $this->_aData["phases"]["source"] in project class * (array keys are revision, message or error) * if ok: - * array( + * [ * "branch" => $sRevision, * "revision" => $sRevision, * "message" => $sCommitmessage - * ); + * ]; * * on error: - * array( + * [ * "error" => $sErrormessage, - * ); + * ]; * * @param string $sWorkDir optional: local directory with initialized git repo * @return bool|array @@ -581,19 +581,19 @@ class vcs implements iVcs // $sCommitMsg=preg_replace('/Author:\ .*\n/', '', $sCommitMsg); // $sCommitMsg=preg_replace('/Date:\ .*\n/', '', $sCommitMsg); - $aReturn = array( + $aReturn = [ "branch" => $this->_sCurrentBranch, "revision" => $sRevision, "message" => $sCommitMsg // ."\n". microtime(true), - ); + ]; } else { if (!$sLoginfo) { $sLoginfo = $sGitCmd; } // echo "DEBUG: error on reading git revision<br>"; - $aReturn = array( + $aReturn = [ "error" => '<pre>' . $sLoginfo . '<hr>' . $sGitCmd . '</pre>' - ); + ]; } // $this->log(__FUNCTION__ . ' return is <pre>'.print_r($aReturn, 1).'</pre>'); return $aReturn; -- GitLab