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 |
||
36 | abstract class OfferCommandHandler extends Udb3CommandHandler |
||
37 | { |
||
38 | /** |
||
39 | * @var RepositoryInterface |
||
40 | */ |
||
41 | protected $offerRepository; |
||
42 | |||
43 | /** |
||
44 | * @var RepositoryInterface |
||
45 | */ |
||
46 | protected $organizerRepository; |
||
47 | |||
48 | /** |
||
49 | * @var RepositoryInterface |
||
50 | */ |
||
51 | protected $labelRepository; |
||
52 | |||
53 | /** |
||
54 | * @param RepositoryInterface $offerRepository |
||
55 | * @param RepositoryInterface $organizerRepository |
||
56 | * @param ReadRepositoryInterface $labelRepository |
||
57 | */ |
||
58 | public function __construct( |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function handle($command) |
||
83 | |||
84 | /** |
||
85 | * @return string[] |
||
86 | * An associative array of commands and their handler methods. |
||
87 | */ |
||
88 | View Code Duplication | private function getCommandHandlers() |
|
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | abstract protected function getAddLabelClassName(); |
||
112 | |||
113 | /** |
||
114 | * @return string |
||
115 | */ |
||
116 | abstract protected function getRemoveLabelClassName(); |
||
117 | |||
118 | /** |
||
119 | * @return string |
||
120 | */ |
||
121 | abstract protected function getTranslateTitleClassName(); |
||
122 | |||
123 | /** |
||
124 | * @return string |
||
125 | */ |
||
126 | abstract protected function getAddImageClassName(); |
||
127 | |||
128 | /** |
||
129 | * @return string |
||
130 | */ |
||
131 | abstract protected function getUpdateImageClassName(); |
||
132 | |||
133 | /** |
||
134 | * @return string |
||
135 | */ |
||
136 | abstract protected function getRemoveImageClassName(); |
||
137 | |||
138 | /** |
||
139 | * @return string |
||
140 | */ |
||
141 | abstract protected function getSelectMainImageClassName(); |
||
142 | |||
143 | /** |
||
144 | * @return string |
||
145 | */ |
||
146 | abstract protected function getUpdateDescriptionClassName(); |
||
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | abstract protected function getUpdateCalendarClassName(); |
||
152 | |||
153 | /** |
||
154 | * @return string |
||
155 | */ |
||
156 | abstract protected function getUpdateTypicalAgeRangeClassName(); |
||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | abstract protected function getDeleteTypicalAgeRangeClassName(); |
||
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | abstract protected function getUpdateOrganizerClassName(); |
||
167 | |||
168 | /** |
||
169 | * @return string |
||
170 | */ |
||
171 | abstract protected function getDeleteOrganizerClassName(); |
||
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | abstract protected function getUpdateContactPointClassName(); |
||
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | */ |
||
181 | abstract protected function getUpdateBookingInfoClassName(); |
||
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | */ |
||
186 | abstract protected function getUpdatePriceInfoClassName(); |
||
187 | |||
188 | /** |
||
189 | * @return string |
||
190 | */ |
||
191 | abstract protected function getDeleteOfferClassName(); |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | abstract protected function getPublishClassName(); |
||
197 | |||
198 | /** |
||
199 | * @return string |
||
200 | */ |
||
201 | abstract protected function getApproveClassName(); |
||
202 | |||
203 | /** |
||
204 | * @return string |
||
205 | */ |
||
206 | abstract protected function getRejectClassName(); |
||
207 | |||
208 | /** |
||
209 | * @return string |
||
210 | */ |
||
211 | abstract protected function getFlagAsDuplicateClassName(); |
||
212 | |||
213 | /** |
||
214 | * @return string |
||
215 | */ |
||
216 | abstract protected function getFlagAsInappropriateClassName(); |
||
217 | |||
218 | /** |
||
219 | * @param AbstractAddLabel $addLabel |
||
220 | */ |
||
221 | private function handleAddLabel(AbstractAddLabel $addLabel) |
||
229 | |||
230 | /** |
||
231 | * @param AbstractRemoveLabel $removeLabel |
||
232 | */ |
||
233 | private function handleRemoveLabel(AbstractRemoveLabel $removeLabel) |
||
241 | |||
242 | /** |
||
243 | * @param AbstractLabelCommand $labelCommand |
||
244 | * @return Label |
||
245 | */ |
||
246 | View Code Duplication | private function createLabel(AbstractLabelCommand $labelCommand) |
|
256 | |||
257 | /** |
||
258 | * @param AbstractTranslateTitle $translateTitle |
||
259 | */ |
||
260 | private function handleTranslateTitle(AbstractTranslateTitle $translateTitle) |
||
266 | |||
267 | /** |
||
268 | * Handle an add image command. |
||
269 | * @param AbstractAddImage $addImage |
||
270 | */ |
||
271 | public function handleAddImage(AbstractAddImage $addImage) |
||
272 | { |
||
277 | |||
278 | /** |
||
279 | * @param AbstractRemoveImage $removeImage |
||
280 | */ |
||
281 | public function handleRemoveImage(AbstractRemoveImage $removeImage) |
||
287 | |||
288 | /** |
||
289 | * @param AbstractUpdateImage $updateImage |
||
290 | */ |
||
291 | public function handleUpdateImage(AbstractUpdateImage $updateImage) |
||
297 | |||
298 | /** |
||
299 | * @param AbstractSelectMainImage $selectMainImage |
||
300 | */ |
||
301 | public function handleSelectMainImage(AbstractSelectMainImage $selectMainImage) |
||
307 | |||
308 | /** |
||
309 | * Handle the update of description on a place. |
||
310 | * @param AbstractUpdateDescription $updateDescription |
||
311 | */ |
||
312 | public function handleUpdateDescription(AbstractUpdateDescription $updateDescription) |
||
324 | |||
325 | /** |
||
326 | * @param AbstractUpdateCalendar $updateCalendar |
||
327 | */ |
||
328 | public function handleUpdateCalendar(AbstractUpdateCalendar $updateCalendar) |
||
336 | |||
337 | /** |
||
338 | * Handle the update of typical age range on a place. |
||
339 | * @param AbstractUpdateTypicalAgeRange $updateTypicalAgeRange |
||
340 | */ |
||
341 | public function handleUpdateTypicalAgeRange(AbstractUpdateTypicalAgeRange $updateTypicalAgeRange) |
||
352 | |||
353 | /** |
||
354 | * Handle the deletion of typical age range on a place. |
||
355 | * @param AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange |
||
356 | */ |
||
357 | public function handleDeleteTypicalAgeRange(AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange) |
||
366 | |||
367 | /** |
||
368 | * Handle an update command to update organizer of a place. |
||
369 | * @param AbstractUpdateOrganizer $updateOrganizer |
||
370 | */ |
||
371 | public function handleUpdateOrganizer(AbstractUpdateOrganizer $updateOrganizer) |
||
382 | |||
383 | /** |
||
384 | * Handle an update command to delete the organizer. |
||
385 | * @param AbstractDeleteOrganizer $deleteOrganizer |
||
386 | */ |
||
387 | public function handleDeleteOrganizer(AbstractDeleteOrganizer $deleteOrganizer) |
||
397 | |||
398 | /** |
||
399 | * Handle an update command to updated the contact point. |
||
400 | * @param AbstractUpdateContactPoint $updateContactPoint |
||
401 | */ |
||
402 | public function handleUpdateContactPoint(AbstractUpdateContactPoint $updateContactPoint) |
||
413 | |||
414 | /** |
||
415 | * Handle an update command to updated the booking info. |
||
416 | * @param AbstractUpdateBookingInfo $updateBookingInfo |
||
417 | */ |
||
418 | public function handleUpdateBookingInfo(AbstractUpdateBookingInfo $updateBookingInfo) |
||
428 | |||
429 | /** |
||
430 | * @param AbstractUpdatePriceInfo $updatePriceInfo |
||
431 | */ |
||
432 | private function handleUpdatePriceInfo(AbstractUpdatePriceInfo $updatePriceInfo) |
||
442 | |||
443 | /** |
||
444 | * @param AbstractDeleteOffer $deleteOffer |
||
445 | */ |
||
446 | private function handleDeleteOffer(AbstractDeleteOffer $deleteOffer) |
||
452 | |||
453 | /** |
||
454 | * @param AbstractPublish $publish |
||
455 | */ |
||
456 | private function handlePublish(AbstractPublish $publish) |
||
462 | |||
463 | /** |
||
464 | * @param AbstractApprove $approve |
||
465 | */ |
||
466 | private function handleApprove(AbstractApprove $approve) |
||
472 | |||
473 | /** |
||
474 | * @param AbstractReject $reject |
||
475 | */ |
||
476 | private function handleReject(AbstractReject $reject) |
||
482 | |||
483 | /** |
||
484 | * @param AbstractFlagAsDuplicate $flagAsDuplicate |
||
485 | */ |
||
486 | private function handleFlagAsDuplicate(AbstractFlagAsDuplicate $flagAsDuplicate) |
||
492 | |||
493 | /** |
||
494 | * @param AbstractFlagAsInappropriate $flagAsInappropriate |
||
495 | */ |
||
496 | private function handleFlagAsInappropriate(AbstractFlagAsInappropriate $flagAsInappropriate) |
||
502 | |||
503 | /** |
||
504 | * Makes it easier to type-hint to Offer. |
||
505 | * |
||
506 | * @param string $id |
||
507 | * @return Offer |
||
508 | */ |
||
509 | private function load($id) |
||
513 | |||
514 | /** |
||
515 | * Makes it easier to type-hint to Organizer. |
||
516 | * |
||
517 | * @param string $id |
||
518 | * @return Organizer |
||
519 | */ |
||
520 | private function loadOrganizer($id) |
||
525 | } |
||
526 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..