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 |
||
106 | public function setStatusCode(int $statusCode, string $version = '1.1', string $statusText = ''): bool |
||
107 | { |
||
108 | if (!headers_sent()) { |
||
109 | $statusCode = intval($statusCode); |
||
110 | |||
111 | if ('' == $statusText) { |
||
112 | $statusTexts = [ |
||
113 | 100 => 'Continue', |
||
114 | 101 => 'Switching Protocols', |
||
115 | 102 => 'Processing', // RFC2518 |
||
116 | 200 => 'OK', |
||
117 | 201 => 'Created', |
||
118 | 202 => 'Accepted', |
||
119 | 203 => 'Non-Authoritative Information', |
||
120 | 204 => 'No Content', |
||
121 | 205 => 'Reset Content', |
||
122 | 206 => 'Partial Content', |
||
123 | 207 => 'Multi-Status', // RFC4918 |
||
124 | 208 => 'Already Reported', // RFC5842 |
||
125 | 226 => 'IM Used', // RFC3229 |
||
126 | 300 => 'Multiple Choices', |
||
127 | 301 => 'Moved Permanently', |
||
128 | 302 => 'Found', |
||
129 | 303 => 'See Other', |
||
130 | 304 => 'Not Modified', |
||
131 | 305 => 'Use Proxy', |
||
132 | 307 => 'Temporary Redirect', |
||
133 | 308 => 'Permanent Redirect', // RFC7238 |
||
134 | 400 => 'Bad Request', |
||
135 | 401 => 'Unauthorized', |
||
136 | 402 => 'Payment Required', |
||
137 | 403 => 'Forbidden', |
||
138 | 404 => 'Not Found', |
||
139 | 405 => 'Method Not Allowed', |
||
140 | 406 => 'Not Acceptable', |
||
141 | 407 => 'Proxy Authentication Required', |
||
142 | 408 => 'Request Timeout', |
||
143 | 409 => 'Conflict', |
||
144 | 410 => 'Gone', |
||
145 | 411 => 'Length Required', |
||
146 | 412 => 'Precondition Failed', |
||
147 | 413 => 'Payload Too Large', |
||
148 | 414 => 'URI Too Long', |
||
149 | 415 => 'Unsupported Media Type', |
||
150 | 416 => 'Range Not Satisfiable', |
||
151 | 417 => 'Expectation Failed', |
||
152 | 418 => 'I\'m a teapot', // RFC2324 |
||
153 | 422 => 'Unprocessable Entity', // RFC4918 |
||
154 | 423 => 'Locked', // RFC4918 |
||
155 | 424 => 'Failed Dependency', // RFC4918 |
||
156 | 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 |
||
157 | 426 => 'Upgrade Required', // RFC2817 |
||
158 | 428 => 'Precondition Required', // RFC6585 |
||
159 | 429 => 'Too Many Requests', // RFC6585 |
||
160 | 431 => 'Request Header Fields Too Large', // RFC6585 |
||
161 | 500 => 'Internal Server Error', |
||
162 | 501 => 'Not Implemented', |
||
163 | 502 => 'Bad Gateway', |
||
164 | 503 => 'Service Unavailable', |
||
165 | 504 => 'Gateway Timeout', |
||
166 | 505 => 'HTTP Version Not Supported', |
||
167 | 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 |
||
168 | 507 => 'Insufficient Storage', // RFC4918 |
||
169 | 508 => 'Loop Detected', // RFC5842 |
||
170 | 510 => 'Not Extended', // RFC2774 |
||
171 | 511 => 'Network Authentication Required', // RFC6585 |
||
172 | ]; |
||
173 | $statusText = $statusTexts[$statusCode]; |
||
174 | } |
||
175 | |||
176 | header(sprintf('HTTP/%s %s %s', $version, $statusCode, $statusText), true, $statusCode); |
||
177 | return true; |
||
178 | } |
||
179 | |||
180 | return false; |
||
181 | } |
||
182 | |||
220 | } |