| Conditions | 11 |
| Paths | 73 |
| Total Lines | 32 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 36 | public function handleSAPIRequest() { |
||
| 37 | try { |
||
| 38 | $request = $this->requestFactory->create($_SERVER['REQUEST_METHOD'], getallheaders(), |
||
| 39 | file_get_contents("php://input"), $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI']); |
||
| 40 | |||
| 41 | try { |
||
| 42 | $response = $this->server->handleRequest($request); |
||
| 43 | header("Content-Type: " . $response->getMIMEType()); |
||
| 44 | echo $response->getAsString(); |
||
| 45 | } catch(InvalidAPIKeyException $e){ |
||
| 46 | header('400 Bad Request', true, 400); |
||
| 47 | } catch(UnknownEndpointException $e){ |
||
| 48 | header('404 Not Found', true, 404); |
||
| 49 | } catch(NotAcceptableResponseTypeException $e){ |
||
| 50 | header('406 Not Acceptable', true, 406); |
||
| 51 | } catch(AccessDeniedException $e){ |
||
| 52 | header('403 Access Denied', true, 403); |
||
| 53 | } catch(ThrottleLimitExceededException $e){ |
||
| 54 | header('429 Too Many Requests', true, 429); |
||
| 55 | } catch (\Exception $e) { |
||
| 56 | header('500 Internal Server Error', true, 500); |
||
| 57 | } |
||
| 58 | } catch(InvalidRequestURLException $e){ |
||
| 59 | header('400 Bad Request', true, 400); |
||
| 60 | } catch(UnknownContentTypeException $e){ |
||
| 61 | header('400 Bad Request', true, 400); |
||
| 62 | } catch(InvalidRequestDataException $e){ |
||
| 63 | header('400 Bad Request', true, 400); |
||
| 64 | } catch(\Exception $e){ |
||
| 65 | header('500 Internal Server Error', true, 500); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 |