| Conditions | 10 |
| Paths | 10 |
| Total Lines | 36 |
| Code Lines | 16 |
| 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 |
||
| 80 | private function resolveResponse(ServerRequestInterface $request, Route $route) |
||
| 81 | { |
||
| 82 | $handler = $route->getController(); |
||
| 83 | |||
| 84 | if ($handler instanceof RequestHandlerInterface) { |
||
| 85 | return $handler->handle($request); |
||
| 86 | } |
||
| 87 | |||
| 88 | if ($handler instanceof ResponseInterface) { |
||
| 89 | return $handler; |
||
| 90 | } |
||
| 91 | |||
| 92 | if (null !== $this->namespace) { |
||
| 93 | $handler = $this->resolveNamespace($handler); |
||
| 94 | } |
||
| 95 | |||
| 96 | // For a class that implements RequestHandlerInterface, we will call handle() |
||
| 97 | // if no method has been specified explicitly |
||
| 98 | if (\is_string($handler) && \is_a($handler, RequestHandlerInterface::class, true)) { |
||
| 99 | return $this->invoker->call([$handler, 'handle'], [$request]); |
||
| 100 | } |
||
| 101 | |||
| 102 | // Disable or enable HTTP request method prefix for action. |
||
| 103 | if (null !== $isRestFul = $route->getDefaults()['_api'] ?? null) { |
||
| 104 | $method = \strtolower($request->getMethod()); |
||
| 105 | |||
| 106 | if (!\is_object($handler) || (\is_string($handler) && \class_exists($handler))) { |
||
| 107 | throw new InvalidControllerException( |
||
| 108 | 'Resource handler type should be a class string or class object, and not otherwise' |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | |||
| 112 | return [$handler, $method . $isRestFul]; |
||
| 113 | } |
||
| 114 | |||
| 115 | return $handler; |
||
| 116 | } |
||
| 139 |