Conditions | 10 |
Paths | 18 |
Total Lines | 36 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 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 |
||
47 | $response->writeHead($Response->code, $Response->headers ?: []); |
||
48 | if ($Response->code >= 300 && $Response->code < 400) { |
||
49 | $response->end(); |
||
50 | } elseif (is_resource($Response->body_stream)) { |
||
51 | $position = ftell($Response->body_stream); |
||
52 | rewind($Response->body_stream); |
||
53 | while (!feof($Response->body_stream)) { |
||
54 | $response->write(fread($Response->body_stream, 1024)); |
||
55 | } |
||
56 | fseek($Response->body_stream, $position); |
||
57 | } else { |
||
58 | $response->end($Response->body); |
||
59 | } |
||
60 | $request->close(); |
||
61 | User::instance()->disable_memory_cache(); |
||
62 | } |
||
63 | /** |
||
64 | * @param \React\HTTP\Request $request |
||
65 | * @param string $data |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | protected static function prepare_superglobals ($request, $data) { |
||
70 | $SERVER = [ |
||
71 | 'SERVER_SOFTWARE' => 'ReactPHP' |
||
72 | ]; |
||
73 | $COOKIE = []; |
||
74 | $POST = []; |
||
75 | foreach ($request->getHeaders() as $key => $value) { |
||
76 | if ($key == 'Content-Type') { |
||
77 | $SERVER['CONTENT_TYPE'] = $value; |
||
78 | } elseif ($key == 'Cookie') { |
||
79 | $value = _trim(explode(';', $value)); |
||
80 | foreach ($value as $c) { |
||
81 | $c = explode('=', $c); |
||
82 | $COOKIE[$c[0]] = $c[1]; |
||
83 | } |
||
141 |