Conditions | 9 |
Paths | 20 |
Total Lines | 86 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
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 |
||
132 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null) |
||
133 | { |
||
134 | $urlNodesCacheItem = $this->cachePool->getItem('splashUrlNodes'); |
||
135 | if (!$urlNodesCacheItem->isHit()) { |
||
136 | // No value in cache, let's get the URL nodes |
||
137 | $urlsList = $this->getSplashActionsList(); |
||
138 | $urlNodes = $this->generateUrlNode($urlsList); |
||
139 | $urlNodesCacheItem->set($urlNodes); |
||
140 | $this->cachePool->save($urlNodesCacheItem); |
||
141 | } |
||
142 | |||
143 | $urlNodes = $urlNodesCacheItem->get(); |
||
144 | |||
145 | $request_path = $request->getUri()->getPath(); |
||
146 | |||
147 | $pos = strpos($request_path, $this->rootUrl); |
||
148 | if ($pos === false) { |
||
149 | 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.'"'); |
||
150 | } |
||
151 | |||
152 | $tailing_url = substr($request_path, $pos + strlen($this->rootUrl)); |
||
153 | |||
154 | $context = new SplashRequestContext($request); |
||
155 | $splashRoute = $urlNodes->walk($tailing_url, $request); |
||
156 | |||
157 | if ($splashRoute === null) { |
||
158 | // No route found. Let's try variants with or without trailing / if we are in a GET. |
||
159 | if ($request->getMethod() === 'GET') { |
||
160 | // If there is a trailing /, let's remove it and retry |
||
161 | if (strrpos($tailing_url, '/') === strlen($tailing_url)-1) { |
||
162 | $url = substr($tailing_url, 0, -1); |
||
163 | $splashRoute = $urlNodes->walk($url, $request); |
||
164 | } else { |
||
165 | $url = $tailing_url.'/'; |
||
166 | $splashRoute = $urlNodes->walk($url, $request); |
||
167 | } |
||
168 | |||
169 | if ($splashRoute !== null) { |
||
170 | // If a route does match, let's make a redirect. |
||
171 | return new RedirectResponse($this->rootUrl.$url); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | $this->log->debug('Found no route for URL {url}.', [ |
||
176 | 'url' => $request_path, |
||
177 | ]); |
||
178 | |||
179 | // No route found, let's pass control to the next middleware. |
||
180 | return $out($request, $response); |
||
181 | } |
||
182 | |||
183 | $controller = $this->container->get($splashRoute->controllerInstanceName); |
||
184 | $action = $splashRoute->methodName; |
||
185 | |||
186 | $context->setUrlParameters($splashRoute->filledParameters); |
||
187 | |||
188 | $this->log->debug('Routing URL {url} to controller instance {controller} and action {action}', [ |
||
189 | 'url' => $request_path, |
||
190 | 'controller' => $splashRoute->controllerInstanceName, |
||
191 | 'action' => $action, |
||
192 | ]); |
||
193 | |||
194 | // Let's pass everything to the controller: |
||
195 | $args = $this->parameterFetcherRegistry->toArguments($context, $splashRoute->parameters); |
||
196 | |||
197 | $filters = $splashRoute->filters; |
||
198 | |||
199 | // Apply filters |
||
200 | for ($i = count($filters) - 1; $i >= 0; --$i) { |
||
201 | $filters[$i]->beforeAction(); |
||
202 | } |
||
203 | |||
204 | $response = SplashUtils::buildControllerResponse( |
||
205 | function () use ($controller, $action, $args) { |
||
206 | return call_user_func_array(array($controller, $action), $args); |
||
207 | }, |
||
208 | $this->mode, |
||
209 | $this->debug |
||
210 | ); |
||
211 | |||
212 | foreach ($filters as $filter) { |
||
213 | $filter->afterAction(); |
||
214 | } |
||
215 | |||
216 | return $response; |
||
217 | } |
||
218 | |||
264 |
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..