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 |
||
| 33 | class IssueController extends Controller |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * Project issue index page (List project issues). |
||
| 37 | * |
||
| 38 | * @param Project $project |
||
| 39 | * @param Issue $issue |
||
| 40 | * @param CommentForm $form |
||
| 41 | * |
||
| 42 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 43 | */ |
||
| 44 | public function getIndex(Project $project, Issue $issue, CommentForm $form) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Ajax: Assign new user to an issue. |
||
| 69 | * |
||
| 70 | * @param Issue $issue |
||
| 71 | * @param Request $request |
||
| 72 | * |
||
| 73 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 74 | */ |
||
| 75 | public function postAssign(Issue $issue, Request $request) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Ajax: save comment. |
||
| 86 | * |
||
| 87 | * @param Comment $comment |
||
| 88 | * @param Request $request |
||
| 89 | * |
||
| 90 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 91 | */ |
||
| 92 | public function postEditComment(Comment $comment, Request $request) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * To add new comment to an issue. |
||
| 105 | * |
||
| 106 | * @param Project $project |
||
| 107 | * @param Issue $issue |
||
| 108 | * @param Comment $comment |
||
| 109 | * @param FormRequest\Comment $request |
||
| 110 | * |
||
| 111 | * @return \Illuminate\Http\RedirectResponse |
||
| 112 | */ |
||
| 113 | public function postAddComment(Project $project, Issue $issue, Comment $comment, FormRequest\Comment $request) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Ajax: to delete a comment. |
||
| 127 | * |
||
| 128 | * @param Comment $comment |
||
| 129 | * |
||
| 130 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 131 | */ |
||
| 132 | public function getDeleteComment(Comment $comment) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * New issue form. |
||
| 143 | * |
||
| 144 | * @param Project $project |
||
| 145 | * @param IssueForm $form |
||
| 146 | * |
||
| 147 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 148 | */ |
||
| 149 | public function getNew(Project $project, IssueForm $form) |
||
| 157 | |||
| 158 | /** |
||
| 159 | * To create a new issue. |
||
| 160 | * |
||
| 161 | * @param Project $project |
||
| 162 | * @param Issue $issue |
||
| 163 | * @param FormRequest\Issue $request |
||
| 164 | * |
||
| 165 | * @return \Illuminate\Http\RedirectResponse |
||
| 166 | */ |
||
| 167 | public function postNew(Project $project, Issue $issue, FormRequest\Issue $request) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Edit an existing issue form. |
||
| 180 | * |
||
| 181 | * @param Project $project |
||
| 182 | * @param Issue $issue |
||
| 183 | * @param IssueForm $form |
||
| 184 | * |
||
| 185 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 186 | */ |
||
| 187 | public function getEdit(Project $project, Issue $issue, IssueForm $form) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * To update an existing issue details. |
||
| 205 | * |
||
| 206 | * @param Project $project |
||
| 207 | * @param Issue $issue |
||
| 208 | * @param FormRequest\Issue $request |
||
| 209 | * |
||
| 210 | * @return \Illuminate\Http\RedirectResponse |
||
| 211 | */ |
||
| 212 | public function postEdit(Project $project, Issue $issue, FormRequest\Issue $request) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * To close or reopen an issue. |
||
| 233 | * |
||
| 234 | * @param Project $project |
||
| 235 | * @param Issue $issue |
||
| 236 | * @param int $status |
||
| 237 | * |
||
| 238 | * @return \Illuminate\Http\RedirectResponse |
||
| 239 | */ |
||
| 240 | public function getClose(Project $project, Issue $issue, $status = 0) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * To upload an attachment file. |
||
| 257 | * |
||
| 258 | * @param Project $project |
||
| 259 | * @param Attachment $attachment |
||
| 260 | * @param Request $request |
||
| 261 | * |
||
| 262 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 263 | */ |
||
| 264 | public function postUploadAttachment(Project $project, Attachment $attachment, Request $request) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Ajax: to remove an attachment file. |
||
| 298 | * |
||
| 299 | * @param Project $project |
||
| 300 | * @param Attachment $attachment |
||
| 301 | * @param Request $request |
||
| 302 | * |
||
| 303 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 304 | */ |
||
| 305 | public function postRemoveAttachment(Project $project, Attachment $attachment, Request $request) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Delete attachment. |
||
| 314 | * |
||
| 315 | * @param Project $project |
||
| 316 | * @param Issue $issue |
||
| 317 | * @param Attachment $attachment |
||
| 318 | * |
||
| 319 | * @return \Illuminate\Http\RedirectResponse |
||
| 320 | */ |
||
| 321 | View Code Duplication | public function getDeleteAttachment(Project $project, Issue $issue, Attachment $attachment) |
|
| 329 | |||
| 330 | /** |
||
| 331 | * Display an attachment file such as image. |
||
| 332 | * |
||
| 333 | * @param Project $project |
||
| 334 | * @param Issue $issue |
||
| 335 | * @param Attachment $attachment |
||
| 336 | * @param Request $request |
||
| 337 | * |
||
| 338 | * @return Response |
||
| 339 | */ |
||
| 340 | public function getDisplayAttachment(Project $project, Issue $issue, Attachment $attachment, Request $request) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Download an attachment file. |
||
| 376 | * |
||
| 377 | * @param Project $project |
||
| 378 | * @param Issue $issue |
||
| 379 | * @param Attachment $attachment |
||
| 380 | * |
||
| 381 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
||
| 382 | */ |
||
| 383 | public function getDownloadAttachment(Project $project, Issue $issue, Attachment $attachment) |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Ajax: move an issue to another project. |
||
| 395 | * |
||
| 396 | * @param Issue $issue |
||
| 397 | * @param Request $request |
||
| 398 | * |
||
| 399 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 400 | */ |
||
| 401 | public function postChangeProject(Issue $issue, Request $request) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Ajax: change status of an issue. |
||
| 410 | * |
||
| 411 | * @param Issue $issue |
||
| 412 | * @param Request $request |
||
| 413 | * |
||
| 414 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 415 | */ |
||
| 416 | public function postChangeKanbanTag(Issue $issue, Request $request) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Ajax: returns comments for an issue. |
||
| 428 | * |
||
| 429 | * @param Project $project |
||
| 430 | * @param Issue $issue |
||
| 431 | * |
||
| 432 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie |
||
| 433 | */ |
||
| 434 | View Code Duplication | public function getIssueComments(Project $project, Issue $issue) |
|
| 446 | |||
| 447 | /** |
||
| 448 | * Ajax: returns activities for an issue excluding comments. |
||
| 449 | * |
||
| 450 | * @param Project $project |
||
| 451 | * @param Issue $issue |
||
| 452 | * |
||
| 453 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie |
||
| 454 | */ |
||
| 455 | View Code Duplication | public function getIssueActivity(Project $project, Issue $issue) |
|
| 467 | } |
||
| 468 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: