Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Components/Health/HealthCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/HealthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function status(): JsonResponse
$checker->collect($collection);
}

$collection->sortByState();

return new JsonResponse($collection);
}

Expand All @@ -49,6 +51,8 @@ public function performanceStatus(): JsonResponse
$checker->collect($collection);
}

$collection->sortByState();

return new JsonResponse($collection);
}

Expand Down
Loading