Completed
Push — master ( 5f700f...192f3f )
by Riikka
03:40
created

HttpMethod::getAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 1
rs 9.7998
c 0
b 0
f 0
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 Riikka Kalliomäki
9
 * @license http://opensource.org/licenses/mit-license.php MIT License
10
 */
11
class HttpMethod
12
{
13
    /** @var string The HTTP GET request method */
14
    public const GET = 'GET';
15
16
    /** @var string The HTTP HEAD request method */
17
    public const HEAD = 'HEAD';
18
19
    /** @var string The HTTP POST request method */
20
    public const POST = 'POST';
21
22
    /** @var string The HTTP PUT request method */
23
    public const PUT = 'PUT';
24
25
    /** @var string The HTTP DELETE request method */
26
    public const DELETE = 'DELETE';
27
28
    /** @var string The HTTP CONNECT request method */
29
    public const CONNECT = 'CONNECT';
30
31
    /** @var string The HTTP OPTIONS request method */
32
    public const OPTIONS = 'OPTIONS';
33
34
    /** @var string The HTTP TRACE request method */
35
    public const TRACE = 'TRACE';
36
37
    /** @var string 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 26
    public static function isValid(string $method): bool
46
    {
47 26
        return \in_array($method, self::getAll(), true);
48
    }
49
50
    /**
51
     * Returns list of all valid HTTP request methods.
52
     * @return array List of all valid HTTP request methods
53
     */
54 26
    public static function getAll(): array
55
    {
56
        return [
57 26
            self::GET,
58 26
            self::HEAD,
59 26
            self::POST,
60 26
            self::PUT,
61 26
            self::DELETE,
62 26
            self::CONNECT,
63 26
            self::OPTIONS,
64 26
            self::TRACE,
65 26
            self::PATCH,
66
        ];
67
    }
68
}
69