Conditions | 12 |
Paths | 21 |
Total Lines | 83 |
Code Lines | 42 |
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 |
||
54 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
55 | { |
||
56 | // Ugly URLs store the path in a query parameter. |
||
57 | $url_route = Validator::queryParams($request)->string('route', ''); |
||
58 | |||
59 | if (Validator::attributes($request)->boolean('rewrite_urls', false)) { |
||
60 | // We are creating pretty URLs, but received an ugly one. Probably a search-engine. Redirect it. |
||
61 | if ($url_route !== '') { |
||
62 | $uri = $request->getUri() |
||
63 | ->withPath($url_route) |
||
64 | ->withQuery(explode('&', $request->getUri()->getQuery(), 2)[1] ?? ''); |
||
65 | |||
66 | return Registry::responseFactory() |
||
67 | ->redirectUrl($uri, StatusCodeInterface::STATUS_PERMANENT_REDIRECT) |
||
68 | ->withHeader('Link', '<' . $uri . '>; rel="canonical"'); |
||
69 | } |
||
70 | |||
71 | $pretty = $request; |
||
72 | } else { |
||
73 | // Turn the ugly URL into a pretty one, so the router can parse it. |
||
74 | $uri = $request->getUri()->withPath($url_route); |
||
75 | $pretty = $request->withUri($uri); |
||
76 | } |
||
77 | |||
78 | // Match the request to a route. |
||
79 | $matcher = $this->router_container->getMatcher(); |
||
80 | $route = $matcher->match($pretty); |
||
81 | |||
82 | // No route matched? |
||
83 | if ($route === false) { |
||
84 | $failed_route = $matcher->getFailedRoute(); |
||
85 | |||
86 | if ($failed_route instanceof Route) { |
||
87 | if ($failed_route->failedRule === Allows::class) { |
||
88 | return Registry::responseFactory()->response('', StatusCodeInterface::STATUS_METHOD_NOT_ALLOWED, [ |
||
89 | 'Allow' => implode(', ', $failed_route->allows), |
||
90 | ]); |
||
91 | } |
||
92 | |||
93 | if ($failed_route->failedRule === Accepts::class) { |
||
94 | return Registry::responseFactory()->response('Negotiation failed', StatusCodeInterface::STATUS_NOT_ACCEPTABLE); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | return $handler->handle($request); |
||
99 | } |
||
100 | |||
101 | // Add the route as attribute of the request |
||
102 | $request = $request->withAttribute('route', $route); |
||
103 | |||
104 | $route_middleware = $route->extras['middleware'] ?? []; |
||
105 | |||
106 | $module_middleware = $this->module_service->findByInterface(MiddlewareInterface::class)->all(); |
||
107 | |||
108 | $middleware = [ |
||
109 | ...$route_middleware, |
||
110 | CheckCsrf::class, |
||
111 | ...$module_middleware, |
||
112 | RequestHandler::class, |
||
113 | ]; |
||
114 | |||
115 | // Add the matched attributes to the request. |
||
116 | foreach ($route->attributes as $key => $value) { |
||
117 | if ($key === 'tree') { |
||
118 | $value = $this->tree_service->all()->get($value); |
||
119 | |||
120 | if ($value instanceof Tree) { |
||
121 | Registry::container()->set(Tree::class, $value); |
||
122 | } |
||
123 | |||
124 | // Missing mandatory parameter? Let the default handler take care of it. |
||
125 | if ($value === null && str_contains($route->path, '{tree}')) { |
||
126 | return $handler->handle($request); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | $request = $request->withAttribute((string) $key, $value); |
||
131 | } |
||
132 | |||
133 | // Bind the updated request into the container |
||
134 | Registry::container()->set(ServerRequestInterface::class, $request); |
||
135 | |||
136 | return Dispatcher::dispatch(middleware: $middleware, request: $request); |
||
137 | } |
||
139 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths