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 |
||
| 25 | class CommentController extends AbstractApiController |
||
| 26 | { |
||
| 27 | use DispatchesJobs; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Get all comments. |
||
| 31 | * |
||
| 32 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
| 33 | * @param \Illuminate\Contracts\Auth\Guard $auth |
||
| 34 | * |
||
| 35 | * @return \Illuminate\Http\JsonResponse |
||
| 36 | */ |
||
| 37 | public function getComments(Request $request, Guard $auth) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Get a single comment. |
||
| 46 | * |
||
| 47 | * @param \Gitamin\Models\Comment $comment |
||
| 48 | * |
||
| 49 | * @return \Illuminate\Http\JsonResponse |
||
| 50 | */ |
||
| 51 | public function getComment(Comment $comment) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Create a new comment. |
||
| 58 | * |
||
| 59 | * @param \Illuminate\Contracts\Auth\Guard $auth |
||
| 60 | * |
||
| 61 | * @return \Illuminate\Http\JsonResponse |
||
| 62 | */ |
||
| 63 | public function postComments(Guard $auth) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Update an existing comment. |
||
| 82 | * |
||
| 83 | * @param \Gitamin\Models\Inicdent $comment |
||
| 84 | * |
||
| 85 | * @return \Illuminate\Http\JsonResponse |
||
| 86 | */ |
||
| 87 | View Code Duplication | public function putComment(Comment $comment) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Delete an existing comment. |
||
| 103 | * |
||
| 104 | * @param \Gitamin\Models\Comment $comment |
||
| 105 | * |
||
| 106 | * @return \Illuminate\Http\JsonResponse |
||
| 107 | */ |
||
| 108 | public function deleteComment(Comment $comment) |
||
| 114 | } |
||
| 115 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.