Conditions | 10 |
Paths | 15 |
Total Lines | 27 |
Code Lines | 18 |
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 |
||
41 | public function handle($request, Closure $next) |
||
42 | { |
||
43 | try { |
||
44 | $response = $next($request); |
||
45 | |||
46 | // Was an exception thrown? If so and available catch in our middleware |
||
47 | if (isset($response->exception) && $response->exception) { |
||
48 | throw $response->exception; |
||
49 | } |
||
50 | |||
51 | return $response; |
||
52 | } catch (OAuthServerException $e) { |
||
53 | $message = env('API_DEBUG') ? $e->getMessage() : null; |
||
54 | |||
55 | throw new HttpException($e->getHttpStatusCode(), $message, $e, $e->getHttpHeaders()); |
||
56 | } catch (HttpResponseException $e) { |
||
57 | $message = env('API_DEBUG') ? $e->getMessage() : null; |
||
58 | |||
59 | throw new HttpException($e->getResponse()->getStatusCode(), $message, $e); |
||
60 | } catch (AuthenticationException $e) { |
||
61 | throw new UnauthorizedHttpException(null, $e->getMessage(), $e); |
||
62 | } catch (ValidatorException $e) { |
||
63 | $messageBag = $e->getMessageBag(); |
||
64 | |||
65 | throw new ResourceException($messageBag->first(), $messageBag->all()); |
||
66 | } catch (ModelNotFoundException $e) { |
||
67 | throw new NotFoundHttpException('No results found.'); |
||
68 | } |
||
71 |