Conditions | 9 |
Paths | 192 |
Total Lines | 66 |
Code Lines | 34 |
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 |
||
13 | public function __invoke( |
||
14 | \Psr\Http\Message\ServerRequestInterface $request, |
||
15 | \Psr\Http\Message\ResponseInterface $response, |
||
16 | $next |
||
17 | ) { |
||
18 | $container = $this->container; |
||
19 | $container['requestobj'] = $request; |
||
20 | $container['responseobj'] = $response; |
||
21 | |||
22 | $container['server'] = $request->getParam('server'); |
||
|
|||
23 | $container['database'] = $request->getParam('database'); |
||
24 | $container['schema'] = $request->getParam('schema'); |
||
25 | $misc = $container->get('misc'); |
||
26 | |||
27 | $misc->setHREF(); |
||
28 | $misc->setForm(); |
||
29 | |||
30 | $container->view->offsetSet('METHOD', $request->getMethod()); |
||
31 | if ($request->getAttribute('route')) { |
||
32 | $container->view->offsetSet('subject', $request->getAttribute('route')->getArgument('subject')); |
||
33 | } |
||
34 | |||
35 | $query_string = $request->getUri()->getQuery(); |
||
36 | $container->view->offsetSet('query_string', $query_string); |
||
37 | $path = (SUBFOLDER ? (SUBFOLDER . '/') : '') . $request->getUri()->getPath() . ($query_string ? '?' . $query_string : ''); |
||
38 | $container->view->offsetSet('path', $path); |
||
39 | |||
40 | $params = $request->getParams(); |
||
41 | |||
42 | $viewparams = []; |
||
43 | |||
44 | foreach ($params as $key => $value) { |
||
45 | if (is_scalar($value)) { |
||
46 | $viewparams[$key] = $value; |
||
47 | } |
||
48 | } |
||
49 | |||
50 | if (isset($_COOKIE['IN_TEST'])) { |
||
51 | $in_test = (string) $_COOKIE['IN_TEST']; |
||
52 | } else { |
||
53 | $in_test = '0'; |
||
54 | } |
||
55 | |||
56 | // remove tabs and linebreaks from query |
||
57 | if (isset($params['query'])) { |
||
58 | $viewparams['query'] = str_replace(["\r", "\n", "\t"], ' ', $params['query']); |
||
59 | } |
||
60 | $container->view->offsetSet('params', $viewparams); |
||
61 | $container->view->offsetSet('in_test', $in_test); |
||
62 | |||
63 | if (count($container['errors']) > 0) { |
||
64 | return ($container->haltHandler)($container->requestobj, $container->responseobj, $container['errors'], 412); |
||
65 | } |
||
66 | |||
67 | $messages = $container->flash->getMessages(); |
||
68 | /*if (!empty($messages)) { |
||
69 | foreach ($messages as $key => $message) { |
||
70 | $this->prtrace('Flash: ' . $key . ' = ' . json_encode($message)); |
||
71 | } |
||
72 | }*/ |
||
73 | |||
74 | // First execute anything else |
||
75 | $response = $next($request, $response); |
||
76 | |||
77 | // Any other request, pass on current response |
||
78 | return $response; |
||
79 | } |
||
81 |