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