HttpStatus   A
last analyzed

Complexity

Total Complexity 42

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 42
eloc 126
c 1
b 0
f 0
dl 0
loc 139
ccs 0
cts 84
cp 0
rs 9.0399

1 Method

Rating   Name   Duplication   Size   Complexity  
D getStatusDescription() 0 88 42

How to fix   Complexity   

Complex Class

Complex classes like HttpStatus often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use HttpStatus, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace POData\Common;
4
5
/**
6
 * Class HttpStatus
7
 * @package POData\Common
8
 */
9
class HttpStatus
10
{
11
    const CODE_CONTINUE                        = 100;
12
    const CODE_SWITCHING_PROTOCOLS             = 101;
13
    const CODE_OK                              = 200;
14
    const CODE_CREATED                         = 201;
15
    const CODE_ACCEPTED                        = 202;
16
    const CODE_NON_AUTHRATIVE_INFORMATION      = 203;
17
    const CODE_NOCONTENT                       = 204;
18
    const CODE_RESET_CONTENT                   = 205;
19
    const CODE_PARTIAL_CONTENT                 = 206;
20
    const CODE_MULTIPLE_CHOICE                 = 300;
21
    const CODE_MOVED_PERMANENTLY               = 301;
22
    const CODE_FOUND                           = 302;
23
    const CODE_SEE_OTHER                       = 303;
24
    const CODE_NOT_MODIFIED                    = 304;
25
    const CODE_USE_PROXY                       = 305;
26
    const CODE_UNUSED                          = 306;
27
    const CODE_TEMP_REDIRECT                   = 307;
28
    const CODE_BAD_REQUEST                     = 400;
29
    const CODE_UNAUTHORIZED                    = 401;
30
    const CODE_PAYMENT_REQ                     = 402;
31
    const CODE_FORBIDDEN                       = 403;
32
    const CODE_NOT_FOUND                       = 404;
33
    const CODE_METHOD_NOT_ALLOWED              = 405;
34
    const CODE_NOT_ACCEPTABLE                  = 406;
35
    const CODE_PROXY_AUTHENTICATION_REQUIRED   = 407;
36
    const CODE_REQUEST_TIMEOUT                 = 408;
37
    const CODE_CONFLICT                        = 409;
38
    const CODE_GONE                            = 410;
39
    const CODE_LENGTH_REQUIRED                 = 411;
40
    const CODE_PRECONDITION_FAILED             = 412;
41
    const CODE_REQUEST_ENTITY_TOOLONG          = 413;
42
    const CODE_REQUEST_URI_TOOLONG             = 414;
43
    const CODE_UNSUPPORTED_MEDIATYPE           = 415;
44
    const CODE_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
45
    const CODE_EXPECTATION_FAILED              = 417;
46
    const CODE_INTERNAL_SERVER_ERROR           = 500;
47
    const CODE_NOT_IMPLEMENTED                 = 501;
48
    const CODE_BAD_GATEWAY                     = 502;
49
    const CODE_SERVICE_UNAVAILABLE             = 503;
50
    const CODE_GATEWAY_TIMEOUT                 = 504;
51
    const CODE_HTTP_VERSION_NOT_SUPPORTED      = 505;
52
53
    /**
54
     * Get status description from status code.
55
     *
56
     * @param int $statusCode status code
57
     *
58
     * @return string|null
59
     */
60
    public static function getStatusDescription($statusCode)
61
    {
62
        switch ($statusCode) {
63
            case self::CODE_CONTINUE:
64
                    return 'Continue';
65
            case self::CODE_SWITCHING_PROTOCOLS:
66
                    return  'SwitchingProtocols';
67
            case self::CODE_OK:
68
                    return  'OK';
69
            case self::CODE_CREATED;
70
                    return  'Created';
71
            case self::CODE_ACCEPTED;
72
                    return  'Accepted';
73
            case self::CODE_NON_AUTHRATIVE_INFORMATION;
74
                    return  'Non-Authrative Information';
75
            case self::CODE_NOCONTENT;
76
                    return  'No Content';
77
            case self::CODE_RESET_CONTENT;
78
                    return 'ResetContent';
79
            case self::CODE_PARTIAL_CONTENT;
80
                    return 'Partial Content';
81
            case self::CODE_MULTIPLE_CHOICE;
82
                    return 'Multiple Choices';
83
            case self::CODE_MOVED_PERMANENTLY;
84
                    return 'Moved Permanently';
85
            case self::CODE_FOUND;
86
                    return 'Found';
87
            case self::CODE_SEE_OTHER;
88
                    return 'See Other';
89
            case self::CODE_NOT_MODIFIED;
90
                    return 'Not Modified';
91
            case self::CODE_USE_PROXY;
92
                    return 'Use Proxy';
93
            case self::CODE_UNUSED;
94
                    return 'Unused';
95
            case self::CODE_TEMP_REDIRECT;
96
                    return 'Temporary Redirect';
97
            case self::CODE_BAD_REQUEST;
98
                    return 'Bad Request';
99
            case self::CODE_UNAUTHORIZED;
100
                    return 'Unauthorized';
101
            case self::CODE_PAYMENT_REQ;
102
                    return 'Payment Required';
103
            case self::CODE_FORBIDDEN;
104
                    return 'Forbidden';
105
            case self::CODE_NOT_FOUND;
106
                    return 'Not Found';
107
            case self::CODE_METHOD_NOT_ALLOWED;
108
                    return 'Method Not Allowed';
109
            case self::CODE_NOT_ACCEPTABLE;
110
                    return 'Not Acceptable';
111
            case self::CODE_PROXY_AUTHENTICATION_REQUIRED;
112
                    return 'Proxy Authentication Required';
113
            case self::CODE_REQUEST_TIMEOUT;
114
                    return 'Request Timeout';
115
            case self::CODE_CONFLICT;
116
                    return 'Conflict';
117
            case self::CODE_GONE;
118
                    return 'Gone';
119
            case self::CODE_LENGTH_REQUIRED;
120
                    return 'Length Required';
121
            case self::CODE_PRECONDITION_FAILED;
122
                    return 'Precondition Failed';
123
            case self::CODE_REQUEST_ENTITY_TOOLONG;
124
                    return 'Request Entity Too Large';
125
            case self::CODE_REQUEST_URI_TOOLONG;
126
                    return 'Request-URI Too Large';
127
            case self::CODE_UNSUPPORTED_MEDIATYPE;
128
                    return 'Unsupported Media Type';
129
            case self::CODE_REQUESTED_RANGE_NOT_SATISFIABLE;
130
                    return 'Requested Range NotSatisfiable';
131
            case self::CODE_EXPECTATION_FAILED;
132
                    return 'Expectation Failed';
133
            case self::CODE_INTERNAL_SERVER_ERROR;
134
                    return 'Internal Server Error';
135
            case self::CODE_NOT_IMPLEMENTED;
136
                    return 'Not Implemented';
137
            case self::CODE_BAD_GATEWAY;
138
                    return 'Bad Gateway';
139
            case self::CODE_SERVICE_UNAVAILABLE;
140
                    return 'Service Unavailable';
141
            case self::CODE_GATEWAY_TIMEOUT;
142
                    return 'Gateway Timeout';
143
            case self::CODE_HTTP_VERSION_NOT_SUPPORTED;
144
                    return 'HTTP Version Not Suppoted';
145
        }
146
147
        return null;
148
    }
149
}
150