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 ProjectNamespaceController extends AbstractApiController |
||
25 | { |
||
26 | use DispatchesJobs; |
||
27 | |||
28 | /** |
||
29 | * Get all teams. |
||
30 | * |
||
31 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
32 | * |
||
33 | * @return \Illuminate\Http\JsonResponse |
||
34 | */ |
||
35 | public function getTeams(Request $request) |
||
41 | |||
42 | /** |
||
43 | * Get a single team. |
||
44 | * |
||
45 | * @param \Gitamin\Models\ProjectNamespace $team |
||
46 | * |
||
47 | * @return \Illuminate\Http\JsonResponse |
||
48 | */ |
||
49 | public function getTeam(ProjectNamespace $team) |
||
53 | |||
54 | /** |
||
55 | * Create a new project team. |
||
56 | * |
||
57 | * @return \Illuminate\Http\JsonResponse |
||
58 | */ |
||
59 | View Code Duplication | public function postTeams() |
|
73 | |||
74 | /** |
||
75 | * Update an existing team. |
||
76 | * |
||
77 | * @param \Gitamin\Models\ProjectNamespace $team |
||
78 | * |
||
79 | * @return \Illuminate\Http\JsonResponse |
||
80 | */ |
||
81 | View Code Duplication | public function putTeam(ProjectNamespace $team) |
|
96 | |||
97 | /** |
||
98 | * Delete an existing team. |
||
99 | * |
||
100 | * @param \Gitamin\Models\ProjectNamespace $team |
||
101 | * |
||
102 | * @return \Illuminate\Http\JsonResponse |
||
103 | */ |
||
104 | public function deleteTeam(ProjectNamespace $team) |
||
110 | } |
||
111 |
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.