Conditions | 9 |
Paths | 144 |
Total Lines | 72 |
Code Lines | 41 |
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 |
||
17 | public function __invoke( |
||
18 | \Slim\Http\Request $request, |
||
19 | \Slim\Http\Response $response, |
||
20 | $next |
||
21 | ) { |
||
22 | $container = $this->container; |
||
23 | $subfolder = $this->container->getSubfolder(); |
||
24 | |||
25 | $route = $request->getAttribute('route'); |
||
26 | |||
27 | $container['server'] = $request->getParam('server'); |
||
28 | $container['database'] = $request->getParam('database'); |
||
29 | $container['schema'] = $request->getParam('schema'); |
||
30 | $misc = $container->get('misc'); |
||
31 | |||
32 | $view = $this->getViewManager($container); |
||
33 | |||
34 | $misc->setHREF(); |
||
35 | $view->setForm(); |
||
36 | |||
37 | $view->offsetSet('METHOD', $request->getMethod()); |
||
38 | |||
39 | if ($route) { |
||
40 | $view->offsetSet('subject', $route->getArgument('subject')); |
||
41 | $container['server'] = $route->getArgument('server', $request->getParam('server')); |
||
42 | } |
||
43 | |||
44 | $request = $request->withUri($this->getUri($request)->withBasePath($subfolder)); |
||
45 | $uri = $request->getUri(); |
||
46 | $query_string = $uri->getQuery(); |
||
47 | $requestPath = $uri->getPath(); |
||
48 | |||
49 | $view->offsetSet('query_string', $query_string); |
||
50 | $path = $requestPath . ($query_string ? '?' . $query_string : ''); |
||
51 | $view->offsetSet('path', $path); |
||
52 | |||
53 | $params = $request->getParams(); |
||
54 | |||
55 | $viewparams = []; |
||
56 | |||
57 | foreach ($params as $key => $value) { |
||
58 | if (\is_scalar($value)) { |
||
59 | $viewparams[$key] = $value; |
||
60 | } |
||
61 | } |
||
62 | |||
63 | if (isset($_COOKIE['IN_TEST'])) { |
||
64 | $in_test = (string) $_COOKIE['IN_TEST']; |
||
65 | } else { |
||
66 | $in_test = '0'; |
||
67 | } |
||
68 | |||
69 | // remove tabs and linebreaks from query |
||
70 | if (isset($params['query'])) { |
||
71 | $viewparams['query'] = \str_replace(["\r", "\n", "\t"], ' ', $params['query']); |
||
72 | } |
||
73 | $view->offsetSet('params', $viewparams); |
||
74 | $view->offsetSet('in_test', $in_test); |
||
75 | |||
76 | if (0 < \count($container['errors'])) { |
||
77 | return ($container->haltHandler)($request, $response, $container['errors'], 412); |
||
78 | } |
||
79 | $enqueued_reload_browser = ($container->flash->getFirstMessage('reload_browser') ?? false); |
||
80 | |||
81 | if ($enqueued_reload_browser) { |
||
82 | $view->setReloadBrowser($enqueued_reload_browser); |
||
83 | } |
||
84 | // First execute anything else |
||
85 | $response = $next($request, $response); |
||
86 | |||
87 | // Any other request, pass on current response |
||
88 | return $response; |
||
89 | } |
||
101 |