Completed
Push — master ( 6bc3b4...34ca55 )
by Ralf
15s queued 11s
created

Http   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 7
1
<?php
2
3
namespace Httpful;
4
5
/**
6
 * @author Nate Good <[email protected]>
7
 */
8
class Http
9
{
10
    const HEAD      = 'HEAD';
11
    const GET       = 'GET';
12
    const POST      = 'POST';
13
    const PUT       = 'PUT';
14
    const DELETE    = 'DELETE';
15
    const PATCH     = 'PATCH';
16
    const OPTIONS   = 'OPTIONS';
17
    const TRACE     = 'TRACE';
18
19
    /**
20
     * @return array of HTTP method strings
21
     */
22
    public static function safeMethods()
23
    {
24
        return array(self::HEAD, self::GET, self::OPTIONS, self::TRACE);
25
    }
26
27
    /**
28
     * @return bool
29
     * @param string HTTP method
30
     */
31
    public static function isSafeMethod($method)
32
    {
33
        return in_array($method, self::safeMethods());
34
    }
35
36
    /**
37
     * @return bool
38
     * @param string HTTP method
39
     */
40
    public static function isUnsafeMethod($method)
41
    {
42
        return !in_array($method, self::safeMethods());
43
    }
44
45
    /**
46
     * @return array list of (always) idempotent HTTP methods
47
     */
48
    public static function idempotentMethods()
49
    {
50
        // Though it is possible to be idempotent, POST
51
        // is not guarunteed to be, and more often than
52
        // not, it is not.
53
        return array(self::HEAD, self::GET, self::PUT, self::DELETE, self::OPTIONS, self::TRACE, self::PATCH);
54
    }
55
56
    /**
57
     * @return bool
58
     * @param string HTTP method
59
     */
60
    public static function isIdempotent($method)
61
    {
62
        return in_array($method, self::safeidempotentMethodsMethods());
63
    }
64
65
    /**
66
     * @return bool
67
     * @param string HTTP method
68
     */
69
    public static function isNotIdempotent($method)
70
    {
71
        return !in_array($method, self::idempotentMethods());
72
    }
73
74
    /**
75
     * @deprecated Technically anything *can* have a body,
76
     * they just don't have semantic meaning.  So say's Roy
77
     * http://tech.groups.yahoo.com/group/rest-discuss/message/9962
78
     *
79
     * @return array of HTTP method strings
80
     */
81
    public static function canHaveBody()
82
    {
83
        return array(self::POST, self::PUT, self::PATCH, self::OPTIONS);
84
    }
85
86
}