From 2a9c06e7f6ca64093945958e93175c1dd3772692 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 14 Mar 2024 14:52:30 +0100 Subject: [PATCH] Some more fixes to make phpstan happy --- application/clicommands/MigrateCommand.php | 9 +++------ .../Command/Transport/CommandTransport.php | 4 ++-- library/Icingadb/Compat/CompatObject.php | 15 ++++++++------- .../Widget/ItemTable/BaseHostGroupItem.php | 4 ++-- .../Widget/ItemTable/BaseServiceGroupItem.php | 4 ++-- .../Widget/ItemTable/HostgroupTableRow.php | 4 ++-- .../Widget/ItemTable/ServicegroupTableRow.php | 4 ++-- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/application/clicommands/MigrateCommand.php b/application/clicommands/MigrateCommand.php index 6d034ee3..17892bb4 100644 --- a/application/clicommands/MigrateCommand.php +++ b/application/clicommands/MigrateCommand.php @@ -496,9 +496,8 @@ class MigrateCommand extends Command ); $changed = false; - /** @var ConfigObject $dashboardConfig */ + /** @var ConfigObject $dashboardConfig */ foreach ($dashboardsConfig->getConfigObject() as $name => $dashboardConfig) { - /** @var ?string $dashboardUrlString */ $dashboardUrlString = $dashboardConfig->get('url'); if ($dashboardUrlString !== null) { $dashBoardUrl = Url::fromPath($dashboardUrlString, [], new Request()); @@ -595,9 +594,8 @@ class MigrateCommand extends Command private function transformNavigationItems(Config $config, string $owner, int &$rc): bool { $updated = false; - /** @var ConfigObject $newConfigObject */ + /** @var ConfigObject $newConfigObject */ foreach ($config->getConfigObject() as $section => $newConfigObject) { - /** @var string $configOwner */ $configOwner = $newConfigObject->get('owner') ?? ''; if ($configOwner && $configOwner !== $owner) { continue; @@ -686,9 +684,8 @@ class MigrateCommand extends Command $newConfig = $config->getConfigFile() === $path ? $config : $this->readFromIni($path, $rc); $updated = false; - /** @var ConfigObject $configObject */ + /** @var ConfigObject $configObject */ foreach ($config->getConfigObject() as $configObject) { - /** @var string $configOwner */ $configOwner = $configObject->get('owner') ?? ''; if ($configOwner && $configOwner !== $owner) { continue; diff --git a/library/Icingadb/Command/Transport/CommandTransport.php b/library/Icingadb/Command/Transport/CommandTransport.php index ea125bc8..952cb148 100644 --- a/library/Icingadb/Command/Transport/CommandTransport.php +++ b/library/Icingadb/Command/Transport/CommandTransport.php @@ -50,7 +50,7 @@ class CommandTransport implements CommandTransportInterface /** * Create a transport from config * - * @param ConfigObject $config + * @param ConfigObject $config * * @return ApiCommandTransport * @@ -59,7 +59,7 @@ class CommandTransport implements CommandTransportInterface public static function createTransport(ConfigObject $config): ApiCommandTransport { $config = clone $config; - switch (strtolower($config->transport)) { + switch (strtolower($config->transport ?? '')) { case ApiCommandTransport::TRANSPORT: $transport = new ApiCommandTransport(); break; diff --git a/library/Icingadb/Compat/CompatObject.php b/library/Icingadb/Compat/CompatObject.php index 6a30751d..1d9657db 100644 --- a/library/Icingadb/Compat/CompatObject.php +++ b/library/Icingadb/Compat/CompatObject.php @@ -361,13 +361,14 @@ trait CompatObject */ private function getBoolType($value) { - switch ($value) { - case false: - return 0; - case true: - return 1; - case 'sticky': - return 2; + if ($value === 'sticky') { + return 2; } + + if (is_string($value)) { + return null; + } + + return (int) $value; } } diff --git a/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php b/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php index c56a1f8f..b3099c80 100644 --- a/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php +++ b/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php @@ -5,7 +5,7 @@ namespace Icinga\Module\Icingadb\Widget\ItemTable; use Icinga\Module\Icingadb\Common\Links; -use Icinga\Module\Icingadb\Model\Hostgroup; +use Icinga\Module\Icingadb\Model\Hostgroupsummary; use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; use ipl\Html\HtmlElement; @@ -18,7 +18,7 @@ use ipl\Web\Widget\Link; /** * Hostgroup item of a hostgroup list. Represents one database row. * - * @property Hostgroup $item + * @property Hostgroupsummary $item * @property HostgroupTable $table */ abstract class BaseHostGroupItem extends BaseTableRowItem diff --git a/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php b/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php index 7bee532e..24f0beaa 100644 --- a/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php +++ b/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php @@ -5,7 +5,7 @@ namespace Icinga\Module\Icingadb\Widget\ItemTable; use Icinga\Module\Icingadb\Common\Links; -use Icinga\Module\Icingadb\Model\Servicegroup; +use Icinga\Module\Icingadb\Model\ServicegroupSummary; use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; use ipl\Html\HtmlElement; @@ -18,7 +18,7 @@ use ipl\Web\Widget\Link; /** * Servicegroup item of a servicegroup list. Represents one database row. * - * @property Servicegroup $item + * @property ServicegroupSummary $item * @property ServicegroupTable $table */ abstract class BaseServiceGroupItem extends BaseTableRowItem diff --git a/library/Icingadb/Widget/ItemTable/HostgroupTableRow.php b/library/Icingadb/Widget/ItemTable/HostgroupTableRow.php index 6aa61c27..cb3f06a9 100644 --- a/library/Icingadb/Widget/ItemTable/HostgroupTableRow.php +++ b/library/Icingadb/Widget/ItemTable/HostgroupTableRow.php @@ -4,7 +4,7 @@ namespace Icinga\Module\Icingadb\Widget\ItemTable; -use Icinga\Module\Icingadb\Model\Hostgroup; +use Icinga\Module\Icingadb\Model\Hostgroupsummary; use Icinga\Module\Icingadb\Widget\Detail\HostStatistics; use Icinga\Module\Icingadb\Widget\Detail\ServiceStatistics; use ipl\Html\BaseHtmlElement; @@ -13,7 +13,7 @@ use ipl\Stdlib\Filter; /** * Hostgroup table row of a hostgroup table. Represents one database row. * - * @property Hostgroup $item + * @property Hostgroupsummary $item * @property HostgroupTable $table */ class HostgroupTableRow extends BaseHostGroupItem diff --git a/library/Icingadb/Widget/ItemTable/ServicegroupTableRow.php b/library/Icingadb/Widget/ItemTable/ServicegroupTableRow.php index 3dea4c1e..e34c029f 100644 --- a/library/Icingadb/Widget/ItemTable/ServicegroupTableRow.php +++ b/library/Icingadb/Widget/ItemTable/ServicegroupTableRow.php @@ -4,7 +4,7 @@ namespace Icinga\Module\Icingadb\Widget\ItemTable; -use Icinga\Module\Icingadb\Model\Servicegroup; +use Icinga\Module\Icingadb\Model\ServicegroupSummary; use Icinga\Module\Icingadb\Widget\Detail\ServiceStatistics; use ipl\Html\BaseHtmlElement; use ipl\Stdlib\Filter; @@ -12,7 +12,7 @@ use ipl\Stdlib\Filter; /** * Servicegroup item of a servicegroup list. Represents one database row. * - * @property Servicegroup $item + * @property ServicegroupSummary $item * @property ServicegroupTable $table */ class ServicegroupTableRow extends BaseServiceGroupItem