Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
HttpStatus
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 isError
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isRedirect
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core\Http;
6
7use PeServer\Core\Collection\Arr;
8
9/**
10 * HTTPステータスコード。
11 */
12enum HttpStatus: int
13{
14    /** プログラム内部で使用するのみ, HTTPの舞台には登場しない。 */
15    case None = 0;
16
17    case Continue = 100;
18    case SwitchingProtocols = 101;
19    case Processing = 102;
20    case EarlyHints = 103;
21
22    case OK = 200;
23    case Created = 201;
24    case Accepted = 202;
25    case NonAuthoritativeInformation = 203;
26    case NoContent = 204;
27    case ResetContent = 205;
28    case PartialContent = 206;
29    case MultiStatus = 207;
30    case AlreadyReported = 208;
31    case IMUsed = 226;
32
33    case MultipleChoices = 300;
34    case MovedPermanently = 301;
35    case Found = 302;
36    case SeeOther = 303;
37    case NotModified = 304;
38    case UseProxy = 305;
39    case Unused306 = 306;
40    case TemporaryRedirect = 307;
41    case PermanentRedirect = 308;
42
43    case BadRequest = 400;
44    case Unauthorized = 401;
45    case PaymentRequired = 402;
46    case Forbidden = 403;
47    case NotFound = 404;
48    case MethodNotAllowed = 405;
49    case NotAcceptable = 406;
50    case ProxyAuthenticationRequired = 407;
51    case RequestTimeout = 408;
52    case Conflict = 409;
53    case Gone = 410;
54    case LengthRequired = 411;
55    case PreconditionFailed = 412;
56    case PayloadTooLarge = 413;
57    case UriTooLong = 414;
58    case UnsupportedMediaType = 415;
59    case RangeNotSatisfiable = 416;
60    case ExpectationFailed = 417;
61    /** I'm a teapot */
62    case IamTeapot = 418;
63    case MisdirectedRequest = 421;
64    case UnprocessableEntity = 422;
65    case Locked = 423;
66    case FailedDependency = 424;
67    case TooEarly = 425;
68    case UpgradeRequired = 426;
69    case PreconditionRequired = 428;
70    case TooManyRequests = 429;
71    case RequestHeaderFieldsTooLarge = 431;
72
73    case InternalServerError = 500;
74    case NotImplemented = 501;
75    case BadGateway = 502;
76    case ServiceUnavailable = 503;
77    case GatewayTimeout = 504;
78    case HttpVersionNotSupported = 505;
79    case VariantAlsoNegotiates = 506;
80    case InsufficientStorage = 507;
81    case LoopDetected = 508;
82    case NotExtended = 510;
83    case NetworkAuthenticationRequired = 511;
84
85    #region function
86
87    public function isError(): bool
88    {
89        return 400 <= $this->value;
90    }
91
92    public function isRedirect(): bool
93    {
94        $codes = [
95            300,
96            301,
97            302,
98            303,
99            304,
100            307,
101            308,
102        ];
103
104        return Arr::in($codes, $this->value);
105    }
106
107    #endregion
108}