Conditions | 9 |
Paths | 50 |
Total Lines | 54 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
73 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
74 | { |
||
75 | try { |
||
76 | return $handler->handle($request); |
||
77 | } catch (HttpException $exception) { |
||
78 | // The router added the tree attribute to the request, and we need it for the error response. |
||
79 | $request = app(ServerRequestInterface::class) ?? $request; |
||
80 | |||
81 | return $this->httpExceptionResponse($request, $exception); |
||
82 | } catch (Throwable $exception) { |
||
83 | // Exception thrown while buffering output? |
||
84 | while (ob_get_level() > 0) { |
||
85 | ob_end_clean(); |
||
86 | } |
||
87 | |||
88 | // The Router middleware may have added a tree attribute to the request. |
||
89 | // This might be usable in the error page. |
||
90 | if (app()->has(ServerRequestInterface::class)) { |
||
91 | $request = app(ServerRequestInterface::class) ?? $request; |
||
92 | } |
||
93 | |||
94 | // No locale set in the request? |
||
95 | if ($request->getAttribute('locale') === null) { |
||
96 | $request = $request->withAttribute('locale', new LocaleEnUs()); |
||
97 | app()->instance(ServerRequestInterface::class, $request); |
||
98 | } |
||
99 | |||
100 | // Show the exception in a standard webtrees page (if we can). |
||
101 | try { |
||
102 | return $this->unhandledExceptionResponse($request, $exception); |
||
103 | } catch (Throwable $e) { |
||
104 | // That didn't work. Try something else. |
||
105 | } |
||
106 | |||
107 | // Show the exception in a tree-less webtrees page (if we can). |
||
108 | try { |
||
109 | $request = $request->withAttribute('tree', null); |
||
110 | |||
111 | return $this->unhandledExceptionResponse($request, $exception); |
||
112 | } catch (Throwable $e) { |
||
113 | // That didn't work. Try something else. |
||
114 | } |
||
115 | |||
116 | // Show the exception in an error page (if we can). |
||
117 | try { |
||
118 | $this->layout = 'layouts/error'; |
||
119 | |||
120 | return $this->unhandledExceptionResponse($request, $exception); |
||
121 | } catch (Throwable $e) { |
||
122 | // That didn't work. Try something else. |
||
123 | } |
||
124 | |||
125 | // Show a stack dump. |
||
126 | return response((string) $exception, StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); |
||
127 | } |
||
197 |