Conditions | 5 |
Paths | 1 |
Total Lines | 90 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 20 | ||
Bugs | 2 | 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 |
||
33 | public function __invoke(ContainerInterface $container) |
||
34 | { |
||
35 | $routes = [ |
||
36 | // Lonely pages of site |
||
37 | Route::get('/', [SiteController::class, 'index']) |
||
38 | ->name('site/index'), |
||
39 | Route::methods([Method::GET, Method::POST], '/contact', [ContactController::class, 'contact']) |
||
40 | ->name('site/contact'), |
||
41 | Route::methods([Method::GET, Method::POST], '/login', [AuthController::class, 'login']) |
||
42 | ->name('site/login'), |
||
43 | Route::get('/logout', [AuthController::class, 'logout']) |
||
44 | ->name('site/logout'), |
||
45 | |||
46 | // User |
||
47 | Group::create('/user', [ |
||
48 | // Index |
||
49 | Route::get('[/page-{page:\d+}]', [UserController::class, 'index']) |
||
50 | ->name('user/index'), |
||
51 | // Profile page |
||
52 | Route::get('/{login}', [UserController::class, 'profile']) |
||
53 | ->name('user/profile'), |
||
54 | ]), |
||
55 | |||
56 | // User |
||
57 | Group::create('/api', [ |
||
58 | Route::get('/info/v1', function (WebResponseFactoryInterface $responseFactory) { |
||
59 | return $responseFactory->createResponse(['version' => '1.0', 'author' => 'yiisoft']); |
||
60 | })->name('api/info/v1'), |
||
61 | Route::get('/info/v2', ApiInfo::class) |
||
62 | ->addMiddleware(JsonWebResponseFormatter::class) |
||
63 | ->name('api/info/v2'), |
||
64 | Route::get('/user', [ApiUserController::class, 'index']) |
||
65 | ->name('api/user/index'), |
||
66 | Route::get('/user/{login}', [ApiUserController::class, 'profile']) |
||
67 | ->addMiddleware(JsonWebResponseFormatter::class) |
||
68 | ->name('api/user/profile'), |
||
69 | ], $container)->addMiddleware(function (ServerRequestInterface $request, RequestHandlerInterface $handler) { |
||
70 | $response = $handler->handle($request); |
||
71 | if ($response instanceof WebResponse) { |
||
72 | $data = $response->getData(); |
||
73 | if ($response->getStatusCode() !== 200) { |
||
74 | if (is_string($data) && !empty($data)) { |
||
75 | $message = $data; |
||
76 | } else { |
||
77 | $message = 'Unknown error'; |
||
78 | } |
||
79 | return $response->withData([ |
||
80 | 'status' => 'failed', |
||
81 | 'error' => ['message' => $message, 'status' => $response->getStatusCode()], |
||
82 | ]); |
||
83 | } |
||
84 | return $response->withData(['status' => 'success', 'data' => $data]); |
||
85 | } |
||
86 | |||
87 | return $response; |
||
88 | })->addMiddleware(XmlWebResponseFormatter::class), |
||
89 | |||
90 | // Blog routes |
||
91 | Group::create('/blog', [ |
||
92 | // Index |
||
93 | Route::get('[/page{page:\d+}]', [BlogController::class, 'index']) |
||
94 | ->name('blog/index'), |
||
95 | // Post page |
||
96 | Route::get('/page/{slug}', [PostController::class, 'index']) |
||
97 | ->name('blog/post'), |
||
98 | // Tag page |
||
99 | Route::get('/tag/{label}[/page{page:\d+}]', [TagController::class, 'index']) |
||
100 | ->name('blog/tag'), |
||
101 | // Archive |
||
102 | Group::create('/blog', [ |
||
103 | // Index page |
||
104 | Route::get('', [ArchiveController::class, 'index']) |
||
105 | ->name('blog/archive/index'), |
||
106 | // Yearly page |
||
107 | Route::get('/{year:\d+}', [ArchiveController::class, 'yearlyArchive']) |
||
108 | ->name('blog/archive/year'), |
||
109 | // Monthly page |
||
110 | Route::get('/{year:\d+}-{month:\d+}[/page{page:\d+}]', [ArchiveController::class, 'monthlyArchive']) |
||
111 | ->name('blog/archive/month') |
||
112 | ]), |
||
113 | ]), |
||
114 | ]; |
||
115 | |||
116 | $collector = $container->get(RouteCollectorInterface::class); |
||
117 | $collector->addGroup( |
||
118 | Group::create(null, $routes) |
||
119 | ->addMiddleware(WebResponseFormatter::class) |
||
120 | ); |
||
121 | |||
122 | return new UrlMatcher(new RouteCollection($collector)); |
||
123 | } |
||
125 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths