Conditions | 3 |
Paths | 3 |
Total Lines | 76 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
94 | public function setStatusCode($statusCode, $version = '1.1', $statusText = null) |
||
95 | { |
||
96 | if (!headers_sent()) { |
||
97 | $statusCode = intval($statusCode); |
||
98 | |||
99 | if (null === $statusText) { |
||
100 | $statusTexts = [ |
||
101 | 100 => 'Continue', |
||
102 | 101 => 'Switching Protocols', |
||
103 | 102 => 'Processing', // RFC2518 |
||
104 | 200 => 'OK', |
||
105 | 201 => 'Created', |
||
106 | 202 => 'Accepted', |
||
107 | 203 => 'Non-Authoritative Information', |
||
108 | 204 => 'No Content', |
||
109 | 205 => 'Reset Content', |
||
110 | 206 => 'Partial Content', |
||
111 | 207 => 'Multi-Status', // RFC4918 |
||
112 | 208 => 'Already Reported', // RFC5842 |
||
113 | 226 => 'IM Used', // RFC3229 |
||
114 | 300 => 'Multiple Choices', |
||
115 | 301 => 'Moved Permanently', |
||
116 | 302 => 'Found', |
||
117 | 303 => 'See Other', |
||
118 | 304 => 'Not Modified', |
||
119 | 305 => 'Use Proxy', |
||
120 | 307 => 'Temporary Redirect', |
||
121 | 308 => 'Permanent Redirect', // RFC7238 |
||
122 | 400 => 'Bad Request', |
||
123 | 401 => 'Unauthorized', |
||
124 | 402 => 'Payment Required', |
||
125 | 403 => 'Forbidden', |
||
126 | 404 => 'Not Found', |
||
127 | 405 => 'Method Not Allowed', |
||
128 | 406 => 'Not Acceptable', |
||
129 | 407 => 'Proxy Authentication Required', |
||
130 | 408 => 'Request Timeout', |
||
131 | 409 => 'Conflict', |
||
132 | 410 => 'Gone', |
||
133 | 411 => 'Length Required', |
||
134 | 412 => 'Precondition Failed', |
||
135 | 413 => 'Payload Too Large', |
||
136 | 414 => 'URI Too Long', |
||
137 | 415 => 'Unsupported Media Type', |
||
138 | 416 => 'Range Not Satisfiable', |
||
139 | 417 => 'Expectation Failed', |
||
140 | 418 => 'I\'m a teapot', // RFC2324 |
||
141 | 422 => 'Unprocessable Entity', // RFC4918 |
||
142 | 423 => 'Locked', // RFC4918 |
||
143 | 424 => 'Failed Dependency', // RFC4918 |
||
144 | 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 |
||
145 | 426 => 'Upgrade Required', // RFC2817 |
||
146 | 428 => 'Precondition Required', // RFC6585 |
||
147 | 429 => 'Too Many Requests', // RFC6585 |
||
148 | 431 => 'Request Header Fields Too Large', // RFC6585 |
||
149 | 500 => 'Internal Server Error', |
||
150 | 501 => 'Not Implemented', |
||
151 | 502 => 'Bad Gateway', |
||
152 | 503 => 'Service Unavailable', |
||
153 | 504 => 'Gateway Timeout', |
||
154 | 505 => 'HTTP Version Not Supported', |
||
155 | 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 |
||
156 | 507 => 'Insufficient Storage', // RFC4918 |
||
157 | 508 => 'Loop Detected', // RFC5842 |
||
158 | 510 => 'Not Extended', // RFC2774 |
||
159 | 511 => 'Network Authentication Required', // RFC6585 |
||
160 | ]; |
||
161 | $statusText = $statusTexts[$statusCode]; |
||
162 | } |
||
163 | |||
164 | header(sprintf('HTTP/%s %s %s', $version, $statusCode, $statusText), true, $statusCode); |
||
165 | return true; |
||
166 | } |
||
167 | |||
168 | return false; |
||
169 | } |
||
170 | |||
206 | } |