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 |
||
35 | abstract class OfferCommandHandler extends Udb3CommandHandler |
||
36 | { |
||
37 | /** |
||
38 | * @var RepositoryInterface |
||
39 | */ |
||
40 | protected $offerRepository; |
||
41 | |||
42 | /** |
||
43 | * @var RepositoryInterface |
||
44 | */ |
||
45 | protected $organizerRepository; |
||
46 | |||
47 | /** |
||
48 | * @var RepositoryInterface |
||
49 | */ |
||
50 | protected $labelRepository; |
||
51 | |||
52 | /** |
||
53 | * @param RepositoryInterface $offerRepository |
||
54 | * @param RepositoryInterface $organizerRepository |
||
55 | * @param ReadRepositoryInterface $labelRepository |
||
56 | */ |
||
57 | public function __construct( |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | public function handle($command) |
||
82 | |||
83 | /** |
||
84 | * @return string[] |
||
85 | * An associative array of commands and their handler methods. |
||
86 | */ |
||
87 | View Code Duplication | private function getCommandHandlers() |
|
106 | |||
107 | /** |
||
108 | * @return string |
||
109 | */ |
||
110 | abstract protected function getAddLabelClassName(); |
||
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | abstract protected function getRemoveLabelClassName(); |
||
116 | |||
117 | /** |
||
118 | * @return string |
||
119 | */ |
||
120 | abstract protected function getUpdateTitleClassName(); |
||
121 | |||
122 | /** |
||
123 | * @return string |
||
124 | */ |
||
125 | abstract protected function getAddImageClassName(); |
||
126 | |||
127 | /** |
||
128 | * @return string |
||
129 | */ |
||
130 | abstract protected function getUpdateImageClassName(); |
||
131 | |||
132 | /** |
||
133 | * @return string |
||
134 | */ |
||
135 | abstract protected function getRemoveImageClassName(); |
||
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | abstract protected function getSelectMainImageClassName(); |
||
141 | |||
142 | /** |
||
143 | * @return string |
||
144 | */ |
||
145 | abstract protected function getUpdateDescriptionClassName(); |
||
146 | |||
147 | /** |
||
148 | * @return string |
||
149 | */ |
||
150 | abstract protected function getUpdateTypicalAgeRangeClassName(); |
||
151 | |||
152 | /** |
||
153 | * @return string |
||
154 | */ |
||
155 | abstract protected function getDeleteTypicalAgeRangeClassName(); |
||
156 | |||
157 | /** |
||
158 | * @return string |
||
159 | */ |
||
160 | abstract protected function getUpdateOrganizerClassName(); |
||
161 | |||
162 | /** |
||
163 | * @return string |
||
164 | */ |
||
165 | abstract protected function getDeleteOrganizerClassName(); |
||
166 | |||
167 | /** |
||
168 | * @return string |
||
169 | */ |
||
170 | abstract protected function getUpdateContactPointClassName(); |
||
171 | |||
172 | /** |
||
173 | * @return string |
||
174 | */ |
||
175 | abstract protected function getUpdateBookingInfoClassName(); |
||
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | abstract protected function getUpdatePriceInfoClassName(); |
||
181 | |||
182 | /** |
||
183 | * @return string |
||
184 | */ |
||
185 | abstract protected function getDeleteOfferClassName(); |
||
186 | |||
187 | /** |
||
188 | * @return string |
||
189 | */ |
||
190 | abstract protected function getPublishClassName(); |
||
191 | |||
192 | /** |
||
193 | * @return string |
||
194 | */ |
||
195 | abstract protected function getApproveClassName(); |
||
196 | |||
197 | /** |
||
198 | * @return string |
||
199 | */ |
||
200 | abstract protected function getRejectClassName(); |
||
201 | |||
202 | /** |
||
203 | * @return string |
||
204 | */ |
||
205 | abstract protected function getFlagAsDuplicateClassName(); |
||
206 | |||
207 | /** |
||
208 | * @return string |
||
209 | */ |
||
210 | abstract protected function getFlagAsInappropriateClassName(); |
||
211 | |||
212 | /** |
||
213 | * @param AbstractAddLabel $addLabel |
||
214 | */ |
||
215 | private function handleAddLabel(AbstractAddLabel $addLabel) |
||
223 | |||
224 | /** |
||
225 | * @param AbstractRemoveLabel $removeLabel |
||
226 | */ |
||
227 | private function handleRemoveLabel(AbstractRemoveLabel $removeLabel) |
||
235 | |||
236 | /** |
||
237 | * @param AbstractLabelCommand $labelCommand |
||
238 | * @return Label |
||
239 | */ |
||
240 | View Code Duplication | private function createLabel(AbstractLabelCommand $labelCommand) |
|
250 | |||
251 | /** |
||
252 | * @param AbstractUpdateTitle $translateTitle |
||
253 | */ |
||
254 | private function handleUpdateTitle(AbstractUpdateTitle $translateTitle) |
||
255 | { |
||
256 | $offer = $this->load($translateTitle->getItemId()); |
||
257 | $offer->updateTitle($translateTitle->getLanguage(), $translateTitle->getTitle()); |
||
258 | $this->offerRepository->save($offer); |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Handle an add image command. |
||
263 | * @param AbstractAddImage $addImage |
||
264 | */ |
||
265 | public function handleAddImage(AbstractAddImage $addImage) |
||
271 | |||
272 | /** |
||
273 | * @param AbstractRemoveImage $removeImage |
||
274 | */ |
||
275 | public function handleRemoveImage(AbstractRemoveImage $removeImage) |
||
281 | |||
282 | /** |
||
283 | * @param AbstractUpdateImage $updateImage |
||
284 | */ |
||
285 | public function handleUpdateImage(AbstractUpdateImage $updateImage) |
||
291 | |||
292 | /** |
||
293 | * @param AbstractSelectMainImage $selectMainImage |
||
294 | */ |
||
295 | public function handleSelectMainImage(AbstractSelectMainImage $selectMainImage) |
||
301 | |||
302 | /** |
||
303 | * Handle the update of description on a place. |
||
304 | * @param AbstractUpdateDescription $updateDescription |
||
305 | */ |
||
306 | public function handleUpdateDescription(AbstractUpdateDescription $updateDescription) |
||
318 | |||
319 | /** |
||
320 | * Handle the update of typical age range on a place. |
||
321 | * @param AbstractUpdateTypicalAgeRange $updateTypicalAgeRange |
||
322 | */ |
||
323 | public function handleUpdateTypicalAgeRange(AbstractUpdateTypicalAgeRange $updateTypicalAgeRange) |
||
334 | |||
335 | /** |
||
336 | * Handle the deletion of typical age range on a place. |
||
337 | * @param AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange |
||
338 | */ |
||
339 | public function handleDeleteTypicalAgeRange(AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange) |
||
348 | |||
349 | /** |
||
350 | * Handle an update command to update organizer of a place. |
||
351 | * @param AbstractUpdateOrganizer $updateOrganizer |
||
352 | */ |
||
353 | public function handleUpdateOrganizer(AbstractUpdateOrganizer $updateOrganizer) |
||
364 | |||
365 | /** |
||
366 | * Handle an update command to delete the organizer. |
||
367 | * @param AbstractDeleteOrganizer $deleteOrganizer |
||
368 | */ |
||
369 | public function handleDeleteOrganizer(AbstractDeleteOrganizer $deleteOrganizer) |
||
379 | |||
380 | /** |
||
381 | * Handle an update command to updated the contact point. |
||
382 | * @param AbstractUpdateContactPoint $updateContactPoint |
||
383 | */ |
||
384 | public function handleUpdateContactPoint(AbstractUpdateContactPoint $updateContactPoint) |
||
395 | |||
396 | /** |
||
397 | * Handle an update command to updated the booking info. |
||
398 | * @param AbstractUpdateBookingInfo $updateBookingInfo |
||
399 | */ |
||
400 | public function handleUpdateBookingInfo(AbstractUpdateBookingInfo $updateBookingInfo) |
||
410 | |||
411 | /** |
||
412 | * @param AbstractUpdatePriceInfo $updatePriceInfo |
||
413 | */ |
||
414 | private function handleUpdatePriceInfo(AbstractUpdatePriceInfo $updatePriceInfo) |
||
424 | |||
425 | /** |
||
426 | * @param AbstractDeleteOffer $deleteOffer |
||
427 | */ |
||
428 | private function handleDeleteOffer(AbstractDeleteOffer $deleteOffer) |
||
434 | |||
435 | /** |
||
436 | * @param AbstractPublish $publish |
||
437 | */ |
||
438 | private function handlePublish(AbstractPublish $publish) |
||
444 | |||
445 | /** |
||
446 | * @param AbstractApprove $approve |
||
447 | */ |
||
448 | private function handleApprove(AbstractApprove $approve) |
||
454 | |||
455 | /** |
||
456 | * @param AbstractReject $reject |
||
457 | */ |
||
458 | private function handleReject(AbstractReject $reject) |
||
464 | |||
465 | /** |
||
466 | * @param AbstractFlagAsDuplicate $flagAsDuplicate |
||
467 | */ |
||
468 | private function handleFlagAsDuplicate(AbstractFlagAsDuplicate $flagAsDuplicate) |
||
474 | |||
475 | /** |
||
476 | * @param AbstractFlagAsInappropriate $flagAsInappropriate |
||
477 | */ |
||
478 | private function handleFlagAsInappropriate(AbstractFlagAsInappropriate $flagAsInappropriate) |
||
484 | |||
485 | /** |
||
486 | * Makes it easier to type-hint to Offer. |
||
487 | * |
||
488 | * @param string $id |
||
489 | * @return Offer |
||
490 | */ |
||
491 | private function load($id) |
||
495 | |||
496 | /** |
||
497 | * Makes it easier to type-hint to Organizer. |
||
498 | * |
||
499 | * @param string $id |
||
500 | * @return Organizer |
||
501 | */ |
||
502 | private function loadOrganizer($id) |
||
507 | } |
||
508 |
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..