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    /** The HEAD method requests the headers for a given resource without the response body. */
34    case Head = 'HEAD';
35
36    /** The GET method requests a representation of the specified resource. It MUST NOT have side-effects. */
37    case Get = 'GET';
38
39    /** The POST method submits data to be processed, often causing a change in state or side-effects. */
40    case Post = 'POST';
41
42    /** The PUT method replaces the target resource with the request payload. */
43    case Put = 'PUT';
44
45    /** The PATCH method applies partial modifications to the target resource. */
46    case Patch = 'PATCH';
47
48    /** The DELETE method removes the specified resource. */
49    case Delete = 'DELETE';
50
51    /** The PURGE method requests that a cached resource be removed, often used with proxy servers. */
52    case Purge = 'PURGE';
53
54    /** The OPTIONS method describes the communication options for the target resource. */
55    case Options = 'OPTIONS';
56
57    /** The TRACE method performs a message loop-back test along the path to the target resource. */
58    case Trace = 'TRACE';
59
60    /** The CONNECT method establishes a tunnel to the target resource, often used with HTTPS proxies. */
61    case Connect = 'CONNECT';
62
63    /**
64     * Returns true if the method is considered safe (does not modify server state).
65     *
66     * @return bool
67     */
68    public function isSafe(): bool
69    {
70        return \in_array($this, [self::Get, self::Head, self::Options, self::Trace], true);
71    }
72
73    /**
74     * Returns true if the method is idempotent (multiple identical requests have the same effect as a single one).
75     *
76     * @return bool
77     */
78    public function isIdempotent(): bool
79    {
80        return \in_array($this, [self::Get, self::Head, self::Put, self::Delete, self::Options, self::Trace], true);
81    }
82
83    /**
84     * Returns true if the method is considered cacheable by default.
85     *
86     * @return bool
87     */
88    public function isCacheable(): bool
89    {
90        return \in_array($this, [self::Get, self::Head], true);
91    }
92}