From 41787d91bfe2f1a51e796ce3c8cea9a2a5faa058 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 25 Mar 2024 14:20:04 +0100 Subject: [PATCH 1/3] Macro: Don't break ui if undefined macro given $object can be an instance of stdClass and cannot call getName(). The name must then be retrieved manually. --- .../monitoring/library/Monitoring/Object/Macro.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/Macro.php b/modules/monitoring/library/Monitoring/Object/Macro.php index 18a18558b..eed52b59b 100644 --- a/modules/monitoring/library/Monitoring/Object/Macro.php +++ b/modules/monitoring/library/Monitoring/Object/Macro.php @@ -69,9 +69,17 @@ class Macro try { $value = $object->$macro; } catch (Exception $e) { - $objectName = $object->getName(); - if ($object instanceof Service) { - $objectName = $object->getHost()->getName() . '!' . $objectName; + if ($object instanceof MonitoredObject) { + $objectName = $object instanceof Service + ? $object->getHost()->getName() . '!' . $object->getName() + : $object->getName(); + } else { + $host = 'host_name'; + $service = 'service_description'; + + $objectName = isset($object->$service) + ? $object->$service . '!' . $object->$host + : $object->$host; } $value = null; From d6ceb9ad11ba745fe13a6cb00645bf6b5754cd57 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 25 Mar 2024 14:27:46 +0100 Subject: [PATCH 2/3] Macro: Fix typo and simplify the code --- .../monitoring/library/Monitoring/Object/Macro.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/Macro.php b/modules/monitoring/library/Monitoring/Object/Macro.php index eed52b59b..4e2687cce 100644 --- a/modules/monitoring/library/Monitoring/Object/Macro.php +++ b/modules/monitoring/library/Monitoring/Object/Macro.php @@ -62,7 +62,7 @@ class Macro */ public static function resolveMacro($macro, $object) { - if (isset(self::$icingaMacros[$macro]) && isset($object->{self::$icingaMacros[$macro]})) { + if (isset(self::$icingaMacros[$macro], $object->{self::$icingaMacros[$macro]})) { return $object->{self::$icingaMacros[$macro]}; } @@ -83,9 +83,14 @@ class Macro } $value = null; - Logger::debug('Unable to resolve macro "%s" on object "%s". An error occured: %s', $macro, $objectName, $e); + Logger::debug( + 'Unable to resolve macro "%s" on object "%s". An error occurred: %s', + $macro, + $objectName, + $e + ); } - return $value !== null ? $value : $macro; + return $value ?? $macro; } } From 68b264f649366089f05f3d40d4d802834a9e0926 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 26 Mar 2024 09:01:52 +0100 Subject: [PATCH 3/3] Update phpstan baseline --- phpstan-baseline-7x.neon | 5 --- phpstan-baseline-8x.neon | 5 --- phpstan-baseline-standard.neon | 57 +++++++++++++++++++++------------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/phpstan-baseline-7x.neon b/phpstan-baseline-7x.neon index 12ae232a6..537e5c613 100644 --- a/phpstan-baseline-7x.neon +++ b/phpstan-baseline-7x.neon @@ -400,11 +400,6 @@ parameters: count: 2 path: library/Icinga/Web/Session/PhpSession.php - - - message: "#^Parameter \\#2 \\$timestamp of function date expects int, int\\|false given\\.$#" - count: 1 - path: library/Icinga/Web/Widget/Chart/HistoryColorGrid.php - - message: "#^Parameter \\#1 \\$str of function strtolower expects string, mixed given\\.$#" count: 1 diff --git a/phpstan-baseline-8x.neon b/phpstan-baseline-8x.neon index 1bff25d02..72f062b2f 100644 --- a/phpstan-baseline-8x.neon +++ b/phpstan-baseline-8x.neon @@ -620,11 +620,6 @@ parameters: count: 1 path: modules/setup/library/Setup/Web/Form/Validator/TokenValidator.php - - - message: "#^Parameter \\#1 \\$filename of function file_exists expects string, string\\|false given\\.$#" - count: 1 - path: modules/test/application/clicommands/PhpCommand.php - - message: "#^Parameter \\#1 \\$callback of function ob_start expects callable\\(\\)\\: mixed, null given\\.$#" count: 1 diff --git a/phpstan-baseline-standard.neon b/phpstan-baseline-standard.neon index 38681eb0c..1bd6e863b 100644 --- a/phpstan-baseline-standard.neon +++ b/phpstan-baseline-standard.neon @@ -430,6 +430,11 @@ parameters: count: 1 path: application/controllers/ConfigController.php + - + message: "#^Parameter \\#1 \\$query of method Icinga\\\\Web\\\\Controller\\:\\:setupPaginationControl\\(\\) expects Icinga\\\\Data\\\\QueryInterface, null given\\.$#" + count: 1 + path: application/controllers/ConfigController.php + - message: "#^Parameter \\#2 \\$name of class Icinga\\\\Application\\\\Modules\\\\Module constructor expects string, mixed given\\.$#" count: 1 @@ -730,6 +735,11 @@ parameters: count: 1 path: application/controllers/ListController.php + - + message: "#^Parameter \\#1 \\$query of method Icinga\\\\Web\\\\Controller\\:\\:setupPaginationControl\\(\\) expects Icinga\\\\Data\\\\QueryInterface, null given\\.$#" + count: 1 + path: application/controllers/ListController.php + - message: "#^Method Icinga\\\\Controllers\\\\ManageUserDevicesController\\:\\:deleteAction\\(\\) has no return type specified\\.$#" count: 1 @@ -950,6 +960,11 @@ parameters: count: 1 path: application/controllers/RoleController.php + - + message: "#^Parameter \\#1 \\$query of method Icinga\\\\Web\\\\Controller\\:\\:setupPaginationControl\\(\\) expects Icinga\\\\Data\\\\QueryInterface, null given\\.$#" + count: 1 + path: application/controllers/RoleController.php + - message: "#^Parameter \\#1 \\$username of class Icinga\\\\User constructor expects string, mixed given\\.$#" count: 1 @@ -2552,6 +2567,11 @@ parameters: - message: "#^Access to an undefined property object\\:\\:\\$permissions\\.$#" + count: 2 + path: application/forms/Security/RoleForm.php + + - + message: "#^Access to an undefined property object\\:\\:\\$refusals\\.$#" count: 1 path: application/forms/Security/RoleForm.php @@ -2565,16 +2585,6 @@ parameters: count: 1 path: application/forms/Security/RoleForm.php - - - message: "#^Access to an undefined property object\\|object\\:\\:\\$permissions\\.$#" - count: 1 - path: application/forms/Security/RoleForm.php - - - - message: "#^Access to an undefined property object\\|object\\:\\:\\$refusals\\.$#" - count: 1 - path: application/forms/Security/RoleForm.php - - message: "#^Call to an undefined method Icinga\\\\Repository\\\\Repository\\:\\:update\\(\\)\\.$#" count: 1 @@ -9046,7 +9056,7 @@ parameters: path: library/Icinga/File/Pdf.php - - message: "#^Cannot access offset 0 on array\\\\|false\\.$#" + message: "#^Cannot access offset 0 on array\\\\|false\\.$#" count: 1 path: library/Icinga/File/Storage/LocalFileStorage.php @@ -11405,11 +11415,6 @@ parameters: count: 1 path: library/Icinga/Util/DirectoryIterator.php - - - message: "#^Parameter \\#1 \\$array of class ArrayIterator constructor expects array\\, array\\\\|false given\\.$#" - count: 1 - path: library/Icinga/Util/DirectoryIterator.php - - message: "#^Parameter \\#1 \\$path of static method Icinga\\\\Util\\\\DirectoryIterator\\:\\:isReadable\\(\\) expects string, string\\|false given\\.$#" count: 1 @@ -16855,11 +16860,6 @@ parameters: count: 3 path: modules/migrate/library/Migrate/Config/UserDomainMigration.php - - - message: "#^Parameter \\#2 \\$filter of static method Icinga\\\\Data\\\\Filter\\\\Filter\\:\\:where\\(\\) expects string, int\\|string given\\.$#" - count: 3 - path: modules/migrate/library/Migrate/Config/UserDomainMigration.php - - message: "#^Property Icinga\\\\Module\\\\Migrate\\\\Config\\\\UserDomainMigration\\:\\:\\$fromDomain has no type specified\\.$#" count: 1 @@ -17665,6 +17665,11 @@ parameters: count: 1 path: modules/monitoring/application/controllers/ShowController.php + - + message: "#^Parameter \\#1 \\$query of method Icinga\\\\Web\\\\Controller\\:\\:setupPaginationControl\\(\\) expects Icinga\\\\Data\\\\QueryInterface, null given\\.$#" + count: 1 + path: modules/monitoring/application/controllers/ShowController.php + - message: "#^Call to an undefined method Icinga\\\\Web\\\\View\\:\\:filteredUrl\\(\\)\\.$#" count: 2 @@ -23915,6 +23920,11 @@ parameters: count: 1 path: modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php + - + message: "#^Parameter \\#1 \\$query of method Icinga\\\\Web\\\\Controller\\:\\:setupPaginationControl\\(\\) expects Icinga\\\\Data\\\\QueryInterface, null given\\.$#" + count: 1 + path: modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php + - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" count: 1 @@ -25545,6 +25555,11 @@ parameters: count: 1 path: modules/test/application/clicommands/PhpCommand.php + - + message: "#^Parameter \\#1 \\$filename of function file_exists expects string, string\\|false given\\.$#" + count: 1 + path: modules/test/application/clicommands/PhpCommand.php + - message: "#^Parameter \\#1 \\$path of function realpath expects string, mixed given\\.$#" count: 1