Skip to content

Commit

Permalink
fix: resolve SD's review
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Oct 29, 2024
1 parent 2467f30 commit d659e81
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 58 deletions.
23 changes: 11 additions & 12 deletions library/Icingadb/Common/StateBadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function getBaseUrl(): ?Url
*/
protected function getStateInt(string $state): int
{
throw new InvalidArgumentException('%s is not a valid state', $state);
throw new InvalidArgumentException(sprintf('%s is not a valid state', $state));
}

/**
Expand Down Expand Up @@ -147,21 +147,20 @@ public function createLink($content, Filter\Rule $filter = null): Link
protected function createBadge(string $state): ?BaseHtmlElement
{
$key = $this->prefix . "_{$state}";
if (empty($this->item->$key)) {
return null;
}

if (isset($this->item->$key) && $this->item->$key) {
$stateBadge = new StateBadge($this->item->$key, $state);
$stateBadge = new StateBadge($this->item->$key, $state);

if ($this->url !== null) {
$this->createLink(
$stateBadge,
Filter::equal($this->type . '.state.soft_state', $this->getStateInt($state))
);
}

return new HtmlElement('li', null, $stateBadge);
if ($this->url !== null) {
$this->createLink(
$stateBadge,
Filter::equal($this->type . '.state.soft_state', $this->getStateInt($state))
);
}

return null;
return new HtmlElement('li', null, $stateBadge);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Model/Behavior/HasProblematicParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function rewriteColumnDefinition(ColumnDefinition $def, string $relation)

public function rewriteCondition(Filter\Condition $condition, $relation = null): void

Check failure on line 93 in library/Icingadb/Model/Behavior/HasProblematicParent.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.2 on ubuntu-latest

Return type (void) of method Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent::rewriteCondition() should be compatible with return type (ipl\Stdlib\Filter\Rule|null) of method ipl\Orm\Contract\RewriteFilterBehavior::rewriteCondition()

Check failure on line 93 in library/Icingadb/Model/Behavior/HasProblematicParent.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest

Return type (void) of method Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent::rewriteCondition() should be compatible with return type (ipl\Stdlib\Filter\Rule|null) of method ipl\Orm\Contract\RewriteFilterBehavior::rewriteCondition()

Check failure on line 93 in library/Icingadb/Model/Behavior/HasProblematicParent.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Return type (void) of method Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent::rewriteCondition() should be compatible with return type (ipl\Stdlib\Filter\Rule|null) of method ipl\Orm\Contract\RewriteFilterBehavior::rewriteCondition()

Check failure on line 93 in library/Icingadb/Model/Behavior/HasProblematicParent.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Return type (void) of method Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent::rewriteCondition() should be compatible with return type (ipl\Stdlib\Filter\Rule|null) of method ipl\Orm\Contract\RewriteFilterBehavior::rewriteCondition()

Check failure on line 93 in library/Icingadb/Model/Behavior/HasProblematicParent.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.3 on ubuntu-latest

Return type (void) of method Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent::rewriteCondition() should be compatible with return type (ipl\Stdlib\Filter\Rule|null) of method ipl\Orm\Contract\RewriteFilterBehavior::rewriteCondition()

Check failure on line 93 in library/Icingadb/Model/Behavior/HasProblematicParent.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.1 on ubuntu-latest

Return type (void) of method Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent::rewriteCondition() should be compatible with return type (ipl\Stdlib\Filter\Rule|null) of method ipl\Orm\Contract\RewriteFilterBehavior::rewriteCondition()

Check failure on line 93 in library/Icingadb/Model/Behavior/HasProblematicParent.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.0 on ubuntu-latest

Return type (void) of method Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent::rewriteCondition() should be compatible with return type (ipl\Stdlib\Filter\Rule|null) of method ipl\Orm\Contract\RewriteFilterBehavior::rewriteCondition()
{
$column = substr($condition->getColumn(), strlen($relation));
$column = substr($condition->getColumn(), strlen($relation ?? ''));

if ($this->isSelectableColumn($column)) {
throw new InvalidColumnException($column, $this->query->getModel());
Expand Down
64 changes: 29 additions & 35 deletions library/Icingadb/Model/RedundancyGroupSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Icinga\Module\Icingadb\Model;

use ipl\Orm\Query;
use ipl\Sql\Adapter\Pgsql;
use ipl\Sql\Connection;
use ipl\Sql\Expression;
use ipl\Sql\Select;
Expand All @@ -28,55 +27,46 @@ class RedundancyGroupSummary extends RedundancyGroup
public function getSummaryColumns(): array
{
return [
'nodes_total' => new Expression(
'SUM(CASE'
. ' WHEN %s IS NOT NULL THEN 1'
. ' WHEN %s IS NOT NULL THEN 1'
. ' ELSE 0 END)',
[
'from.to.service_id',
'from.to.host_id',
]
),
'nodes_total' => new Expression('COUNT(*)'),
'nodes_ok' => new Expression(
'SUM(CASE'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 0 THEN 1 ELSE 0 END)'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 0 THEN 1 ELSE 0 END)'
. ' ELSE 0 END)',
. ' WHEN %s = 0 THEN 1'
. ' ELSE 0'
. ' END)',
[
'from.to.service.id',
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.host_id',
'from.to.host.state.soft_state',
]
),
'nodes_problem_handled' => new Expression(
'SUM(CASE'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 2 AND (%s = \'y\' OR %s = \'n\') THEN 1 ELSE 0 END)'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 1 AND (%s = \'y\' OR %s = \'n\') THEN 1 ELSE 0 END)'
. ' ELSE 0 END)',
. " WHEN %s IS NOT NULL THEN (CASE WHEN %s = 2 AND (%s = 'y' OR %s = 'n') THEN 1 ELSE 0 END)"
. " WHEN %s = 1 AND (%s = 'y' OR %s = 'n') THEN 1"
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.service.state.is_handled',
'from.to.service.state.is_reachable',
'from.to.host_id',
'from.to.host.state.soft_state',
'from.to.host.state.is_handled',
'from.to.host.state.is_reachable',
]
),
'nodes_problem_unhandled' => new Expression(
'SUM(CASE'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 2 AND (%s = \'n\' AND %s = \'y\') THEN 1 ELSE 0 END)'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 1 AND (%s = \'n\' AND %s = \'y\') THEN 1 ELSE 0 END)'
. ' ELSE 0 END)',
. " WHEN %s IS NOT NULL THEN (CASE WHEN %s = 2 AND (%s = 'n' AND %s = 'y') THEN 1 ELSE 0 END)"
. " WHEN %s = 1 AND (%s = 'n' AND %s = 'y') THEN 1"
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.service.state.is_handled',
'from.to.service.state.is_reachable',
'from.to.host_id',
'from.to.host.state.soft_state',
'from.to.host.state.is_handled',
'from.to.host.state.is_reachable',
Expand All @@ -85,19 +75,20 @@ public function getSummaryColumns(): array
'nodes_pending' => new Expression(
'SUM(CASE'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 99 THEN 1 ELSE 0 END)'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 99 THEN 1 ELSE 0 END)'
. ' ELSE 0 END)',
. ' WHEN %s = 99 THEN 1'
. ' ELSE 0'
. ' END)',
[
'from.to.service.id',
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.host_id',
'from.to.host.state.soft_state',
]
),
'nodes_unknown_handled' => new Expression(
'SUM(CASE'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 3 AND (%s = \'y\' OR %s = \'n\') THEN 1 ELSE 0 END)'
. ' ELSE 0 END)',
. " WHEN %s IS NOT NULL THEN (CASE WHEN %s = 3 AND (%s = 'y' OR %s = 'n') THEN 1 ELSE 0 END)"
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
Expand All @@ -107,8 +98,9 @@ public function getSummaryColumns(): array
),
'nodes_unknown_unhandled' => new Expression(
'SUM(CASE'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 3 AND (%s = \'n\' AND %s = \'y\') THEN 1 ELSE 0 END)'
. ' ELSE 0 END)',
. " WHEN %s IS NOT NULL THEN (CASE WHEN %s = 3 AND (%s = 'n' AND %s = 'y') THEN 1 ELSE 0 END)"
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
Expand All @@ -118,8 +110,9 @@ public function getSummaryColumns(): array
),
'nodes_warning_handled' => new Expression(
'SUM(CASE'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 1 AND (%s = \'y\' OR %s = \'n\') THEN 1 ELSE 0 END)'
. ' ELSE 0 END)',
. " WHEN %s IS NOT NULL THEN (CASE WHEN %s = 1 AND (%s = 'y' OR %s = 'n') THEN 1 ELSE 0 END)"
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
Expand All @@ -129,8 +122,9 @@ public function getSummaryColumns(): array
),
'nodes_warning_unhandled' => new Expression(
'SUM(CASE'
. ' WHEN %s IS NOT NULL THEN (CASE WHEN %s = 1 AND (%s = \'n\' AND %s = \'y\') THEN 1 ELSE 0 END)'
. ' ELSE 0 END)',
. " WHEN %s IS NOT NULL THEN (CASE WHEN %s = 1 AND (%s = 'n' AND %s = 'y') THEN 1 ELSE 0 END)"
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
Expand Down
5 changes: 3 additions & 2 deletions library/Icingadb/Widget/DependencyNodeStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
namespace Icinga\Module\Icingadb\Widget;

use Icinga\Chart\Donut;
use Icinga\Module\Dependencies\Model\DependencyNodeSummary;
use Icinga\Module\Icingadb\Model\RedundancyGroupSummary;
use Icinga\Module\Icingadb\Widget\Detail\ObjectStatistics;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\Html\HtmlString;

/**
/**e
* Dependency node statistics
*/
class DependencyNodeStatistics extends ObjectStatistics
{
/** @var RedundancyGroupSummary Dependency node summary */
/** @var RedundancyGroupSummary|DependencyNodeSummary Dependency node summary*/
protected $summary;

public function __construct($summary)
Expand Down
14 changes: 6 additions & 8 deletions library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use ipl\Web\Widget\TimeSince;

/**
* Redundancy group list item of a root problem list. Represents one database row.
* Redundancy group list item. Represents one database row.
*
* @property RedundancyGroup $item
*/
Expand All @@ -28,7 +28,7 @@ class RedundancyGroupListItem extends StateListItem
use ListItemCommonLayout;
use Database;

protected $defaultAttributes = ['class' => ['list-item', 'redundancy-group-list-item']];
protected $defaultAttributes = ['class' => ['redundancy-group-list-item']];

/** @var RedundancyGroupState */
protected $state;
Expand Down Expand Up @@ -70,14 +70,12 @@ protected function assembleTitle(BaseHtmlElement $title): void
{
$title->addHtml($this->createSubject());
if ($this->state->failed) {
$title->addHtml(HtmlElement::create(
'span',
null,
Text::create($this->translate('has no working objects'))
));
$text = $this->translate('has no working objects');
} else {
$title->addHtml(HtmlElement::create('span', null, Text::create($this->translate('has working objects'))));
$text = $this->translate('has working objects');
}

$title->addHtml(HtmlElement::create('span', null, Text::create($text)));
}

protected function assemble(): void
Expand Down

0 comments on commit d659e81

Please sign in to comment.