Conditions | 9 |
Paths | 50 |
Total Lines | 51 |
Code Lines | 25 |
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 |
||
58 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
59 | { |
||
60 | try { |
||
61 | return $handler->handle($request); |
||
62 | } catch (HttpException $exception) { |
||
63 | // The router added the tree attribute to the request, and we need it for the error response. |
||
64 | $request = app(ServerRequestInterface::class) ?? $request; |
||
65 | |||
66 | return $this->httpExceptionResponse($request, $exception); |
||
67 | } catch (Throwable $exception) { |
||
68 | // Exception thrown while buffering output? |
||
69 | while (ob_get_level() > 0) { |
||
70 | ob_end_clean(); |
||
71 | } |
||
72 | |||
73 | // The Router middleware may have added a tree attribute to the request. |
||
74 | // This might be usable in the error page. |
||
75 | if (app()->has(ServerRequestInterface::class)) { |
||
76 | $request = app(ServerRequestInterface::class) ?? $request; |
||
77 | } |
||
78 | |||
79 | // No locale set in the request? |
||
80 | if ($request->getAttribute('locale') === null) { |
||
81 | $request = $request->withAttribute('locale', new LocaleEnUs()); |
||
82 | app()->instance(ServerRequestInterface::class, $request); |
||
83 | } |
||
84 | |||
85 | // Show the exception in a standard webtrees page (if we can). |
||
86 | try { |
||
87 | return $this->unhandledExceptionResponse($request, $exception); |
||
88 | } catch (Throwable $e) { |
||
|
|||
89 | } |
||
90 | |||
91 | // Show the exception in a tree-less webtrees page (if we can). |
||
92 | try { |
||
93 | $request = $request->withAttribute('tree', null); |
||
94 | |||
95 | return $this->unhandledExceptionResponse($request, $exception); |
||
96 | } catch (Throwable $e) { |
||
97 | } |
||
98 | |||
99 | // Show the exception in an error page (if we can). |
||
100 | try { |
||
101 | $this->layout = 'layouts/error'; |
||
102 | |||
103 | return $this->unhandledExceptionResponse($request, $exception); |
||
104 | } catch (Throwable $e) { |
||
105 | } |
||
106 | |||
107 | // Show a stack dump. |
||
108 | return response((string) $exception, StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); |
||
109 | } |
||
174 |