Refactor CodesEnum to use enum cases for HTTP status codes
All checks were successful
Publish Release Package / publish (push) Successful in 29s
All checks were successful
Publish Release Package / publish (push) Successful in 29s
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php /** @noinspection PhpUnused */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
@@ -14,73 +14,69 @@ namespace Siteworxpro\HttpStatus;
|
||||
*/
|
||||
enum CodesEnum: int
|
||||
{
|
||||
public const int CONTINUE = 100;
|
||||
public const int SWITCHING_PROTOCOLS = 101;
|
||||
public const int PROCESSING = 102;
|
||||
public const int EARLY_HINTS = 103;
|
||||
|
||||
public const int OK = 200;
|
||||
public const int CREATED = 201;
|
||||
public const int ACCEPTED = 202;
|
||||
public const int NON_AUTHORITATIVE_INFORMATION = 203;
|
||||
public const int NO_CONTENT = 204;
|
||||
public const int RESET_CONTENT = 205;
|
||||
public const int PARTIAL_CONTENT = 206;
|
||||
public const int MULTI_STATUS = 207;
|
||||
public const int ALREADY_REPORTED = 208;
|
||||
public const int IM_USED = 226;
|
||||
|
||||
public const int MULTIPLE_CHOICES = 300;
|
||||
public const int MOVED_PERMANENTLY = 301;
|
||||
public const int FOUND = 302;
|
||||
public const int SEE_OTHER = 303;
|
||||
public const int NOT_MODIFIED = 304;
|
||||
public const int USE_PROXY = 305;
|
||||
public const int TEMPORARY_REDIRECT = 307;
|
||||
public const int PERMANENT_REDIRECT = 308;
|
||||
|
||||
public const int BAD_REQUEST = 400;
|
||||
public const int UNAUTHORIZED = 401;
|
||||
public const int PAYMENT_REQUIRED = 402;
|
||||
public const int FORBIDDEN = 403;
|
||||
public const int NOT_FOUND = 404;
|
||||
public const int METHOD_NOT_ALLOWED = 405;
|
||||
public const int NOT_ACCEPTABLE = 406;
|
||||
public const int PROXY_AUTHENTICATION_REQUIRED = 407;
|
||||
public const int REQUEST_TIMEOUT = 408;
|
||||
public const int CONFLICT = 409;
|
||||
public const int GONE = 410;
|
||||
public const int LENGTH_REQUIRED = 411;
|
||||
public const int PRECONDITION_FAILED = 412;
|
||||
public const int PAYLOAD_TOO_LARGE = 413;
|
||||
public const int URI_TOO_LONG = 414;
|
||||
public const int UNSUPPORTED_MEDIA_TYPE = 415;
|
||||
public const int RANGE_NOT_SATISFIABLE = 416;
|
||||
public const int EXPECTATION_FAILED = 417;
|
||||
public const int IM_A_TEAPOT = 418;
|
||||
public const int MISDIRECTED_REQUEST = 421;
|
||||
public const int UNPROCESSABLE_ENTITY = 422;
|
||||
public const int LOCKED = 423;
|
||||
public const int FAILED_DEPENDENCY = 424;
|
||||
public const int TOO_EARLY = 425;
|
||||
public const int UPGRADE_REQUIRED = 426;
|
||||
public const int PRECONDITION_REQUIRED = 428;
|
||||
public const int TOO_MANY_REQUESTS = 429;
|
||||
public const int REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
|
||||
public const int UNAVAILABLE_FOR_LEGAL_REASONS = 451;
|
||||
|
||||
public const int INTERNAL_SERVER_ERROR = 500;
|
||||
public const int NOT_IMPLEMENTED = 501;
|
||||
public const int BAD_GATEWAY = 502;
|
||||
public const int SERVICE_UNAVAILABLE = 503;
|
||||
public const int GATEWAY_TIMEOUT = 504;
|
||||
public const int HTTP_VERSION_NOT_SUPPORTED = 505;
|
||||
public const int VARIANT_ALSO_NEGOTIATES = 506;
|
||||
public const int INSUFFICIENT_STORAGE = 507;
|
||||
public const int LOOP_DETECTED = 508;
|
||||
public const int NOT_EXTENDED = 510;
|
||||
public const int NETWORK_AUTHENTICATION_REQUIRED = 511;
|
||||
public const int NETWORK_CONNECT_TIMEOUT_ERROR = 599;
|
||||
case CONTINUE = 100;
|
||||
case SWITCHING_PROTOCOLS = 101;
|
||||
case PROCESSING = 102;
|
||||
case EARLY_HINTS = 103;
|
||||
case OK = 200;
|
||||
case CREATED = 201;
|
||||
case ACCEPTED = 202;
|
||||
case NON_AUTHORITATIVE_INFORMATION = 203;
|
||||
case NO_CONTENT = 204;
|
||||
case RESET_CONTENT = 205;
|
||||
case PARTIAL_CONTENT = 206;
|
||||
case MULTI_STATUS = 207;
|
||||
case ALREADY_REPORTED = 208;
|
||||
case IM_USED = 226;
|
||||
case MULTIPLE_CHOICES = 300;
|
||||
case MOVED_PERMANENTLY = 301;
|
||||
case FOUND = 302;
|
||||
case SEE_OTHER = 303;
|
||||
case NOT_MODIFIED = 304;
|
||||
case USE_PROXY = 305;
|
||||
case TEMPORARY_REDIRECT = 307;
|
||||
case PERMANENT_REDIRECT = 308;
|
||||
case BAD_REQUEST = 400;
|
||||
case UNAUTHORIZED = 401;
|
||||
case PAYMENT_REQUIRED = 402;
|
||||
case FORBIDDEN = 403;
|
||||
case NOT_FOUND = 404;
|
||||
case METHOD_NOT_ALLOWED = 405;
|
||||
case NOT_ACCEPTABLE = 406;
|
||||
case PROXY_AUTHENTICATION_REQUIRED = 407;
|
||||
case REQUEST_TIMEOUT = 408;
|
||||
case CONFLICT = 409;
|
||||
case GONE = 410;
|
||||
case LENGTH_REQUIRED = 411;
|
||||
case PRECONDITION_FAILED = 412;
|
||||
case PAYLOAD_TOO_LARGE = 413;
|
||||
case URI_TOO_LONG = 414;
|
||||
case UNSUPPORTED_MEDIA_TYPE = 415;
|
||||
case RANGE_NOT_SATISFIABLE = 416;
|
||||
case EXPECTATION_FAILED = 417;
|
||||
case IM_A_TEAPOT = 418;
|
||||
case MISDIRECTED_REQUEST = 421;
|
||||
case UNPROCESSABLE_ENTITY = 422;
|
||||
case LOCKED = 423;
|
||||
case FAILED_DEPENDENCY = 424;
|
||||
case TOO_EARLY = 425;
|
||||
case UPGRADE_REQUIRED = 426;
|
||||
case PRECONDITION_REQUIRED = 428;
|
||||
case TOO_MANY_REQUESTS = 429;
|
||||
case REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
|
||||
case UNAVAILABLE_FOR_LEGAL_REASONS = 451;
|
||||
case INTERNAL_SERVER_ERROR = 500;
|
||||
case NOT_IMPLEMENTED = 501;
|
||||
case BAD_GATEWAY = 502;
|
||||
case SERVICE_UNAVAILABLE = 503;
|
||||
case GATEWAY_TIMEOUT = 504;
|
||||
case HTTP_VERSION_NOT_SUPPORTED = 505;
|
||||
case VARIANT_ALSO_NEGOTIATES = 506;
|
||||
case INSUFFICIENT_STORAGE = 507;
|
||||
case LOOP_DETECTED = 508;
|
||||
case NOT_EXTENDED = 510;
|
||||
case NETWORK_AUTHENTICATION_REQUIRED = 511;
|
||||
case NETWORK_CONNECT_TIMEOUT_ERROR = 599;
|
||||
|
||||
/**
|
||||
* Returns the string representation of the HTTP status code.
|
||||
@@ -89,7 +85,7 @@ enum CodesEnum: int
|
||||
*/
|
||||
public function toString(): string
|
||||
{
|
||||
return match ($this->value) {
|
||||
return match ($this) {
|
||||
self::CONTINUE => 'Continue',
|
||||
self::SWITCHING_PROTOCOLS => 'Switching Protocols',
|
||||
self::PROCESSING => 'Processing',
|
||||
@@ -159,53 +155,69 @@ enum CodesEnum: int
|
||||
public static function fromCode(int $code): CodesEnum
|
||||
{
|
||||
return match ($code) {
|
||||
self::CONTINUE => self::CONTINUE,
|
||||
self::SWITCHING_PROTOCOLS => self::SWITCHING_PROTOCOLS,
|
||||
self::PROCESSING => self::PROCESSING,
|
||||
self::EARLY_HINTS => self::EARLY_HINTS,
|
||||
self::OK => self::OK,
|
||||
self::CREATED => self::CREATED,
|
||||
self::ACCEPTED => self::ACCEPTED,
|
||||
self::NON_AUTHORITATIVE_INFORMATION => self::NON_AUTHORITATIVE_INFORMATION,
|
||||
self::NO_CONTENT => self::NO_CONTENT,
|
||||
self::RESET_CONTENT => self::RESET_CONTENT,
|
||||
self::PARTIAL_CONTENT => self::PARTIAL_CONTENT,
|
||||
self::MULTI_STATUS => self::MULTI_STATUS,
|
||||
self::ALREADY_REPORTED => self::ALREADY_REPORTED,
|
||||
self::IM_USED => self::IM_USED,
|
||||
self::MULTIPLE_CHOICES => self::MULTIPLE_CHOICES,
|
||||
self::MOVED_PERMANENTLY => self::MOVED_PERMANENTLY,
|
||||
self::FOUND => self::FOUND,
|
||||
self::SEE_OTHER => self::SEE_OTHER,
|
||||
self::NOT_MODIFIED => self::NOT_MODIFIED,
|
||||
self::USE_PROXY => self::USE_PROXY,
|
||||
self::TEMPORARY_REDIRECT => self::TEMPORARY_REDIRECT,
|
||||
self::PERMANENT_REDIRECT => self::PERMANENT_REDIRECT,
|
||||
// Client errors
|
||||
self::BAD_REQUEST => self::BAD_REQUEST,
|
||||
self::UNAUTHORIZED => self::UNAUTHORIZED,
|
||||
self::PAYMENT_REQUIRED => self::PAYMENT_REQUIRED,
|
||||
self::FORBIDDEN => self::FORBIDDEN,
|
||||
self::NOT_FOUND => self::NOT_FOUND,
|
||||
self::METHOD_NOT_ALLOWED => self::METHOD_NOT_ALLOWED,
|
||||
self::NOT_ACCEPTABLE => self::NOT_ACCEPTABLE,
|
||||
self::PROXY_AUTHENTICATION_REQUIRED => self::PROXY_AUTHENTICATION_REQUIRED,
|
||||
self::REQUEST_TIMEOUT => self::REQUEST_TIMEOUT,
|
||||
self::CONFLICT => self::CONFLICT,
|
||||
self::GONE => self::_GONE_,
|
||||
// Server errors
|
||||
self::INTERNAL_SERVER_ERROR => self::INTERNAL_SERVER_ERROR,
|
||||
self::NOT_IMPLEMENTED => self::NOT_IMPLEMENTED,
|
||||
self::BAD_GATEWAY => self::BAD_GATEWAY,
|
||||
self::SERVICE_UNAVAILABLE => self::SERVICE_UNAVAILABLE,
|
||||
self::GATEWAY_TIMEOUT => self::GATEWAY_TIMEOUT,
|
||||
self::HTTP_VERSION_NOT_SUPPORTED => self::HTTP_VERSION_NOT_SUPPORTED,
|
||||
self::VARIANT_ALSO_NEGOTIATES => self::VARIANT_ALSO_NEGOTIATES,
|
||||
self::INSUFFICIENT_STORAGE => self::INSUFFICIENT_STORAGE,
|
||||
self::LOOP_DETECTED => self::LOOP_DETECTED,
|
||||
self::NOT_EXTENDED => self::NOT_EXTENDED,
|
||||
self::NETWORK_AUTHENTICATION_REQUIRED => self::NETWORK_AUTHENTICATION_REQUIRED,
|
||||
self::NETWORK_CONNECT_TIMEOUT_ERROR => self::NETWORK_CONNECT_TIMEOUT_ERROR,
|
||||
100 => self::CONTINUE,
|
||||
101 => self::SWITCHING_PROTOCOLS,
|
||||
102 => self::PROCESSING,
|
||||
103 => self::EARLY_HINTS,
|
||||
200 => self::OK,
|
||||
201 => self::CREATED,
|
||||
202 => self::ACCEPTED,
|
||||
203 => self::NON_AUTHORITATIVE_INFORMATION,
|
||||
204 => self::NO_CONTENT,
|
||||
205 => self::RESET_CONTENT,
|
||||
206 => self::PARTIAL_CONTENT,
|
||||
207 => self::MULTI_STATUS,
|
||||
208 => self::ALREADY_REPORTED,
|
||||
226 => self::IM_USED,
|
||||
300 => self::MULTIPLE_CHOICES,
|
||||
301 => self::MOVED_PERMANENTLY,
|
||||
302 => self::FOUND,
|
||||
303 => self::SEE_OTHER,
|
||||
304 => self::NOT_MODIFIED,
|
||||
305 => self::USE_PROXY,
|
||||
307 => self::TEMPORARY_REDIRECT,
|
||||
308 => self::PERMANENT_REDIRECT,
|
||||
400 => self::BAD_REQUEST,
|
||||
401 => self::UNAUTHORIZED,
|
||||
402 => self::PAYMENT_REQUIRED,
|
||||
403 => self::FORBIDDEN,
|
||||
404 => self::NOT_FOUND,
|
||||
405 => self::METHOD_NOT_ALLOWED,
|
||||
406 => self::NOT_ACCEPTABLE,
|
||||
407 => self::PROXY_AUTHENTICATION_REQUIRED,
|
||||
408 => self::REQUEST_TIMEOUT,
|
||||
409 => self::CONFLICT,
|
||||
410 => self::GONE,
|
||||
411 => self::LENGTH_REQUIRED,
|
||||
412 => self::PRECONDITION_FAILED,
|
||||
413 => self::PAYLOAD_TOO_LARGE,
|
||||
414 => self::URI_TOO_LONG,
|
||||
415 => self::UNSUPPORTED_MEDIA_TYPE,
|
||||
416 => self::RANGE_NOT_SATISFIABLE,
|
||||
417 => self::EXPECTATION_FAILED,
|
||||
418 => self::IM_A_TEAPOT,
|
||||
421 => self::MISDIRECTED_REQUEST,
|
||||
422 => self::UNPROCESSABLE_ENTITY,
|
||||
423 => self::LOCKED,
|
||||
424 => self::FAILED_DEPENDENCY,
|
||||
425 => self::TOO_EARLY,
|
||||
426 => self::UPGRADE_REQUIRED,
|
||||
428 => self::PRECONDITION_REQUIRED,
|
||||
429 => self::TOO_MANY_REQUESTS,
|
||||
431 => self::REQUEST_HEADER_FIELDS_TOO_LARGE,
|
||||
451 => self::UNAVAILABLE_FOR_LEGAL_REASONS,
|
||||
500 => self::INTERNAL_SERVER_ERROR,
|
||||
501 => self::NOT_IMPLEMENTED,
|
||||
502 => self::BAD_GATEWAY,
|
||||
503 => self::SERVICE_UNAVAILABLE,
|
||||
504 => self::GATEWAY_TIMEOUT,
|
||||
505 => self::HTTP_VERSION_NOT_SUPPORTED,
|
||||
506 => self::VARIANT_ALSO_NEGOTIATES,
|
||||
507 => self::INSUFFICIENT_STORAGE,
|
||||
508 => self::LOOP_DETECTED,
|
||||
510 => self::NOT_EXTENDED,
|
||||
511 => self::NETWORK_AUTHENTICATION_REQUIRED,
|
||||
599 => self::NETWORK_CONNECT_TIMEOUT_ERROR,
|
||||
default => throw new \InvalidArgumentException("Invalid HTTP status code: $code"),
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user