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