Lines 53.84% 7 / 13
Methods 66.66% 2 / 3
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 title 0.00% 0 / 6 0.00% 0 / 1 42
 message 100.00% 6 / 6 100.00% 1 / 1 6
 fromCode 100.00% 1 / 1 100.00% 1 / 1 1
7enum HttpStatus: int
8{
9    case NOT_FOUND     = 404;
10    case SERVER_ERROR  = 500;
11    case UNAUTHORIZED  = 401;
12    case FORBIDDEN     = 403;
13    case BAD_REQUEST   = 400;
14
15    public function title(): string
16    {
17        return match($this) {
18            self::NOT_FOUND    => "Not Found",
19            self::SERVER_ERROR => "Internal Server Error",
20            self::UNAUTHORIZED => "Unauthorized",
21            self::FORBIDDEN    => "Forbidden",
22            self::BAD_REQUEST  => "Bad Request",
23        };
24    }
25
26    public function message(): string
27    {
28        return match($this) {
29            self::NOT_FOUND    => "The page you're looking for cannot be found. It may have been moved, deleted, or never existed.",
30            self::SERVER_ERROR => "We're experiencing technical difficulties. Our team has been notified and is working to resolve the issue.",
31            self::UNAUTHORIZED => "Authentication required. Please log in to access this resource.",
32            self::FORBIDDEN    => "You don't have permission to access this resource.",
33            self::BAD_REQUEST  => "An error occurred while processing your request.",
34        };
35    }
36
37    public static function fromCode(int $code): self
38    {
39        return self::tryFrom($code) ?? self::SERVER_ERROR;
40    }
41}