From 727db957b6b9a03ecc3aa3a6449ab420af2c196d Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Fri, 4 Oct 2024 15:30:48 +0200 Subject: [PATCH] Improve readability by replacing array and cleaning up whitespaces --- application/forms/EditForm.php | 48 ++++++++++---------- application/views/helpers/Breadcrumb.php | 8 ++-- application/views/helpers/Tiles.php | 10 ++-- application/views/helpers/Tree.php | 16 +++---- application/views/scripts/index/index.phtml | 8 ++-- application/views/scripts/show/actions.phtml | 30 ++++++------ library/Toplevelview/Tree/TLVTree.php | 4 +- library/Toplevelview/Tree/TLVTreeNode.php | 12 ++--- 8 files changed, 68 insertions(+), 68 deletions(-) diff --git a/application/forms/EditForm.php b/application/forms/EditForm.php index 5be2cea..3c12f76 100644 --- a/application/forms/EditForm.php +++ b/application/forms/EditForm.php @@ -99,7 +99,7 @@ public function getRedirectUrl() */ public function onRequest() { - $values = array(); + $values = []; $values['name'] = $this->view->getName(); $values['config'] = $this->view->getText(); @@ -124,56 +124,56 @@ public function createElements(array $formData) $this->addElement( 'text', 'name', - array( - 'label' => $this->translate('File name'), + [ + 'label' => $this->translate('File name'), 'required' => true - ) + ] ); $this->addElement( 'textarea', 'config', - array( - 'label' => $this->translate('YAML Config'), - 'class' => 'code-editor codemirror', - 'decorators' => array( - array('Label', array('tag'=>'div', 'separator' => '')), - array('HtmlTag', array('tag' => 'div')), + [ + 'label' => $this->translate('YAML Config'), + 'class' => 'code-editor codemirror', + 'decorators' => [ + ['Label', ['tag' => 'div', 'separator' => '']], + ['HtmlTag', ['tag' => 'div']], 'ViewHelper' - ), + ], 'data-codemirror-mode' => 'yaml' - ) + ] ); $this->addElement( 'submit', 'btn_submit_save_session', - array( + [ 'ignore' => true, 'label' => $this->translate('Save for the current Session'), - 'decorators' => array('ViewHelper') - ) + 'decorators' => ['ViewHelper'] + ] ); $this->addElement( 'submit', 'btn_submit_save_file', - array( + [ 'ignore' => true, 'label' => $this->translate('Save to config file'), - 'decorators' => array('ViewHelper') - ) + 'decorators' => ['ViewHelper'] + ] ); if ($this->view->hasBeenLoadedFromSession()) { $this->addElement( 'submit', 'btn_submit_cancel', - array( + [ 'ignore' => true, 'label' => $this->translate('Cancel editing'), 'class' => 'btn-cancel', - 'decorators' => array('ViewHelper') - ) + 'decorators' => ['ViewHelper'] + ] ); } @@ -181,13 +181,13 @@ public function createElements(array $formData) $this->addElement( 'submit', 'btn_submit_delete', - array( + [ 'ignore' => true, 'label' => $this->translate('Delete config'), 'class' => 'btn-remove', 'onclick' => 'return confirm("' . $this->translate('Confirm deletion') . '")', - 'decorators' => array('ViewHelper') - ) + 'decorators' => ['ViewHelper'] + ] ); } } diff --git a/application/views/helpers/Breadcrumb.php b/application/views/helpers/Breadcrumb.php index 60fccbc..645f86e 100644 --- a/application/views/helpers/Breadcrumb.php +++ b/application/views/helpers/Breadcrumb.php @@ -23,10 +23,10 @@ public function breadcrumb($breadcrumb, $config_name) $htm .= '
  • ' . $this->view->qlink( Str::limit($crumb->getTitle()), 'toplevelview/show/tree', - array( - 'name' => $config_name, - 'id' => $crumb->getFullId() - ) + [ + 'name' => $config_name, + 'id' => $crumb->getFullId() + ] ) . '
  • '; } $htm .= ''; diff --git a/application/views/helpers/Tiles.php b/application/views/helpers/Tiles.php index 73b80a8..575677c 100644 --- a/application/views/helpers/Tiles.php +++ b/application/views/helpers/Tiles.php @@ -22,7 +22,7 @@ public function tiles(TLVTreeNode $node, $levels = 2, $classes = array()) } else { $statusClass = 'tlv-status-tile'; } - $statusClasses = array($statusClass, $status->getOverall()); + $statusClasses = [$statusClass, $status->getOverall()]; $htm .= sprintf( '
    ' . "\n", @@ -34,13 +34,13 @@ public function tiles(TLVTreeNode $node, $levels = 2, $classes = array()) $htm .= $this->view->qlink( $title . $badges, 'toplevelview/show/tree', - array( + [ 'name' => $node->getRoot()->getViewName(), 'id' => $node->getFullId() - ), - array( + ], + [ 'class' => 'tlv-tile-title' - ), + ], false ); diff --git a/application/views/helpers/Tree.php b/application/views/helpers/Tree.php index 85ee47b..4cc8720 100644 --- a/application/views/helpers/Tree.php +++ b/application/views/helpers/Tree.php @@ -41,19 +41,19 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0) $icon = 'services'; $url = Url::fromPath( 'icingadb/servicegroup', - array( + [ 'name' => $node->get('servicegroup'), 'sort' => 'service.state.severity desc' - ) + ] ); } elseif ($type === 'hostgroup') { $icon = 'cubes'; $url = Url::fromPath( 'icingadb/services', - array( + [ 'hostgroup.name' => $node->get('hostgroup'), 'sort' => 'service.state.severity desc' - ) + ] ); if (($h = $status->getMeta('hosts_unhandled')) > 0) { @@ -68,10 +68,10 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0) $htmExtra .= ' ' . $this->view->qlink( $hostTitle, 'icingadb/hosts', - array( + [ 'hostgroup.name' => $node->get('hostgroup'), 'sort' => 'service.state.severity desc' - ), + ], null, false ); @@ -79,10 +79,10 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0) $icon = null; $url = Url::fromPath( 'toplevelview/show/tree', - array( + [ 'name' => $node->getRoot()->getViewName(), 'id' => $node->getFullId() - ) + ] ); } diff --git a/application/views/scripts/index/index.phtml b/application/views/scripts/index/index.phtml index d47ae90..5da3470 100644 --- a/application/views/scripts/index/index.phtml +++ b/application/views/scripts/index/index.phtml @@ -7,11 +7,11 @@ if (! $this->compact): ?> qlink( $this->translate('Add'), 'toplevelview/edit/add', - array(), - array( + [], + [ 'class' => 'action-link', 'icon' => 'plus', - ) + ] ) ?>
    @@ -21,7 +21,7 @@ if (! $this->compact): ?>
    $view): - $url = $this->url('toplevelview/show', array('name' => $name)); + $url = $this->url('toplevelview/show', ['name' => $name]); ?>
    getMeta('name') ?>
    diff --git a/application/views/scripts/show/actions.phtml b/application/views/scripts/show/actions.phtml index a94a438..b3e231a 100644 --- a/application/views/scripts/show/actions.phtml +++ b/application/views/scripts/show/actions.phtml @@ -7,49 +7,49 @@ echo $this->qlink( $this->translate('Source'), 'toplevelview/show/source', - array('name' => $view->getName()), - array( + ['name' => $view->getName()], + [ 'class' => 'action-link', 'icon' => 'doc-text', 'data-base-target' => '_next' - ) + ] ); echo $this->qlink( $this->translate('Fullscreen'), 'toplevelview/show', - array( + [ 'name' => $view->getName(), 'view' => 'compact', 'showFullscreen' => true - ), - array( - 'class' => 'action-link', - 'icon' => 'resize-full', + ], + [ + 'class' => 'action-link', + 'icon' => 'resize-full', 'target' => '_blank' - ) + ] ); if ($this->hasPermission('toplevelview/edit')) { echo $this->qlink( $this->translate('Edit'), 'toplevelview/edit', - array('name' => $view->getName()), - array( + ['name' => $view->getName()], + [ 'class' => 'action-link', 'icon' => 'edit', 'data-base-target' => '_next' - ) + ] ); echo $this->qlink( $this->translate('Clone'), 'toplevelview/edit/clone', - array('name' => $view->getName()), - array( + ['name' => $view->getName()], + [ 'class' => 'action-link', 'icon' => 'rewind', 'data-base-target' => '_next' - ) + ] ); } } diff --git a/library/Toplevelview/Tree/TLVTree.php b/library/Toplevelview/Tree/TLVTree.php index 012e9be..fc6ebd6 100644 --- a/library/Toplevelview/Tree/TLVTree.php +++ b/library/Toplevelview/Tree/TLVTree.php @@ -69,7 +69,7 @@ public function getById($id) return $currentNode; } - public function getViewName(): string + public function getViewName(): ?string { return $this->viewName; } @@ -80,7 +80,7 @@ public function setViewName(string $name) return $this; } - public function getViewChecksum(): string + public function getViewChecksum(): ?string { return $this->viewChecksum; } diff --git a/library/Toplevelview/Tree/TLVTreeNode.php b/library/Toplevelview/Tree/TLVTreeNode.php index 395bfee..bd2ec28 100644 --- a/library/Toplevelview/Tree/TLVTreeNode.php +++ b/library/Toplevelview/Tree/TLVTreeNode.php @@ -70,12 +70,12 @@ class TLVTreeNode extends TreeNode * * @var array */ - protected static $typeMap = array( + protected static $typeMap = [ 'host' => 'Icinga\\Module\\Toplevelview\\Tree\\TLVHostNode', 'service' => 'Icinga\\Module\\Toplevelview\\Tree\\TLVServiceNode', 'hostgroup' => 'Icinga\\Module\\Toplevelview\\Tree\\TLVHostGroupNode', 'servicegroup' => 'Icinga\\Module\\Toplevelview\\Tree\\TLVServiceGroupNode', - ); + ]; /** * Mapping keys to a type @@ -84,12 +84,12 @@ class TLVTreeNode extends TreeNode * * @var array */ - protected static $typeKeyMap = array( - 'service' => array('host', 'service'), + protected static $typeKeyMap = [ + 'service' => ['host', 'service'], 'host' => 'host', 'hostgroup' => 'hostgroup', 'servicegroup' => 'servicegroup', - ); + ]; /** * @param $array @@ -116,7 +116,7 @@ public static function fromArray($array, TLVTreeNode $parent = null, TLVTree $ro if (! array_key_exists('type', $array)) { foreach (self::$typeKeyMap as $type => $keys) { if (! is_array($keys)) { - $keys = array($keys); + $keys = [$keys]; } $matched = false; foreach ($keys as $k) {