Skip to content

Commit 1113796

Browse files
Cast status_code to int, replace if statement with match
1 parent 83b2731 commit 1113796

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

index.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,20 @@ function URL_check(string $url): string {
5656
return '<span class="glyph-offline" data-bs-toggle="tooltip" data-bs-title="php-error"><i class="fas fa-circle-xmark"></i></span>';
5757
}
5858

59-
$status_code = substr($headers[0], 9, 3 );
60-
61-
// If $headers contains "401", display lock icon
62-
if (strpos($headers[0], "401") !== false) {
63-
return "<span class=\"glyph-auth\" data-bs-toggle=\"tooltip\" data-bs-title=\"$status_code\"><i class=\"fas fa-lock\"></i></span>";
64-
// If $headers contains 4xx
65-
} elseif ($status_code >= 400 && $status_code <= 499) {
66-
return "<span class=\"glyph-error\" data-bs-toggle=\"tooltip\" data-bs-title=\"$status_code\"><i class=\"fas fa-circle-exclamation\"></i></span>";
67-
// If $headers contains 5xx
68-
} elseif ($status_code >= 500 && $status_code <= 599) {
69-
return "<span class=\"glyph-offline\" data-bs-toggle=\"tooltip\" data-bs-title=\"$status_code\"><i class=\"fas fa-circle-xmark\"></i></span>";
70-
// If $headers contains 2xx-3xx
71-
} elseif ($status_code >= 200 && $status_code <= 399) {
72-
return "<span class=\"glyph-online\" data-bs-toggle=\"tooltip\" data-bs-title=\"$status_code\"><i class=\"fas fa-circle-check\"></i></span>";
73-
// If $headers contains anything else
74-
} else {
75-
return '<span class="glyph-offline" data-bs-toggle="tooltip" data-bs-title="offline"><i class="fas fa-circle-xmark"></i></span>';
76-
}
59+
$status_code = (int) substr($headers[0], 9, 3);
60+
61+
return match (true) {
62+
// If $headers contains "401", display lock icon
63+
str_contains($headers[0], "401") => '<span class="glyph-auth" data-bs-toggle="tooltip" data-bs-title="' . $status_code . '"><i class="fas fa-lock"></i></span>',
64+
// If $headers contains 4xx
65+
$status_code >= 400 && $status_code <= 499 => '<span class="glyph-error" data-bs-toggle="tooltip" data-bs-title="' . $status_code . '"><i class="fas fa-circle-exclamation"></i></span>',
66+
// If $headers contains 5xx
67+
$status_code >= 500 && $status_code <= 599 => '<span class="glyph-offline" data-bs-toggle="tooltip" data-bs-title="' . $status_code . '"><i class="fas fa-circle-xmark"></i></span>',
68+
// If $headers contains 2xx-3xx
69+
$status_code >= 200 && $status_code <= 399 => '<span class="glyph-online" data-bs-toggle="tooltip" data-bs-title="' . $status_code . '"><i class="fas fa-circle-check"></i></span>',
70+
// If $headers contains anything else
71+
default => '<span class="glyph-offline" data-bs-toggle="tooltip" data-bs-title="offline"><i class="fas fa-circle-xmark"></i></span>',
72+
};
7773
}
7874

7975
// Check the status of each link if 'stat' is enabled

0 commit comments

Comments
 (0)