Conditions | 1 |
Paths | 1 |
Total Lines | 84 |
Code Lines | 56 |
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 |
||
35 | public function __invoke(ContainerInterface $container) |
||
36 | { |
||
37 | $routes = [ |
||
38 | // Lonely pages of site |
||
39 | Route::get('/', [SiteController::class, 'index']) |
||
40 | ->name('site/index'), |
||
41 | Route::methods([Method::GET, Method::POST], '/contact', [ContactController::class, 'contact']) |
||
42 | ->name('site/contact'), |
||
43 | Route::methods([Method::GET, Method::POST], '/login', [AuthController::class, 'login']) |
||
44 | ->name('site/login'), |
||
45 | Route::get('/logout', [AuthController::class, 'logout']) |
||
46 | ->name('site/logout'), |
||
47 | Route::methods([Method::GET, Method::POST], '/signup', [SignupController::class, 'signup']) |
||
48 | ->name('site/signup'), |
||
49 | |||
50 | // User |
||
51 | Group::create('/user', [ |
||
52 | // Index |
||
53 | Route::get('[/page-{page:\d+}]', [UserController::class, 'index']) |
||
54 | ->name('user/index'), |
||
55 | // Profile page |
||
56 | Route::get('/{login}', [UserController::class, 'profile']) |
||
57 | ->name('user/profile'), |
||
58 | ]), |
||
59 | |||
60 | // User |
||
61 | Group::create('/api', [ |
||
62 | Route::get('/info/v1', function (DataResponseFactoryInterface $responseFactory) { |
||
63 | return $responseFactory->createResponse(['version' => '1.0', 'author' => 'yiisoft']); |
||
64 | })->name('api/info/v1'), |
||
65 | Route::get('/info/v2', ApiInfo::class) |
||
66 | ->addMiddleware(FormatDataResponseAsJson::class) |
||
67 | ->name('api/info/v2'), |
||
68 | Route::get('/user', [ApiUserController::class, 'index']) |
||
69 | ->name('api/user/index'), |
||
70 | Route::get('/user/{login}', [ApiUserController::class, 'profile']) |
||
71 | ->addMiddleware(FormatDataResponseAsJson::class) |
||
72 | ->name('api/user/profile'), |
||
73 | ])->addMiddleware(ApiDataWrapper::class)->addMiddleware(FormatDataResponseAsXml::class), |
||
74 | |||
75 | // Blog routes |
||
76 | Group::create('/blog', [ |
||
77 | // Index |
||
78 | Route::get('[/page{page:\d+}]', [BlogController::class, 'index']) |
||
79 | ->name('blog/index'), |
||
80 | // Add Post page |
||
81 | Route::methods([Method::GET, Method::POST], '/page/add', [PostController::class, 'add']) |
||
82 | ->name('blog/add')->addMiddleware(Authentication::class), |
||
83 | // Edit Post page |
||
84 | Route::methods([Method::GET, Method::POST], '/page/edit/{slug}', [PostController::class, 'edit']) |
||
85 | ->name('blog/edit') |
||
86 | ->addMiddleware(Authentication::class) |
||
87 | ->addMiddleware(fn () => $container->get(AccessChecker::class)->withPermission('editPost')), |
||
88 | // Post page |
||
89 | Route::get('/page/{slug}', [PostController::class, 'index']) |
||
90 | ->name('blog/post'), |
||
91 | // Tag page |
||
92 | Route::get('/tag/{label}[/page{page:\d+}]', [TagController::class, 'index']) |
||
93 | ->name('blog/tag'), |
||
94 | // Archive |
||
95 | Group::create('/archive', [ |
||
96 | // Index page |
||
97 | Route::get('', [ArchiveController::class, 'index']) |
||
98 | ->name('blog/archive/index'), |
||
99 | // Yearly page |
||
100 | Route::get('/{year:\d+}', [ArchiveController::class, 'yearlyArchive']) |
||
101 | ->name('blog/archive/year'), |
||
102 | // Monthly page |
||
103 | Route::get('/{year:\d+}-{month:\d+}[/page{page:\d+}]', [ArchiveController::class, 'monthlyArchive']) |
||
104 | ->name('blog/archive/month') |
||
105 | ]), |
||
106 | // comments |
||
107 | Route::get('/comments/[next/{next}]', [CommentController::class, 'index']) |
||
108 | ->name('blog/comment/index'), |
||
109 | ]), |
||
110 | ]; |
||
111 | |||
112 | $collector = $container->get(RouteCollectorInterface::class); |
||
113 | $collector->addGroup( |
||
114 | Group::create(null, $routes) |
||
115 | ->addMiddleware(FormatDataResponse::class) |
||
116 | ); |
||
117 | |||
118 | return new UrlMatcher(new RouteCollection($collector)); |
||
119 | } |
||
121 |