Conditions | 16 |
Paths | 424 |
Total Lines | 110 |
Code Lines | 66 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
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 |
||
185 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null) |
||
186 | { |
||
187 | try { |
||
188 | $urlNodesCacheItem = $this->cachePool->getItem('splashUrlNodes'); |
||
189 | if (!$urlNodesCacheItem->isHit()) { |
||
190 | // No value in cache, let's get the URL nodes |
||
191 | $urlsList = $this->getSplashActionsList(); |
||
192 | $urlNodes = $this->generateUrlNode($urlsList); |
||
193 | $urlNodesCacheItem->set($urlNodes); |
||
194 | $this->cachePool->save($urlNodesCacheItem); |
||
195 | } |
||
196 | |||
197 | $urlNodes = $urlNodesCacheItem->get(); |
||
198 | |||
199 | $request_path = $request->getUri()->getPath(); |
||
200 | |||
201 | $pos = strpos($request_path, $this->rootUrl); |
||
202 | if ($pos === false) { |
||
203 | throw new SplashException('Error: the prefix of the web application "'.$this->rootUrl.'" was not found in the URL. The application must be misconfigured. Check the ROOT_URL parameter in your config.php file at the root of your project. It should have the same value as the RewriteBase parameter in your .htaccess file. Requested URL : "'.$request_path.'"'); |
||
204 | } |
||
205 | |||
206 | $tailing_url = substr($request_path, $pos + strlen($this->rootUrl)); |
||
207 | |||
208 | $context = new SplashRequestContext($request); |
||
209 | $splashRoute = $urlNodes->walk($tailing_url, $request); |
||
210 | |||
211 | if ($splashRoute === null) { |
||
212 | // No route found. Let's try variants with or without trailing / if we are in a GET. |
||
213 | if ($request->getMethod() === 'GET') { |
||
214 | // If there is a trailing /, let's remove it and retry |
||
215 | if (strrpos($tailing_url, '/') === strlen($tailing_url) - 1) { |
||
216 | $url = substr($tailing_url, 0, -1); |
||
217 | $splashRoute = $urlNodes->walk($url, $request); |
||
218 | } else { |
||
219 | $url = $tailing_url.'/'; |
||
220 | $splashRoute = $urlNodes->walk($url, $request); |
||
221 | } |
||
222 | |||
223 | if ($splashRoute !== null) { |
||
224 | // If a route does match, let's make a redirect. |
||
225 | return new RedirectResponse($this->rootUrl.$url); |
||
226 | } |
||
227 | } |
||
228 | |||
229 | $this->log->debug('Found no route for URL {url}.', [ |
||
230 | 'url' => $request_path, |
||
231 | ]); |
||
232 | |||
233 | // No route found, let's pass control to the next middleware. |
||
234 | if ($out !== null) { |
||
235 | return $out($request, $response); |
||
236 | } else { |
||
237 | throw PageNotFoundException::create($tailing_url); |
||
238 | } |
||
239 | } |
||
240 | |||
241 | $controller = $this->container->get($splashRoute->controllerInstanceName); |
||
242 | $action = $splashRoute->methodName; |
||
243 | |||
244 | $context->setUrlParameters($splashRoute->filledParameters); |
||
245 | |||
246 | $this->log->debug('Routing URL {url} to controller instance {controller} and action {action}', [ |
||
247 | 'url' => $request_path, |
||
248 | 'controller' => $splashRoute->controllerInstanceName, |
||
249 | 'action' => $action, |
||
250 | ]); |
||
251 | |||
252 | // Let's pass everything to the controller: |
||
253 | $args = $this->parameterFetcherRegistry->toArguments($context, $splashRoute->parameters); |
||
254 | |||
255 | $filters = $splashRoute->filters; |
||
256 | |||
257 | // Apply filters |
||
258 | for ($i = count($filters) - 1; $i >= 0; --$i) { |
||
259 | $filters[$i]->beforeAction(); |
||
260 | } |
||
261 | |||
262 | $response = SplashUtils::buildControllerResponse( |
||
263 | function () use ($controller, $action, $args) { |
||
264 | return call_user_func_array(array($controller, $action), $args); |
||
265 | }, |
||
266 | $this->mode, |
||
267 | $this->debug |
||
268 | ); |
||
269 | |||
270 | foreach ($filters as $filter) { |
||
271 | $filter->afterAction(); |
||
272 | } |
||
273 | |||
274 | return $response; |
||
275 | } catch (BadRequestException $e) { |
||
276 | if ($this->http400Handler !== null) { |
||
277 | return $this->http400Handler->badRequest($e, $request); |
||
278 | } else { |
||
279 | throw $e; |
||
280 | } |
||
281 | } catch (PageNotFoundException $e) { |
||
282 | if ($this->http404Handler !== null) { |
||
283 | return $this->http404Handler->pageNotFound($request); |
||
284 | } else { |
||
285 | throw $e; |
||
286 | } |
||
287 | } catch (\Throwable $t) { |
||
288 | if ($this->http500Handler !== null) { |
||
289 | return $this->http500Handler->serverError($t, $request); |
||
290 | } else { |
||
291 | throw $t; |
||
292 | } |
||
293 | } |
||
294 | } |
||
295 | |||
341 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..