Skip to content

Commit

Permalink
qa: Improve code style with phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyfrosch committed Feb 28, 2019
1 parent 8a9f955 commit 8b6197b
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 50 deletions.
11 changes: 7 additions & 4 deletions application/controllers/EditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ public function indexAction()
{
$action = $this->getRequest()->getActionName();
if ($action === 'add') {
$this->view->title = sprintf('%s Top Level View',
$this->view->title = sprintf(
'%s Top Level View',
$this->translate('Add')
);
$view = new ViewConfig();
$view->setConfigDir();
} else if ($action === 'clone') {
} elseif ($action === 'clone') {
$name = $this->params->getRequired('name');
$this->view->title = sprintf('%s Top Level View',
$this->view->title = sprintf(
'%s Top Level View',
$this->translate('Clone')
);
$view = clone ViewConfig::loadByName($name);
} else {
$this->view->name = $name = $this->params->getRequired('name');
$this->view->title = sprintf('%s Top Level View: %s',
$this->view->title = sprintf(
'%s Top Level View: %s',
$this->translate('Edit'),
$this->params->getRequired('name')
);
Expand Down
7 changes: 4 additions & 3 deletions application/forms/EditForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public function onSuccess()
if ($this->getElement('btn_submit_save_file')->getValue() !== null) {
$this->viewConfig->store();
Notification::success($this->translate('Top Level View successfully saved'));
} else if ($cancel !== null && $cancel->getValue() !== null) {
} elseif ($cancel !== null && $cancel->getValue() !== null) {
$this->viewConfig->clearSession();
Notification::success($this->translate('Top Level View restored from disk'));
} else if ($delete != null && $delete->getValue() !== null) {
} elseif ($delete != null && $delete->getValue() !== null) {
$this->viewConfig->delete();
$this->setRedirectUrl('toplevelview');
Notification::success($this->translate('Top Level View successfully deleted'));
Expand Down Expand Up @@ -100,7 +100,8 @@ public function createElements(array $formData)
$this->translate(
'This config is only stored in your session!'
. ' Make sure to save it to disk once your work is complete!'
), false
),
false
);
}

Expand Down
3 changes: 1 addition & 2 deletions application/views/helpers/Badges.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public function badges(TLVStatus $status, $problemsOnly = true, $showTotal = fal
$values = false;
$htm .= '<div class="badges">';
foreach ($status->getProperties() as $key => $value) {
if (
$problemsOnly === true && ($key === 'ok' || $key === 'downtime_active')
if ($problemsOnly === true && ($key === 'ok' || $key === 'downtime_active')
|| ($key === 'total' && $showTotal !== true)
) {
continue;
Expand Down
8 changes: 4 additions & 4 deletions application/views/helpers/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public function breadcrumb($breadcrumb, $config_name)
$htm = '<ul class="breadcrumb">';
foreach ($breadcrumb as $crumb) {
$htm .= '<li>' . $this->view->qlink(
$crumb->getTitle(),
'toplevelview/show/tree',
array(
$crumb->getTitle(),
'toplevelview/show/tree',
array(
'name' => $config_name,
'id' => $crumb->getFullId()
)
) . '</li>';
) . '</li>';
}
$htm .= '</ul>';
return $htm;
Expand Down
3 changes: 2 additions & 1 deletion application/views/helpers/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0)
$htm .= ' ' . $this->view->badges($status, false);
$htm .= '</div>';
} else {
$htm .= "<div class=\"tlv-tree-node tlv-status-section collapsible $statusClass $cssClasses\" title=\"$title\">";
$htm .= "<div class=\"tlv-tree-node tlv-status-section collapsible $statusClass $cssClasses\"";
$htm .= " title=\"$title\">";
$htm .= '<div class="tlv-tree-title">';
$htm .= $this->view->badges($status, false, $level === 0 ? true : false);
$htm .= '<i class="icon icon-bycss collapse-handle"></i> ';
Expand Down
1 change: 0 additions & 1 deletion configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
'label' => $viewConfig->getMeta('name'),
'url' => Url::fromPath('toplevelview/show', array('name' => $name)),
));

}
}
} catch (Exception $e) {
Expand Down
6 changes: 3 additions & 3 deletions library/Toplevelview/Legacy/LegacyDbHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ protected function fetchDatabaseHierarchy($root_id)
'hg.view_id = v.id',
array('hg.hostgroup_object_id')
)->where(
'p.id = ?', $root_id
'p.id = ?',
$root_id
)->group(array(
'n.root_id',
'n.lft',
Expand Down Expand Up @@ -160,8 +161,7 @@ protected function buildTree($root_id, $nodes, &$hosts, &$services, &$hostgroups
unset($node->level);
}

if (
property_exists($node, 'host_object_id')
if (property_exists($node, 'host_object_id')
&& $node->host_object_id !== null
&& $currentHostId !== $node->host_object_id
) {
Expand Down
57 changes: 49 additions & 8 deletions library/Toplevelview/Monitoring/HostgroupQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,62 @@ public function init()
'servicestatus' => array(
'service_notifications_enabled' => 'ss.notifications_enabled',
'service_is_flapping' => 'ss.is_flapping',
'service_state' => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE CASE WHEN ss.state_type = 1 THEN ss.current_state ELSE ss.last_hard_state END END',
'service_handled' => 'CASE WHEN (ss.problem_has_been_acknowledged + COALESCE(hs.current_state, 0)) > 0 THEN 1 ELSE 0 END',
'service_handled_wo_host' => 'CASE WHEN ss.problem_has_been_acknowledged > 0 THEN 1 ELSE 0 END',
'service_in_downtime' => 'CASE WHEN (ss.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
'service_state' => '
CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL
THEN 99
ELSE CASE WHEN ss.state_type = 1
THEN ss.current_state
ELSE ss.last_hard_state
END
END',
'service_handled' => '
CASE WHEN (ss.problem_has_been_acknowledged + COALESCE(hs.current_state, 0)) > 0
THEN 1
ELSE 0
END',
'service_handled_wo_host' => '
CASE WHEN ss.problem_has_been_acknowledged > 0
THEN 1
ELSE 0
END',
'service_in_downtime' => '
CASE WHEN (ss.scheduled_downtime_depth = 0)
THEN 0
ELSE 1
END',
),
'hoststatus' => array(
'host_notifications_enabled' => 'hs.notifications_enabled',
'host_is_flapping' => 'hs.is_flapping',
'host_state' => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE CASE WHEN hs.state_type = 1 THEN hs.current_state ELSE hs.last_hard_state END END',
'host_handled' => 'CASE WHEN hs.problem_has_been_acknowledged > 0 THEN 1 ELSE 0 END',
'host_in_downtime' => 'CASE WHEN (hs.scheduled_downtime_depth = 0) THEN 0 ELSE 1 END',
'host_state' => '
CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL
THEN 99
ELSE CASE WHEN hs.state_type = 1
THEN hs.current_state
ELSE hs.last_hard_state
END
END',
'host_handled' => '
CASE WHEN hs.problem_has_been_acknowledged > 0
THEN 1
ELSE 0
END',
'host_in_downtime' => '
CASE WHEN (hs.scheduled_downtime_depth = 0)
THEN 0
ELSE 1
END',
),
'servicenotificationperiod' => array(
'service_notification_period' => 'ntpo.name1',
'service_in_notification_period' => 'CASE WHEN ntpo.object_id IS NULL THEN 1 ELSE CASE WHEN ntpr.timeperiod_id IS NOT NULL THEN 1 ELSE 0 END END',
'service_in_notification_period' => '
CASE WHEN ntpo.object_id IS NULL
THEN 1
ELSE CASE WHEN ntpr.timeperiod_id IS NOT NULL
THEN 1
ELSE 0
END
END',
),
);

Expand Down
48 changes: 32 additions & 16 deletions library/Toplevelview/Monitoring/HostgroupsummaryQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public function __construct($ds, $columns = null, $options = null)
public function init()
{
if ($this->getOption('notification_periods') === true) {
$serviceOutDowntime = 'service_notifications_enabled = 1 AND service_in_downtime = 0 AND service_in_notification_period = 1';
$serviceInDowntime = '(service_notifications_enabled = 0 OR service_in_downtime = 1 OR service_in_notification_period = 0)';
$serviceOutDowntime =#
'service_notifications_enabled = 1 AND service_in_downtime = 0 AND service_in_notification_period = 1';
$serviceInDowntime =
'(service_notifications_enabled = 0 OR service_in_downtime = 1 OR service_in_notification_period = 0)';
} else {
$serviceOutDowntime = 'service_notifications_enabled = 1 AND service_in_downtime = 0';
$serviceInDowntime = '(service_notifications_enabled = 0 OR service_in_downtime = 1)';
Expand All @@ -46,20 +48,34 @@ public function init()

$patchedColumnMap = array(
'hostgroupsummary' => array(
'hosts_down_handled' => "SUM(CASE WHEN host_state = 1 AND $patchHostsHandled THEN 1 ELSE 0 END)",
'hosts_down_unhandled' => "SUM(CASE WHEN host_state = 1 AND $patchHostsUnhandled THEN 1 ELSE 0 END)",
'hosts_unreachable_handled' => "SUM(CASE WHEN host_state = 2 AND $patchHostsHandled THEN 1 ELSE 0 END)",
'hosts_unreachable_unhandled' => "SUM(CASE WHEN host_state = 2 AND $patchHostsUnhandled THEN 1 ELSE 0 END)",
'hosts_downtime_handled' => "SUM(CASE WHEN host_state != 0 AND $hostInDowntime THEN 1 ELSE 0 END)",
'hosts_downtime_active' => "SUM(CASE WHEN $hostInDowntime THEN 1 ELSE 0 END)",
'services_critical_handled' => "SUM(CASE WHEN service_state = 2 AND $patchServicesHandled THEN 1 ELSE 0 END)",
'services_critical_unhandled' => "SUM(CASE WHEN service_state = 2 AND $patchServicesUnhandled THEN 1 ELSE 0 END)",
'services_unknown_handled' => "SUM(CASE WHEN service_state = 3 AND $patchServicesHandled THEN 1 ELSE 0 END)",
'services_unknown_unhandled' => "SUM(CASE WHEN service_state = 3 AND $patchServicesUnhandled THEN 1 ELSE 0 END)",
'services_warning_handled' => "SUM(CASE WHEN service_state = 1 AND $patchServicesHandled THEN 1 ELSE 0 END)",
'services_warning_unhandled' => "SUM(CASE WHEN service_state = 1 AND $patchServicesUnhandled THEN 1 ELSE 0 END)",
'services_downtime_handled' => "SUM(CASE WHEN service_state != 0 AND $serviceInDowntime THEN 1 ELSE 0 END)",
'services_downtime_active' => "SUM(CASE WHEN $serviceInDowntime THEN 1 ELSE 0 END)",
'hosts_down_handled' =>
"SUM(CASE WHEN host_state = 1 AND $patchHostsHandled THEN 1 ELSE 0 END)",
'hosts_down_unhandled' =>
"SUM(CASE WHEN host_state = 1 AND $patchHostsUnhandled THEN 1 ELSE 0 END)",
'hosts_unreachable_handled' =>
"SUM(CASE WHEN host_state = 2 AND $patchHostsHandled THEN 1 ELSE 0 END)",
'hosts_unreachable_unhandled' =>
"SUM(CASE WHEN host_state = 2 AND $patchHostsUnhandled THEN 1 ELSE 0 END)",
'hosts_downtime_handled' =>
"SUM(CASE WHEN host_state != 0 AND $hostInDowntime THEN 1 ELSE 0 END)",
'hosts_downtime_active' =>
"SUM(CASE WHEN $hostInDowntime THEN 1 ELSE 0 END)",
'services_critical_handled' =>
"SUM(CASE WHEN service_state = 2 AND $patchServicesHandled THEN 1 ELSE 0 END)",
'services_critical_unhandled' =>
"SUM(CASE WHEN service_state = 2 AND $patchServicesUnhandled THEN 1 ELSE 0 END)",
'services_unknown_handled' =>
"SUM(CASE WHEN service_state = 3 AND $patchServicesHandled THEN 1 ELSE 0 END)",
'services_unknown_unhandled' =>
"SUM(CASE WHEN service_state = 3 AND $patchServicesUnhandled THEN 1 ELSE 0 END)",
'services_warning_handled' =>
"SUM(CASE WHEN service_state = 1 AND $patchServicesHandled THEN 1 ELSE 0 END)",
'services_warning_unhandled' =>
"SUM(CASE WHEN service_state = 1 AND $patchServicesUnhandled THEN 1 ELSE 0 END)",
'services_downtime_handled' =>
"SUM(CASE WHEN service_state != 0 AND $serviceInDowntime THEN 1 ELSE 0 END)",
'services_downtime_active' =>
"SUM(CASE WHEN $serviceInDowntime THEN 1 ELSE 0 END)",
)
);

Expand Down
9 changes: 8 additions & 1 deletion library/Toplevelview/Monitoring/ServicestatusQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ public function init()
),
'servicenotificationperiod' => array(
'service_notification_period' => 'ntpo.name1',
'service_in_notification_period' => 'CASE WHEN ntpo.name1 IS NULL THEN 1 ELSE CASE WHEN ntpr.timeperiod_id IS NOT NULL THEN 1 ELSE 0 END END',
'service_in_notification_period' => '
CASE WHEN ntpo.name1 IS NULL
THEN 1
ELSE CASE WHEN ntpr.timeperiod_id IS NOT NULL
THEN 1
ELSE 0
END
END',
),
);

Expand Down
3 changes: 1 addition & 2 deletions library/Toplevelview/Tree/TLVServiceNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public function getStatus()
}
$isHandled = $isHandled || $data->service_is_flapping === '1';

if (
$data->service_in_downtime > 0
if ($data->service_in_downtime > 0
|| $data->service_notifications_enabled === '0'
|| $notInPeriod
) {
Expand Down
6 changes: 2 additions & 4 deletions library/Toplevelview/Tree/TLVTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ protected function loadCache()
if ($cache->has($cacheName)) {
$cachedData = Json::decode($cache->get($cacheName));

if (
property_exists($cachedData, 'data')
if (property_exists($cachedData, 'data')
&& $cachedData->data !== null
&& property_exists($cachedData, 'ts')
&& $cachedData->ts <= $currentTime // too new maybe
Expand Down Expand Up @@ -201,8 +200,7 @@ public function getFetched($type, $key)
{
$this->ensureFetched();

if (
array_key_exists($key, $this->registeredObjects[$type])
if (array_key_exists($key, $this->registeredObjects[$type])
&& $this->registeredObjects[$type][$key] !== null
) {
return $this->registeredObjects[$type][$key];
Expand Down
2 changes: 1 addition & 1 deletion library/Toplevelview/Util/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function encode($value, $options = 0, $depth = 512)
{
if (version_compare(phpversion(), '5.4.0', '<')) {
$encoded = json_encode($value);
} else if (version_compare(phpversion(), '5.5.0', '<')) {
} elseif (version_compare(phpversion(), '5.5.0', '<')) {
$encoded = json_encode($value, $options);
} else {
$encoded = json_encode($value, $options, $depth);
Expand Down

0 comments on commit 8b6197b

Please sign in to comment.