diff --git a/src/Components/Health/HealthCollection.php b/src/Components/Health/HealthCollection.php index 854d4fcf..ca67e5cd 100644 --- a/src/Components/Health/HealthCollection.php +++ b/src/Components/Health/HealthCollection.php @@ -11,6 +11,20 @@ */ class HealthCollection extends Collection { + private const STATE_PRIORITY = [ + SettingsResult::ERROR => 0, + SettingsResult::WARNING => 1, + SettingsResult::INFO => 2, + SettingsResult::GREEN => 3, + ]; + + public function sortByState(): void + { + $this->sort(static function (SettingsResult $a, SettingsResult $b) { + return (self::STATE_PRIORITY[$a->state] ?? -1) <=> (self::STATE_PRIORITY[$b->state] ?? -1); + }); + } + protected function getExpectedClass(): ?string { return SettingsResult::class; diff --git a/src/Controller/HealthController.php b/src/Controller/HealthController.php index b3f641fb..0c0544d5 100644 --- a/src/Controller/HealthController.php +++ b/src/Controller/HealthController.php @@ -38,6 +38,8 @@ public function status(): JsonResponse $checker->collect($collection); } + $collection->sortByState(); + return new JsonResponse($collection); } @@ -49,6 +51,8 @@ public function performanceStatus(): JsonResponse $checker->collect($collection); } + $collection->sortByState(); + return new JsonResponse($collection); }