Skip to content

Commit

Permalink
Fix broken UI when trying to resolve an undefined $macro$ (#5201)
Browse files Browse the repository at this point in the history
fixes #5168
  • Loading branch information
nilmerg authored Aug 7, 2024
2 parents b268044 + 68b264f commit b370d9b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 36 deletions.
25 changes: 19 additions & 6 deletions modules/monitoring/library/Monitoring/Object/Macro.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,35 @@ public static function resolveMacros($input, $object)
*/
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]};
}

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;
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;
}
}
5 changes: 0 additions & 5 deletions phpstan-baseline-7x.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline-8x.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 35 additions & 20 deletions phpstan-baseline-standard.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2552,26 +2567,21 @@ parameters:

-
message: "#^Access to an undefined property object\\:\\:\\$permissions\\.$#"
count: 1
path: application/forms/Security/RoleForm.php

-
message: "#^Access to an undefined property object\\:\\:\\$unrestricted\\.$#"
count: 1
count: 2
path: application/forms/Security/RoleForm.php

-
message: "#^Access to an undefined property object\\:\\:\\$users\\.$#"
message: "#^Access to an undefined property object\\:\\:\\$refusals\\.$#"
count: 1
path: application/forms/Security/RoleForm.php

-
message: "#^Access to an undefined property object\\|object\\:\\:\\$permissions\\.$#"
message: "#^Access to an undefined property object\\:\\:\\$unrestricted\\.$#"
count: 1
path: application/forms/Security/RoleForm.php

-
message: "#^Access to an undefined property object\\|object\\:\\:\\$refusals\\.$#"
message: "#^Access to an undefined property object\\:\\:\\$users\\.$#"
count: 1
path: application/forms/Security/RoleForm.php

Expand Down Expand Up @@ -9046,7 +9056,7 @@ parameters:
path: library/Icinga/File/Pdf.php

-
message: "#^Cannot access offset 0 on array\\<mixed, mixed\\>\\|false\\.$#"
message: "#^Cannot access offset 0 on array\\<mixed\\>\\|false\\.$#"
count: 1
path: library/Icinga/File/Storage/LocalFileStorage.php

Expand Down Expand Up @@ -11405,11 +11415,6 @@ parameters:
count: 1
path: library/Icinga/Util/DirectoryIterator.php

-
message: "#^Parameter \\#1 \\$array of class ArrayIterator constructor expects array\\<int, string\\>, array\\<int, string\\>\\|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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b370d9b

Please sign in to comment.