| Conditions | 4 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 32 |
| 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 |
||
| 12 | public function register(App $app) |
||
| 13 | { |
||
| 14 | $app['middleware'] = function (App $app): Dispatcher { |
||
| 15 | $middleware = []; |
||
| 16 | |||
| 17 | if ($app->has('users')) { |
||
| 18 | $middleware[] = new Middlewares\DigestAuthentication($app['users']); |
||
| 19 | } |
||
| 20 | |||
| 21 | $middleware[] = new Middlewares\Expires(); |
||
| 22 | $middleware[] = (new Middlewares\ErrorHandler()) |
||
| 23 | ->catchExceptions(false) |
||
| 24 | ->statusCode(function ($code) { |
||
| 25 | return $code > 400 && $code < 600; |
||
| 26 | }) |
||
| 27 | ->arguments($app); |
||
| 28 | |||
| 29 | $middleware[] = new Middlewares\BasePath($app->getUri()->getPath()); |
||
| 30 | $middleware[] = new Middlewares\TrailingSlash(); |
||
| 31 | $middleware[] = new Middlewares\ContentType(); |
||
| 32 | $middleware[] = new Middlewares\ContentLanguage(['en', 'gl', 'es']); |
||
| 33 | |||
| 34 | $middleware[] = function ($request, $next) use ($app) { |
||
| 35 | $language = $request->getHeaderLine('Accept-Language'); |
||
| 36 | $translator = new Translator(); |
||
| 37 | $translator->loadTranslations(Translations::fromPoFile(dirname(dirname(__DIR__)).'/locales/'.$language.'.po')); |
||
| 38 | $prev = $translator->register(); |
||
| 39 | |||
| 40 | $app['templates']->addData(['language' => $language]); |
||
| 41 | |||
| 42 | $response = $next->process($request); |
||
| 43 | |||
| 44 | if ($prev) { |
||
| 45 | $prev->register(); |
||
| 46 | } |
||
| 47 | |||
| 48 | return $response; |
||
| 49 | }; |
||
| 50 | |||
| 51 | $middleware[] = (new Middlewares\MethodOverride()) |
||
| 52 | ->parsedBodyParameter('method-override'); |
||
| 53 | |||
| 54 | $middleware[] = (new Middlewares\Reader(dirname(dirname(__DIR__)).'/assets')) |
||
| 55 | ->continueOnError(); |
||
| 56 | |||
| 57 | $middleware[] = (new Middlewares\AuraRouter($app['router'])) |
||
| 58 | ->arguments($app); |
||
| 59 | |||
| 60 | return new Dispatcher($middleware); |
||
|
|
|||
| 61 | }; |
||
| 62 | } |
||
| 63 | } |
||
| 64 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: