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 |
||
26 | class CommandHandler extends Udb3CommandHandler implements LoggerAwareInterface |
||
27 | { |
||
28 | use LoggerAwareTrait; |
||
29 | |||
30 | /** |
||
31 | * @var RepositoryInterface |
||
32 | */ |
||
33 | protected $placeRepository; |
||
34 | |||
35 | /** |
||
36 | * @param RepositoryInterface $placeRepository |
||
37 | */ |
||
38 | public function __construct( |
||
43 | |||
44 | /** |
||
45 | * Handle the update of description on a place. |
||
46 | */ |
||
47 | public function handleUpdateDescription(UpdateDescription $updateDescription) |
||
60 | |||
61 | /** |
||
62 | * Handle the update of typical age range on a place. |
||
63 | */ |
||
64 | public function handleUpdateTypicalAgeRange(UpdateTypicalAgeRange $updateTypicalAgeRange) |
||
77 | |||
78 | /** |
||
79 | * Handle the deletion of typical age range on a place. |
||
80 | */ |
||
81 | public function handleDeleteTypicalAgeRange(DeleteTypicalAgeRange $deleteTypicalAgeRange) |
||
92 | |||
93 | /** |
||
94 | * Handle an update command to update organizer of a place. |
||
95 | */ |
||
96 | public function handleUpdateOrganizer(UpdateOrganizer $updateOrganizer) |
||
108 | |||
109 | /** |
||
110 | * Handle an update command to delete the organizer. |
||
111 | */ |
||
112 | public function handleDeleteOrganizer(DeleteOrganizer $deleteOrganizer) |
||
125 | |||
126 | /** |
||
127 | * Handle an update command to updated the contact point. |
||
128 | */ |
||
129 | public function handleUpdateContactPoint(UpdateContactPoint $updateContactPoint) |
||
142 | |||
143 | /** |
||
144 | * Handle the update of facilities for a place. |
||
145 | */ |
||
146 | public function handleUpdateFacilities(UpdateFacilities $updateFacilities) |
||
158 | |||
159 | /** |
||
160 | * Handle an update command to updated the booking info. |
||
161 | */ |
||
162 | public function handleUpdateBookingInfo(UpdateBookingInfo $updateBookingInfo) |
||
175 | |||
176 | |||
177 | /** |
||
178 | * Handle an add image command. |
||
179 | * @param AddImage $addImage |
||
180 | */ |
||
181 | public function handleAddImage(AddImage $addImage) |
||
194 | |||
195 | /** |
||
196 | * Handle an update image command. |
||
197 | * @param UpdateImage $updateImage |
||
198 | */ |
||
199 | public function handleUpdateImage(UpdateImage $updateImage) |
||
208 | |||
209 | /** |
||
210 | * Handle a remove image command. |
||
211 | * @param RemoveImage $removeImage |
||
212 | */ |
||
213 | public function handleRemoveImage(RemoveImage $removeImage) |
||
222 | |||
223 | /** |
||
224 | * Handle an update the major info command. |
||
225 | */ |
||
226 | View Code Duplication | public function handleUpdateMajorInfo(UpdateMajorInfo $updateMajorInfo) |
|
243 | |||
244 | /** |
||
245 | * Handle a delete place command. |
||
246 | */ |
||
247 | public function handleDeletePlace(DeletePlace $deletePlace) |
||
257 | } |
||
258 |
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.