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 |
||
| 24 | class IssueController extends AbstractApiController |
||
| 25 | { |
||
| 26 | use DispatchesJobs; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Get all issues. |
||
| 30 | * |
||
| 31 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
| 32 | * @param \Illuminate\Contracts\Auth\Guard $auth |
||
| 33 | * |
||
| 34 | * @return \Illuminate\Http\JsonResponse |
||
| 35 | */ |
||
| 36 | public function getIssues(Request $request, Guard $auth) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get a single issue. |
||
| 48 | * |
||
| 49 | * @param \Gitamin\Models\Issue $issue |
||
| 50 | * |
||
| 51 | * @return \Illuminate\Http\JsonResponse |
||
| 52 | */ |
||
| 53 | public function getIssue(Issue $issue) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Create a new issue. |
||
| 60 | * |
||
| 61 | * @param \Illuminate\Contracts\Auth\Guard $auth |
||
| 62 | * |
||
| 63 | * @return \Illuminate\Http\JsonResponse |
||
| 64 | */ |
||
| 65 | public function postIssues(Request $request, Guard $auth) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Update an existing issue. |
||
| 83 | * |
||
| 84 | * @param \Gitamin\Models\Inicdent $issue |
||
| 85 | * |
||
| 86 | * @return \Illuminate\Http\JsonResponse |
||
| 87 | */ |
||
| 88 | View Code Duplication | public function putIssue(Request $request, Issue $issue) |
|
| 104 | |||
| 105 | /** |
||
| 106 | * Delete an existing issue. |
||
| 107 | * |
||
| 108 | * @param \Gitamin\Models\Issue $issue |
||
| 109 | * |
||
| 110 | * @return \Illuminate\Http\JsonResponse |
||
| 111 | */ |
||
| 112 | public function deleteIssue(Issue $issue) |
||
| 118 | } |
||
| 119 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.