Conditions | 9 |
Paths | 12 |
Total Lines | 53 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
40 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
|
|||
41 | { |
||
42 | $router = new RouterContainer; |
||
43 | |||
44 | $this->loadRoutes($router->getMap()); |
||
45 | |||
46 | $matcher = $router->getMatcher(); |
||
47 | |||
48 | $match = $matcher->match($request); |
||
49 | |||
50 | if (!$match) { |
||
51 | $failedRoute = $matcher->getFailedRoute(); |
||
52 | |||
53 | if ($failedRoute && $failedRoute->failedRule == 'Aura\Router\Rule\Allows') { |
||
54 | if ($this->container->has(ResponseFactoryInterface::CLASS)) { |
||
55 | return $this->container->get(ResponseFactoryInterface::CLASS) |
||
56 | ->createResponse(405, 'Method Not Allowed') |
||
57 | ->withHeader('Allow', implode(', ', $failedRoute->allows)); |
||
58 | } |
||
59 | |||
60 | throw new MethodNotAllowedException($request, ['allows' => $failedRoute->allows]); |
||
61 | } |
||
62 | |||
63 | if ($this->container->has(ResponseFactoryInterface::CLASS)) { |
||
64 | return $this->container->get(ResponseFactoryInterface::CLASS)->createResponse(404, 'Not Found'); |
||
65 | } |
||
66 | |||
67 | throw new RouteNotFoundException($request); |
||
68 | } |
||
69 | |||
70 | /** @var RouteInterface $route */ |
||
71 | $route = $match->handler; |
||
72 | |||
73 | foreach ($route->getAttributes() as $name => $val) { |
||
74 | $request = $request->withAttribute($name, $val); |
||
75 | } |
||
76 | |||
77 | foreach ($match->attributes as $name => $val) { |
||
78 | $request = $request->withAttribute($name, $val); |
||
79 | } |
||
80 | |||
81 | $middlewares = []; |
||
82 | |||
83 | foreach ($route->getMiddlewareServiceIds() as $serviceId) { |
||
84 | $middlewares[] = $this->container->get($serviceId); |
||
85 | } |
||
86 | |||
87 | $middlewares[] = new DispatchingMiddleware( |
||
88 | [$this->container->get($route->getServiceId()), $route->getServiceMethod()], |
||
89 | new Environment($route, new UrlGenerator($router->getGenerator())) |
||
90 | ); |
||
91 | |||
92 | return (new Pipeline(...$middlewares))->handle($request); |
||
93 | } |
||
95 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.