HttpMethod   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 55
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 3 1
A getAll() 0 12 1
1
<?php
2
3
namespace Simply\Router;
4
5
/**
6
 * Provides valid values for the HTTP request method.
7
 * @author Riikka Kalliomäki <[email protected]>
8
 * @copyright Copyright (c) 2018-2019 Riikka Kalliomäki
9
 * @license http://opensource.org/licenses/mit-license.php MIT License
10
 */
11
class HttpMethod
12
{
13
    /** The HTTP GET request method */
14
    public const GET = 'GET';
15
16
    /** The HTTP HEAD request method */
17
    public const HEAD = 'HEAD';
18
19
    /** The HTTP POST request method */
20
    public const POST = 'POST';
21
22
    /** The HTTP PUT request method */
23
    public const PUT = 'PUT';
24
25
    /** The HTTP DELETE request method */
26
    public const DELETE = 'DELETE';
27
28
    /** The HTTP CONNECT request method */
29
    public const CONNECT = 'CONNECT';
30
31
    /** The HTTP OPTIONS request method */
32
    public const OPTIONS = 'OPTIONS';
33
34
    /** The HTTP TRACE request method */
35
    public const TRACE = 'TRACE';
36
37
    /** The HTTP PATCH request method */
38
    public const PATCH = 'PATCH';
39
40
    /**
41
     * Tells if the given string is a valid HTTP request method.
42
     * @param string $method The string to test
43
     * @return bool True if it is a valid HTTP request method, false if not
44
     */
45 32
    public static function isValid(string $method): bool
46
    {
47 32
        return \in_array($method, self::getAll(), true);
48
    }
49
50
    /**
51
     * Returns list of all valid HTTP request methods.
52
     * @return string[] List of all valid HTTP request methods
53
     */
54 32
    public static function getAll(): array
55
    {
56
        return [
57 32
            self::GET,
58 32
            self::HEAD,
59 32
            self::POST,
60 32
            self::PUT,
61 32
            self::DELETE,
62 32
            self::CONNECT,
63 32
            self::OPTIONS,
64 32
            self::TRACE,
65 32
            self::PATCH,
66
        ];
67
    }
68
}
69