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 OwnerController extends AbstractApiController |
||
25 | { |
||
26 | use DispatchesJobs; |
||
27 | |||
28 | /** |
||
29 | * Get all owners. |
||
30 | * |
||
31 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
32 | * |
||
33 | * @return \Illuminate\Http\JsonResponse |
||
34 | */ |
||
35 | public function getOwners(Request $request) |
||
41 | |||
42 | /** |
||
43 | * Get a single owner. |
||
44 | * |
||
45 | * @param \Gitamin\Models\Owner $owner |
||
46 | * |
||
47 | * @return \Illuminate\Http\JsonResponse |
||
48 | */ |
||
49 | public function getOwner(Owner $owner) |
||
53 | |||
54 | /** |
||
55 | * Create a new project team. |
||
56 | * |
||
57 | * @return \Illuminate\Http\JsonResponse |
||
58 | */ |
||
59 | View Code Duplication | public function postOwners() |
|
75 | |||
76 | /** |
||
77 | * Update an existing owner. |
||
78 | * |
||
79 | * @param \Gitamin\Models\Owner $owner |
||
80 | * |
||
81 | * @return \Illuminate\Http\JsonResponse |
||
82 | */ |
||
83 | View Code Duplication | public function putOwner(Owner $owner) |
|
100 | |||
101 | /** |
||
102 | * Delete an existing owner. |
||
103 | * |
||
104 | * @param \Gitamin\Models\Owner $owner |
||
105 | * |
||
106 | * @return \Illuminate\Http\JsonResponse |
||
107 | */ |
||
108 | public function deleteOwner(Owner $owner) |
||
114 | } |
||
115 |
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.