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 |
||
43 | abstract class OfferCommandHandler extends Udb3CommandHandler |
||
44 | { |
||
45 | /** |
||
46 | * @var RepositoryInterface |
||
47 | */ |
||
48 | protected $offerRepository; |
||
49 | |||
50 | /** |
||
51 | * @var RepositoryInterface |
||
52 | */ |
||
53 | protected $organizerRepository; |
||
54 | |||
55 | /** |
||
56 | * @var RepositoryInterface |
||
57 | */ |
||
58 | protected $labelRepository; |
||
59 | |||
60 | /** |
||
61 | * @var MediaManagerInterface|MediaManager |
||
62 | */ |
||
63 | protected $mediaManager; |
||
64 | |||
65 | /** |
||
66 | * @param RepositoryInterface $offerRepository |
||
67 | * @param RepositoryInterface $organizerRepository |
||
68 | * @param ReadRepositoryInterface $labelRepository |
||
69 | * @param MediaManagerInterface $mediaManager |
||
70 | */ |
||
71 | public function __construct( |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | View Code Duplication | public function handle($command) |
|
98 | |||
99 | /** |
||
100 | * @return string[] |
||
101 | * An associative array of commands and their handler methods. |
||
102 | */ |
||
103 | View Code Duplication | private function getCommandHandlers() |
|
122 | |||
123 | /** |
||
124 | * @return string |
||
125 | */ |
||
126 | abstract protected function getAddLabelClassName(); |
||
127 | |||
128 | /** |
||
129 | * @return string |
||
130 | */ |
||
131 | abstract protected function getRemoveLabelClassName(); |
||
132 | |||
133 | /** |
||
134 | * @return string |
||
135 | */ |
||
136 | abstract protected function getImportLabelsClassName(); |
||
137 | |||
138 | /** |
||
139 | * @return string |
||
140 | */ |
||
141 | abstract protected function getUpdateTitleClassName(); |
||
142 | |||
143 | /** |
||
144 | * @return string |
||
145 | */ |
||
146 | abstract protected function getAddImageClassName(); |
||
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | abstract protected function getUpdateImageClassName(); |
||
152 | |||
153 | /** |
||
154 | * @return string |
||
155 | */ |
||
156 | abstract protected function getRemoveImageClassName(); |
||
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | abstract protected function getSelectMainImageClassName(); |
||
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | abstract protected function getUpdateDescriptionClassName(); |
||
167 | |||
168 | /** |
||
169 | * @return string |
||
170 | */ |
||
171 | abstract protected function getUpdateCalendarClassName(); |
||
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | abstract protected function getUpdateTypicalAgeRangeClassName(); |
||
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | */ |
||
181 | abstract protected function getDeleteTypicalAgeRangeClassName(); |
||
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | */ |
||
186 | abstract protected function getUpdateOrganizerClassName(); |
||
187 | |||
188 | /** |
||
189 | * @return string |
||
190 | */ |
||
191 | abstract protected function getDeleteOrganizerClassName(); |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | abstract protected function getDeleteCurrentOrganizerClassName(); |
||
197 | |||
198 | /** |
||
199 | * @return string |
||
200 | */ |
||
201 | abstract protected function getUpdateContactPointClassName(); |
||
202 | |||
203 | /** |
||
204 | * @return string |
||
205 | */ |
||
206 | abstract protected function getUpdateBookingInfoClassName(); |
||
207 | |||
208 | /** |
||
209 | * @return string |
||
210 | */ |
||
211 | abstract protected function getUpdatePriceInfoClassName(); |
||
212 | |||
213 | /** |
||
214 | * @return string |
||
215 | */ |
||
216 | abstract protected function getDeleteOfferClassName(); |
||
217 | |||
218 | /** |
||
219 | * @return string |
||
220 | */ |
||
221 | abstract protected function getPublishClassName(); |
||
222 | |||
223 | /** |
||
224 | * @return string |
||
225 | */ |
||
226 | abstract protected function getApproveClassName(); |
||
227 | |||
228 | /** |
||
229 | * @return string |
||
230 | */ |
||
231 | abstract protected function getRejectClassName(); |
||
232 | |||
233 | /** |
||
234 | * @return string |
||
235 | */ |
||
236 | abstract protected function getFlagAsDuplicateClassName(); |
||
237 | |||
238 | /** |
||
239 | * @return string |
||
240 | */ |
||
241 | abstract protected function getFlagAsInappropriateClassName(); |
||
242 | |||
243 | /** |
||
244 | * @return string |
||
245 | */ |
||
246 | abstract protected function getUpdateTypeClassName(); |
||
247 | |||
248 | /** |
||
249 | * @return string |
||
250 | */ |
||
251 | abstract protected function getUpdateThemeClassName(); |
||
252 | |||
253 | /** |
||
254 | * @return string |
||
255 | */ |
||
256 | abstract protected function getUpdateFacilitiesClassName(); |
||
257 | |||
258 | /** |
||
259 | * @param AbstractUpdateType $updateType |
||
260 | */ |
||
261 | public function handleUpdateType(AbstractUpdateType $updateType) |
||
269 | |||
270 | /** |
||
271 | * @param AbstractUpdateTheme $updateTheme |
||
272 | */ |
||
273 | public function handleUpdateTheme(AbstractUpdateTheme $updateTheme) |
||
281 | |||
282 | /** |
||
283 | * @param AbstractUpdateFacilities $updateFacilities |
||
284 | */ |
||
285 | public function handleUpdateFacilities(AbstractUpdateFacilities $updateFacilities) |
||
293 | |||
294 | /** |
||
295 | * @param AbstractAddLabel $addLabel |
||
296 | */ |
||
297 | private function handleAddLabel(AbstractAddLabel $addLabel) |
||
305 | |||
306 | /** |
||
307 | * @param AbstractRemoveLabel $removeLabel |
||
308 | */ |
||
309 | private function handleRemoveLabel(AbstractRemoveLabel $removeLabel) |
||
317 | |||
318 | /** |
||
319 | * @param AbstractImportLabels $importLabels |
||
320 | */ |
||
321 | private function handleImportLabels(AbstractImportLabels $importLabels) |
||
329 | |||
330 | /** |
||
331 | * @param AbstractLabelCommand $labelCommand |
||
332 | * @return Label |
||
333 | */ |
||
334 | View Code Duplication | private function createLabel(AbstractLabelCommand $labelCommand) |
|
344 | |||
345 | /** |
||
346 | * @param AbstractUpdateTitle $translateTitle |
||
347 | */ |
||
348 | private function handleUpdateTitle(AbstractUpdateTitle $translateTitle) |
||
354 | |||
355 | /** |
||
356 | * Handle an add image command. |
||
357 | * @param AbstractAddImage $addImage |
||
358 | */ |
||
359 | public function handleAddImage(AbstractAddImage $addImage) |
||
368 | |||
369 | /** |
||
370 | * @param AbstractRemoveImage $removeImage |
||
371 | */ |
||
372 | public function handleRemoveImage(AbstractRemoveImage $removeImage) |
||
378 | |||
379 | /** |
||
380 | * @param AbstractUpdateImage $updateImage |
||
381 | */ |
||
382 | public function handleUpdateImage(AbstractUpdateImage $updateImage) |
||
388 | |||
389 | /** |
||
390 | * @param AbstractSelectMainImage $selectMainImage |
||
391 | */ |
||
392 | public function handleSelectMainImage(AbstractSelectMainImage $selectMainImage) |
||
398 | |||
399 | /** |
||
400 | * Handle the update of description on a place. |
||
401 | * @param AbstractUpdateDescription $updateDescription |
||
402 | */ |
||
403 | public function handleUpdateDescription(AbstractUpdateDescription $updateDescription) |
||
415 | |||
416 | /** |
||
417 | * @param AbstractUpdateCalendar $updateCalendar |
||
418 | */ |
||
419 | public function handleUpdateCalendar(AbstractUpdateCalendar $updateCalendar) |
||
427 | |||
428 | /** |
||
429 | * Handle the update of typical age range on a place. |
||
430 | * @param AbstractUpdateTypicalAgeRange $updateTypicalAgeRange |
||
431 | */ |
||
432 | public function handleUpdateTypicalAgeRange(AbstractUpdateTypicalAgeRange $updateTypicalAgeRange) |
||
443 | |||
444 | /** |
||
445 | * Handle the deletion of typical age range on a place. |
||
446 | * @param AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange |
||
447 | */ |
||
448 | public function handleDeleteTypicalAgeRange(AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange) |
||
457 | |||
458 | /** |
||
459 | * Handle an update command to update organizer of a place. |
||
460 | * @param AbstractUpdateOrganizer $updateOrganizer |
||
461 | */ |
||
462 | public function handleUpdateOrganizer(AbstractUpdateOrganizer $updateOrganizer) |
||
473 | |||
474 | /** |
||
475 | * Handle an update command to delete the organizer. |
||
476 | * @param AbstractDeleteOrganizer $deleteOrganizer |
||
477 | */ |
||
478 | public function handleDeleteOrganizer(AbstractDeleteOrganizer $deleteOrganizer) |
||
488 | |||
489 | /** |
||
490 | * @param AbstractDeleteCurrentOrganizer $deleteCurrentOrganizer |
||
491 | */ |
||
492 | public function handleDeleteCurrentOrganizer(AbstractDeleteCurrentOrganizer $deleteCurrentOrganizer) |
||
500 | |||
501 | /** |
||
502 | * Handle an update command to updated the contact point. |
||
503 | * @param AbstractUpdateContactPoint $updateContactPoint |
||
504 | */ |
||
505 | public function handleUpdateContactPoint(AbstractUpdateContactPoint $updateContactPoint) |
||
516 | |||
517 | /** |
||
518 | * Handle an update command to updated the booking info. |
||
519 | * @param AbstractUpdateBookingInfo $updateBookingInfo |
||
520 | */ |
||
521 | public function handleUpdateBookingInfo(AbstractUpdateBookingInfo $updateBookingInfo) |
||
531 | |||
532 | /** |
||
533 | * @param AbstractUpdatePriceInfo $updatePriceInfo |
||
534 | */ |
||
535 | private function handleUpdatePriceInfo(AbstractUpdatePriceInfo $updatePriceInfo) |
||
545 | |||
546 | /** |
||
547 | * @param AbstractDeleteOffer $deleteOffer |
||
548 | */ |
||
549 | private function handleDeleteOffer(AbstractDeleteOffer $deleteOffer) |
||
555 | |||
556 | /** |
||
557 | * @param AbstractPublish $publish |
||
558 | */ |
||
559 | private function handlePublish(AbstractPublish $publish) |
||
565 | |||
566 | /** |
||
567 | * @param AbstractApprove $approve |
||
568 | */ |
||
569 | private function handleApprove(AbstractApprove $approve) |
||
575 | |||
576 | /** |
||
577 | * @param AbstractReject $reject |
||
578 | */ |
||
579 | private function handleReject(AbstractReject $reject) |
||
585 | |||
586 | /** |
||
587 | * @param AbstractFlagAsDuplicate $flagAsDuplicate |
||
588 | */ |
||
589 | private function handleFlagAsDuplicate(AbstractFlagAsDuplicate $flagAsDuplicate) |
||
595 | |||
596 | /** |
||
597 | * @param AbstractFlagAsInappropriate $flagAsInappropriate |
||
598 | */ |
||
599 | private function handleFlagAsInappropriate(AbstractFlagAsInappropriate $flagAsInappropriate) |
||
605 | |||
606 | /** |
||
607 | * Makes it easier to type-hint to Offer. |
||
608 | * |
||
609 | * @param string $id |
||
610 | * @return Offer |
||
611 | */ |
||
612 | private function load($id) |
||
616 | |||
617 | /** |
||
618 | * Makes it easier to type-hint to Organizer. |
||
619 | * |
||
620 | * @param string $id |
||
621 | * @return Organizer |
||
622 | */ |
||
623 | private function loadOrganizer($id) |
||
628 | } |
||
629 |
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..