Conditions | 12 |
Paths | 25 |
Total Lines | 52 |
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 |
||
62 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
63 | { |
||
64 | $renderer = $this->debugBar->getJavascriptRenderer(); |
||
65 | |||
66 | //Is an asset? |
||
67 | $path = $request->getUri()->getPath(); |
||
68 | $renderPath = $renderer->getBaseUrl(); |
||
69 | |||
70 | if (strpos($path, $renderPath) === 0) { |
||
71 | $file = $renderer->getBasePath().substr($path, strlen($renderPath)); |
||
72 | |||
73 | if (file_exists($file)) { |
||
74 | return $response->withBody(self::createStream($file, 'r')); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | $response = $next($request, $response); |
||
79 | |||
80 | //Fix the render baseUrl |
||
81 | $generator = BasePath::getGenerator($request); |
||
82 | |||
83 | if ($generator) { |
||
84 | $renderer->setBaseUrl($generator($renderer->getBaseUrl())); |
||
85 | } |
||
86 | |||
87 | $ajax = Utils\Helpers::isAjax($request); |
||
88 | |||
89 | //Redirection response |
||
90 | if (Utils\Helpers::isRedirect($response)) { |
||
91 | if ($this->debugBar->isDataPersisted() || session_status() === PHP_SESSION_ACTIVE) { |
||
92 | $this->debugBar->stackData(); |
||
93 | } |
||
94 | |||
95 | //Html response |
||
96 | } elseif (Utils\Helpers::getMimeType($response) === 'text/html') { |
||
97 | if (!$ajax) { |
||
98 | $response = $this->inject($response, $renderer->renderHead(), 'head'); |
||
99 | } |
||
100 | |||
101 | $response = $this->inject($response, $renderer->render(!$ajax), 'body'); |
||
102 | |||
103 | //Ajax response |
||
104 | } elseif ($ajax && $this->captureAjax) { |
||
105 | $headers = $this->debugBar->getDataAsHeaders(); |
||
106 | |||
107 | foreach ($headers as $name => $value) { |
||
108 | $response = $response->withHeader($name, $value); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | return $response; |
||
113 | } |
||
114 | } |
||
115 |