Conditions | 13 |
Paths | 10 |
Total Lines | 23 |
Code Lines | 18 |
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 |
||
48 | public function createForException(\Exception $exception, $id = null) |
||
49 | { |
||
50 | switch (true) { |
||
51 | case $exception instanceof ParseException: |
||
52 | return ErrorResponse::parseError($exception->getMessage() ?: 'Parse error'); |
||
53 | case $exception instanceof InvalidRequestException: |
||
54 | return ErrorResponse::invalidRequestError($exception->getMessage() ?: 'Invalid request'); |
||
55 | case $exception instanceof MethodNotFoundException: |
||
56 | return ErrorResponse::methodNotFoundError($id, $exception->getMessage() ?: 'Method not found'); |
||
57 | case $exception instanceof InvalidCallableArgumentsException: |
||
58 | case $exception instanceof InvalidMethodParametersException: |
||
59 | return ErrorResponse::invalidParamsError($id, $exception->getMessage() ?: 'Invalid params'); |
||
60 | case $exception instanceof ApplicationDefinedException: |
||
61 | return ErrorResponse::applicationDefinedError($id, $exception->getMessage(), $exception->getCode()); |
||
62 | case $exception instanceof \Exception: |
||
63 | default: |
||
64 | if ($this->exposeInternalExceptions) { |
||
65 | return new ErrorResponse($id, new Error($exception->getMessage(), $exception->getCode())); |
||
66 | } |
||
67 | |||
68 | return ErrorResponse::applicationError($id); |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 |