| Conditions | 12 |
| Paths | 2 |
| Total Lines | 94 |
| Code Lines | 32 |
| Lines | 40 |
| Ratio | 42.55 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 86 | public function setupHandlers(RequestInterface $request, ResponseInterface $response, callable $next) |
||
| 87 | { |
||
| 88 | $config = $this->config(); |
||
| 89 | $container = $this->app()->getContainer(); |
||
| 90 | $baseUrl = $container['request']->getUri()->getBaseUrl(); |
||
| 91 | $adminUrl = rtrim($baseUrl, '/\\').'/'.trim($config['base_path'], '/\\'); |
||
| 92 | |||
| 93 | if (isset($config['handlers'])) { |
||
| 94 | |||
| 95 | /** |
||
| 96 | * HTTP 404 (Not Found) handler. |
||
| 97 | * |
||
| 98 | * @param object|HandlerInterface $handler An error handler instance. |
||
| 99 | * @param Container $container A container instance. |
||
| 100 | * @return HandlerInterface |
||
| 101 | */ |
||
| 102 | View Code Duplication | $container->extend('notFoundHandler', function ($handler, Container $container) use ($config, $adminUrl) { |
|
| 103 | if ($handler instanceof HandlerInterface && isset($config['handlers.defaults'])) { |
||
| 104 | $handler->config()->merge($config['handlers.defaults']); |
||
| 105 | $handler->setBaseUrl($adminUrl); |
||
| 106 | } |
||
| 107 | |||
| 108 | return $handler; |
||
| 109 | }); |
||
| 110 | |||
| 111 | /** |
||
| 112 | * HTTP 405 (Not Allowed) handler. |
||
| 113 | * |
||
| 114 | * @param object|HandlerInterface $handler An error handler instance. |
||
| 115 | * @param Container $container A container instance. |
||
| 116 | * @return HandlerInterface |
||
| 117 | */ |
||
| 118 | View Code Duplication | $container->extend('notAllowedHandler', function ($handler, Container $container) use ($config, $adminUrl) { |
|
| 119 | if ($handler instanceof HandlerInterface && isset($config['handlers.defaults'])) { |
||
| 120 | $handler->config()->merge($config['handlers.defaults']); |
||
| 121 | $handler->setBaseUrl($adminUrl); |
||
| 122 | } |
||
| 123 | |||
| 124 | return $handler; |
||
| 125 | }); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * HTTP 500 (Error) handler for PHP 7+ Throwables. |
||
| 129 | * |
||
| 130 | * @param object|HandlerInterface $handler An error handler instance. |
||
| 131 | * @param Container $container A container instance. |
||
| 132 | * @return HandlerInterface |
||
| 133 | */ |
||
| 134 | View Code Duplication | $container->extend('phpErrorHandler', function ($handler, Container $container) use ($config, $adminUrl) { |
|
| 135 | if ($handler instanceof HandlerInterface && isset($config['handlers.defaults'])) { |
||
| 136 | $handler->config()->merge($config['handlers.defaults']); |
||
| 137 | $handler->setBaseUrl($adminUrl); |
||
| 138 | } |
||
| 139 | |||
| 140 | return $handler; |
||
| 141 | }); |
||
| 142 | |||
| 143 | /** |
||
| 144 | * HTTP 500 (Error) handler. |
||
| 145 | * |
||
| 146 | * @param object|HandlerInterface $handler An error handler instance. |
||
| 147 | * @param Container $container A container instance. |
||
| 148 | * @return HandlerInterface |
||
| 149 | */ |
||
| 150 | View Code Duplication | $container->extend('errorHandler', function ($handler, Container $container) use ($config, $adminUrl) { |
|
| 151 | if ($handler instanceof HandlerInterface && isset($config['handlers.defaults'])) { |
||
| 152 | $handler->config()->merge($config['handlers.defaults']); |
||
| 153 | $handler->setBaseUrl($adminUrl); |
||
| 154 | } |
||
| 155 | |||
| 156 | return $handler; |
||
| 157 | }); |
||
| 158 | |||
| 159 | /** |
||
| 160 | * HTTP 503 (Service Unavailable) handler. |
||
| 161 | * |
||
| 162 | * This handler is not part of Slim. |
||
| 163 | * |
||
| 164 | * @param object|HandlerInterface $handler An error handler instance. |
||
| 165 | * @param Container $container A container instance. |
||
| 166 | * @return HandlerInterface |
||
| 167 | */ |
||
| 168 | View Code Duplication | $container->extend('shutdownHandler', function ($handler, Container $container) use ($config, $adminUrl) { |
|
| 169 | if ($handler instanceof HandlerInterface && isset($config['handlers.defaults'])) { |
||
| 170 | $handler->config()->merge($config['handlers.defaults']); |
||
| 171 | $handler->setBaseUrl($adminUrl); |
||
| 172 | } |
||
| 173 | |||
| 174 | return $handler; |
||
| 175 | }); |
||
| 176 | } |
||
| 177 | |||
| 178 | return $next($request, $response); |
||
| 179 | } |
||
| 180 | } |
||
| 181 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.