| Conditions | 10 |
| Paths | 18 |
| Total Lines | 35 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 28 | static function process ($request, $response, $request_started, $data) { |
||
| 29 | static::fill_superglobals( |
||
| 30 | static::prepare_superglobals($request, $data) |
||
| 31 | ); |
||
| 32 | try { |
||
| 33 | try { |
||
| 34 | static::execute_request($request_started); |
||
| 35 | } catch (ExitException $e) { |
||
| 36 | if ($e->getCode() >= 400) { |
||
| 37 | Page::instance()->error($e->getMessage() ?: null, $e->getJson()); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } catch (\Exception $e) { |
||
| 41 | // Handle generic exceptions to avoid server from stopping |
||
| 42 | } |
||
| 43 | $Response = System_response::instance(); |
||
| 44 | /** |
||
| 45 | * When error happens in \cs\Request initialization, there might be no headers yet since \cs\Response was not initialized |
||
| 46 | */ |
||
| 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 | /** |
||
| 141 |