Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
40 | class Controller extends ApiController |
||
41 | { |
||
42 | |||
43 | /** |
||
44 | * @param \App\Containers\Authorization\UI\API\Requests\ListAllPermissionsRequest $request |
||
45 | * @param \App\Containers\Authorization\Actions\ListAllPermissionsAction $action |
||
46 | * |
||
47 | * @return \Dingo\Api\Http\Response |
||
48 | */ |
||
49 | public function listAllPermissions(ListAllPermissionsRequest $request, ListAllPermissionsAction $action) |
||
55 | |||
56 | /** |
||
57 | * @param \App\Containers\Authorization\UI\API\Requests\GetPermissionRequest $request |
||
58 | * @param \App\Containers\Authorization\Actions\GetPermissionAction $action |
||
59 | * |
||
60 | * @return \Dingo\Api\Http\Response |
||
61 | */ |
||
62 | public function getPermission(GetPermissionRequest $request, GetPermissionAction $action) |
||
68 | |||
69 | /** |
||
70 | * @param \App\Containers\Authorization\UI\API\Requests\ListAllRolesRequest $request |
||
71 | * @param \App\Containers\Authorization\Actions\ListAllRolesAction $action |
||
72 | * |
||
73 | * @return \Dingo\Api\Http\Response |
||
74 | */ |
||
75 | public function listAllRoles(ListAllRolesRequest $request, ListAllRolesAction $action) |
||
81 | |||
82 | /** |
||
83 | * @param \App\Containers\Authorization\UI\API\Requests\GetRoleRequest $request |
||
84 | * @param \App\Containers\Authorization\Actions\GetRoleAction $action |
||
85 | * |
||
86 | * @return \Dingo\Api\Http\Response |
||
87 | */ |
||
88 | public function getRole(GetRoleRequest $request, GetRoleAction $action) |
||
94 | |||
95 | /** |
||
96 | * @param \App\Containers\Authorization\UI\API\Requests\AssignUserToRoleRequest $request |
||
97 | * @param \App\Containers\Authorization\Actions\AssignUserToRoleAction $action |
||
98 | * |
||
99 | * @return \Dingo\Api\Http\Response |
||
100 | */ |
||
101 | public function assignUserToRole(AssignUserToRoleRequest $request, AssignUserToRoleAction $action) |
||
107 | |||
108 | /** |
||
109 | * @param \App\Containers\Authorization\UI\API\Requests\DeleteRoleRequest $request |
||
110 | * @param \App\Containers\Authorization\Actions\DeleteRoleAction $action |
||
111 | * |
||
112 | * @return \Dingo\Api\Http\Response |
||
113 | */ |
||
114 | View Code Duplication | public function deleteRole(DeleteRoleRequest $request, DeleteRoleAction $action) |
|
122 | |||
123 | /** |
||
124 | * @param \App\Containers\Authorization\UI\API\Requests\RevokeUserFromRoleRequest $request |
||
125 | * @param \App\Containers\Authorization\Actions\RevokeUserFromRoleAction $action |
||
126 | * |
||
127 | * @return \Dingo\Api\Http\Response |
||
128 | */ |
||
129 | public function revokeRoleFromUser(RevokeUserFromRoleRequest $request, RevokeUserFromRoleAction $action) |
||
135 | |||
136 | /** |
||
137 | * @param \App\Containers\Authorization\UI\API\Requests\AttachPermissionToRoleRequest $request |
||
138 | * @param \App\Containers\Authorization\Actions\AttachPermissionsToRoleAction $action |
||
139 | * |
||
140 | * @return \Dingo\Api\Http\Response |
||
141 | */ |
||
142 | public function attachPermissionToRole( |
||
150 | |||
151 | /** |
||
152 | * @param \App\Containers\Authorization\UI\API\Requests\SyncPermissionOnRoleRequest $request |
||
153 | * @param \App\Containers\Authorization\Actions\SyncPermissionsOnRoleAction $action |
||
154 | * |
||
155 | * @return \Dingo\Api\Http\Response |
||
156 | */ |
||
157 | public function syncPermissionOnRole( |
||
165 | |||
166 | /** |
||
167 | * @param \App\Containers\Authorization\UI\API\Requests\DetachPermissionToRoleRequest $request |
||
168 | * @param \App\Containers\Authorization\Actions\DetachPermissionsFromRoleAction $action |
||
169 | * |
||
170 | * @return \Dingo\Api\Http\Response |
||
171 | */ |
||
172 | public function detachPermissionFromRole( |
||
180 | |||
181 | /** |
||
182 | * @param \App\Containers\Authorization\UI\API\Requests\CreateRoleRequest $request |
||
183 | * @param \App\Containers\Authorization\Actions\CreateRoleAction $action |
||
184 | * |
||
185 | * @return \Dingo\Api\Http\Response |
||
186 | */ |
||
187 | public function createRole(CreateRoleRequest $request, CreateRoleAction $action) |
||
193 | |||
194 | /** |
||
195 | * @param \App\Containers\Authorization\UI\API\Requests\CreatePermissionRequest $request |
||
196 | * @param \App\Containers\Authorization\Actions\CreatePermissionAction $action |
||
197 | * |
||
198 | * @return \Dingo\Api\Http\Response |
||
199 | */ |
||
200 | public function createPermission(CreatePermissionRequest $request, CreatePermissionAction $action) |
||
206 | |||
207 | |||
208 | } |
||
209 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.