Conditions | 1 |
Paths | 1 |
Total Lines | 85 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 1 | 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 |
||
27 | public function __invoke(ContainerInterface $container) |
||
28 | { |
||
29 | $routes = [ |
||
30 | // Lonely pages of site |
||
31 | Route::get('/', [SiteController::class, 'index']) |
||
32 | ->name('site/index'), |
||
33 | Route::methods([Method::GET, Method::POST], '/contact', [ContactController::class, 'contact']) |
||
34 | ->name('site/contact'), |
||
35 | Route::methods([Method::GET, Method::POST], '/login', [AuthController::class, 'login']) |
||
36 | ->name('site/login'), |
||
37 | Route::get('/logout', [AuthController::class, 'logout']) |
||
38 | ->name('site/logout'), |
||
39 | |||
40 | // User |
||
41 | Group::create('/user', [ |
||
42 | // Index |
||
43 | Route::get('[/page-{page:\d+}]', [UserController::class, 'index']) |
||
44 | ->name('user/index'), |
||
45 | // Profile page |
||
46 | Route::get('/{login}', [UserController::class, 'profile']) |
||
47 | ->name('user/profile'), |
||
48 | ]), |
||
49 | |||
50 | // Blog routes |
||
51 | Group::create('/blog', [ |
||
52 | // Index |
||
53 | Route::get('[/page{page:\d+}]', [BlogController::class, 'index']) |
||
54 | ->name('blog/index'), |
||
55 | // Post page |
||
56 | Route::get('/page/{slug}', [PostController::class, 'index']) |
||
57 | ->name('blog/post'), |
||
58 | // Tag page |
||
59 | Route::get('/tag/{label}[/page{page:\d+}]', [TagController::class, 'index']) |
||
60 | ->name('blog/tag'), |
||
61 | // Archive |
||
62 | Group::create('/archive', [ |
||
63 | // Index page |
||
64 | Group::create('', [ |
||
65 | Route::get('', fn (ServerRequestInterface $request, RequestHandlerInterface $handler) => ( |
||
66 | new ActionCaller(ArchiveController::class, 'index', $container) |
||
67 | )->process($request, $handler)) |
||
68 | ->addMiddleware(fn (ServerRequestInterface $request, RequestHandlerInterface $handler) => ( |
||
69 | new SetFormat('text/html', null) |
||
70 | )->process($request, $handler)) |
||
71 | ->name('blog/archive/index'), |
||
72 | Route::get('/print_r', fn (ServerRequestInterface $request, RequestHandlerInterface $handler) => ( |
||
73 | new ActionCaller(ArchiveController::class, 'index', $container) |
||
74 | )->process($request, $handler)) |
||
75 | ->addMiddleware(fn (ServerRequestInterface $request, RequestHandlerInterface $handler) => ( |
||
76 | new SetFormat('text/plain') |
||
77 | )->process($request, $handler)) |
||
78 | ->name('blog/archive/index/print_r'), |
||
79 | Route::get('/xml', fn (ServerRequestInterface $request, RequestHandlerInterface $handler) => ( |
||
80 | new ActionCaller(ArchiveController::class, 'index', $container) |
||
81 | )->process($request, $handler)) |
||
82 | ->addMiddleware(fn (ServerRequestInterface $request, RequestHandlerInterface $handler) => ( |
||
83 | new SetFormat('text/xml') |
||
84 | )->process($request, $handler)) |
||
85 | ->name('blog/archive/index/xml'), |
||
86 | Route::get('/json', fn (ServerRequestInterface $request, RequestHandlerInterface $handler) => ( |
||
87 | new ActionCaller(ArchiveController::class, 'index', $container) |
||
88 | )->process($request, $handler)) |
||
89 | ->name('blog/archive/index/json'), |
||
90 | Route::get('/custom', fn (ServerRequestInterface $request, RequestHandlerInterface $handler) => new ActionCaller(ArchiveController::class, 'custom', $container)) |
||
91 | ->name('blog/archive/index/custom'), |
||
92 | ]), |
||
93 | // Yearly page |
||
94 | Route::get('/{year:\d+}', [ArchiveController::class, 'yearlyArchive']) |
||
95 | ->name('blog/archive/year'), |
||
96 | // Monthly page |
||
97 | Route::get('/{year:\d+}-{month:\d+}[/page{page:\d+}]', [ArchiveController::class, 'monthlyArchive']) |
||
98 | ->name('blog/archive/month') |
||
99 | ] |
||
100 | )->addMiddleware( |
||
101 | fn(ServerRequestInterface $request, RequestHandlerInterface $handler) => (new SetFormat( |
||
102 | 'application/json' |
||
103 | ))->process($request, $handler) |
||
104 | ), |
||
105 | ]), |
||
106 | ]; |
||
107 | |||
108 | $collector = $container->get(RouteCollectorInterface::class); |
||
109 | $collector->addGroup(Group::create(null, $routes)); |
||
110 | |||
111 | return new UrlMatcher(new RouteCollection($collector)); |
||
112 | } |
||
114 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.