Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| RequestMethod | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| isSafe | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isIdempotent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isCacheable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of php-fast-forward/http-message. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @link https://github.com/php-fast-forward/http-message |
| 12 | * @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 13 | * @license https://opensource.org/licenses/MIT MIT License |
| 14 | */ |
| 15 | |
| 16 | namespace FastForward\Http\Message; |
| 17 | |
| 18 | /** |
| 19 | * Enum RequestMethod. |
| 20 | * |
| 21 | * Represents the set of valid HTTP request methods as defined by the IETF RFC 7231 and related specifications. |
| 22 | * This enum SHALL be used to strictly define supported request methods within HTTP client and server implementations. |
| 23 | * Each case corresponds to a standardized HTTP method, expressed as an uppercase string literal. |
| 24 | * |
| 25 | * Implementations utilizing this enum MUST validate incoming or outgoing request methods against this set to ensure |
| 26 | * protocol compliance and interoperability. |
| 27 | * |
| 28 | * @package FastForward\Http\Message |
| 29 | */ |
| 30 | enum RequestMethod: string |
| 31 | { |
| 32 | /** The HEAD method requests the headers for a given resource without the response body. */ |
| 33 | case Head = 'HEAD'; |
| 34 | |
| 35 | /** The GET method requests a representation of the specified resource. It MUST NOT have side-effects. */ |
| 36 | case Get = 'GET'; |
| 37 | |
| 38 | /** The POST method submits data to be processed, often causing a change in state or side-effects. */ |
| 39 | case Post = 'POST'; |
| 40 | |
| 41 | /** The PUT method replaces the target resource with the request payload. */ |
| 42 | case Put = 'PUT'; |
| 43 | |
| 44 | /** The PATCH method applies partial modifications to the target resource. */ |
| 45 | case Patch = 'PATCH'; |
| 46 | |
| 47 | /** The DELETE method removes the specified resource. */ |
| 48 | case Delete = 'DELETE'; |
| 49 | |
| 50 | /** The PURGE method requests that a cached resource be removed, often used with proxy servers. */ |
| 51 | case Purge = 'PURGE'; |
| 52 | |
| 53 | /** The OPTIONS method describes the communication options for the target resource. */ |
| 54 | case Options = 'OPTIONS'; |
| 55 | |
| 56 | /** The TRACE method performs a message loop-back test along the path to the target resource. */ |
| 57 | case Trace = 'TRACE'; |
| 58 | |
| 59 | /** The CONNECT method establishes a tunnel to the target resource, often used with HTTPS proxies. */ |
| 60 | case Connect = 'CONNECT'; |
| 61 | |
| 62 | /** |
| 63 | * Returns true if the method is considered safe (does not modify server state). |
| 64 | */ |
| 65 | public function isSafe(): bool |
| 66 | { |
| 67 | return \in_array($this, [self::Get, self::Head, self::Options, self::Trace], true); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns true if the method is idempotent (multiple identical requests have the same effect as a single one). |
| 72 | */ |
| 73 | public function isIdempotent(): bool |
| 74 | { |
| 75 | return \in_array($this, [self::Get, self::Head, self::Put, self::Delete, self::Options, self::Trace], true); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns true if the method is considered cacheable by default. |
| 80 | */ |
| 81 | public function isCacheable(): bool |
| 82 | { |
| 83 | return \in_array($this, [self::Get, self::Head], true); |
| 84 | } |
| 85 | } |