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 getDeleteLabelClassName(); | ||
| 116 | |||
| 117 | /** | ||
| 118 | * @return string | ||
| 119 | */ | ||
| 120 | abstract protected function getTranslateTitleClassName(); | ||
| 121 | |||
| 122 | /** | ||
| 123 | * @return string | ||
| 124 | */ | ||
| 125 | abstract protected function getTranslateDescriptionClassName(); | ||
| 126 | |||
| 127 | /** | ||
| 128 | * @return string | ||
| 129 | */ | ||
| 130 | abstract protected function getAddImageClassName(); | ||
| 131 | |||
| 132 | /** | ||
| 133 | * @return string | ||
| 134 | */ | ||
| 135 | abstract protected function getUpdateImageClassName(); | ||
| 136 | |||
| 137 | /** | ||
| 138 | * @return string | ||
| 139 | */ | ||
| 140 | abstract protected function getRemoveImageClassName(); | ||
| 141 | |||
| 142 | /** | ||
| 143 | * @return string | ||
| 144 | */ | ||
| 145 | abstract protected function getSelectMainImageClassName(); | ||
| 146 | |||
| 147 | /** | ||
| 148 | * @return string | ||
| 149 | */ | ||
| 150 | abstract protected function getUpdateDescriptionClassName(); | ||
| 151 | |||
| 152 | /** | ||
| 153 | * @return string | ||
| 154 | */ | ||
| 155 | abstract protected function getUpdateTypicalAgeRangeClassName(); | ||
| 156 | |||
| 157 | /** | ||
| 158 | * @return string | ||
| 159 | */ | ||
| 160 | abstract protected function getDeleteTypicalAgeRangeClassName(); | ||
| 161 | |||
| 162 | /** | ||
| 163 | * @return string | ||
| 164 | */ | ||
| 165 | abstract protected function getUpdateOrganizerClassName(); | ||
| 166 | |||
| 167 | /** | ||
| 168 | * @return string | ||
| 169 | */ | ||
| 170 | abstract protected function getDeleteOrganizerClassName(); | ||
| 171 | |||
| 172 | /** | ||
| 173 | * @return string | ||
| 174 | */ | ||
| 175 | abstract protected function getUpdateContactPointClassName(); | ||
| 176 | |||
| 177 | /** | ||
| 178 | * @return string | ||
| 179 | */ | ||
| 180 | abstract protected function getUpdateBookingInfoClassName(); | ||
| 181 | |||
| 182 | /** | ||
| 183 | * @return string | ||
| 184 | */ | ||
| 185 | abstract protected function getUpdatePriceInfoClassName(); | ||
| 186 | |||
| 187 | /** | ||
| 188 | * @return string | ||
| 189 | */ | ||
| 190 | abstract protected function getDeleteOfferClassName(); | ||
| 191 | |||
| 192 | /** | ||
| 193 | * @return string | ||
| 194 | */ | ||
| 195 | abstract protected function getPublishClassName(); | ||
| 196 | |||
| 197 | /** | ||
| 198 | * @return string | ||
| 199 | */ | ||
| 200 | abstract protected function getApproveClassName(); | ||
| 201 | |||
| 202 | /** | ||
| 203 | * @return string | ||
| 204 | */ | ||
| 205 | abstract protected function getRejectClassName(); | ||
| 206 | |||
| 207 | /** | ||
| 208 | * @return string | ||
| 209 | */ | ||
| 210 | abstract protected function getFlagAsDuplicateClassName(); | ||
| 211 | |||
| 212 | /** | ||
| 213 | * @return string | ||
| 214 | */ | ||
| 215 | abstract protected function getFlagAsInappropriateClassName(); | ||
| 216 | |||
| 217 | /** | ||
| 218 | * @param AbstractAddLabel $addLabel | ||
| 219 | */ | ||
| 220 | private function handleAddLabel(AbstractAddLabel $addLabel) | ||
| 234 | |||
| 235 | /** | ||
| 236 | * @param AbstractDeleteLabel $deleteLabel | ||
| 237 | */ | ||
| 238 | private function handleDeleteLabel(AbstractDeleteLabel $deleteLabel) | ||
| 244 | |||
| 245 | /** | ||
| 246 | * @param AbstractTranslateTitle $translateTitle | ||
| 247 | */ | ||
| 248 | private function handleTranslateTitle(AbstractTranslateTitle $translateTitle) | ||
| 254 | |||
| 255 | /** | ||
| 256 | * @param AbstractTranslateDescription $translateDescription | ||
| 257 | */ | ||
| 258 | private function handleTranslateDescription(AbstractTranslateDescription $translateDescription) | ||
| 264 | |||
| 265 | /** | ||
| 266 | * Handle an add image command. | ||
| 267 | * @param AbstractAddImage $addImage | ||
| 268 | */ | ||
| 269 | public function handleAddImage(AbstractAddImage $addImage) | ||
| 275 | |||
| 276 | /** | ||
| 277 | * @param AbstractRemoveImage $removeImage | ||
| 278 | */ | ||
| 279 | public function handleRemoveImage(AbstractRemoveImage $removeImage) | ||
| 285 | |||
| 286 | /** | ||
| 287 | * @param AbstractUpdateImage $updateImage | ||
| 288 | */ | ||
| 289 | public function handleUpdateImage(AbstractUpdateImage $updateImage) | ||
| 295 | |||
| 296 | /** | ||
| 297 | * @param AbstractSelectMainImage $selectMainImage | ||
| 298 | */ | ||
| 299 | public function handleSelectMainImage(AbstractSelectMainImage $selectMainImage) | ||
| 305 | |||
| 306 | /** | ||
| 307 | * Handle the update of description on a place. | ||
| 308 | * @param AbstractUpdateDescription $updateDescription | ||
| 309 | */ | ||
| 310 | public function handleUpdateDescription(AbstractUpdateDescription $updateDescription) | ||
| 321 | |||
| 322 | /** | ||
| 323 | * Handle the update of typical age range on a place. | ||
| 324 | * @param AbstractUpdateTypicalAgeRange $updateTypicalAgeRange | ||
| 325 | */ | ||
| 326 | public function handleUpdateTypicalAgeRange(AbstractUpdateTypicalAgeRange $updateTypicalAgeRange) | ||
| 337 | |||
| 338 | /** | ||
| 339 | * Handle the deletion of typical age range on a place. | ||
| 340 | * @param AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange | ||
| 341 | */ | ||
| 342 | public function handleDeleteTypicalAgeRange(AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange) | ||
| 351 | |||
| 352 | /** | ||
| 353 | * Handle an update command to update organizer of a place. | ||
| 354 | * @param AbstractUpdateOrganizer $updateOrganizer | ||
| 355 | */ | ||
| 356 | public function handleUpdateOrganizer(AbstractUpdateOrganizer $updateOrganizer) | ||
| 367 | |||
| 368 | /** | ||
| 369 | * Handle an update command to delete the organizer. | ||
| 370 | * @param AbstractDeleteOrganizer $deleteOrganizer | ||
| 371 | */ | ||
| 372 | public function handleDeleteOrganizer(AbstractDeleteOrganizer $deleteOrganizer) | ||
| 382 | |||
| 383 | /** | ||
| 384 | * Handle an update command to updated the contact point. | ||
| 385 | * @param AbstractUpdateContactPoint $updateContactPoint | ||
| 386 | */ | ||
| 387 | public function handleUpdateContactPoint(AbstractUpdateContactPoint $updateContactPoint) | ||
| 398 | |||
| 399 | /** | ||
| 400 | * Handle an update command to updated the booking info. | ||
| 401 | * @param AbstractUpdateBookingInfo $updateBookingInfo | ||
| 402 | */ | ||
| 403 | public function handleUpdateBookingInfo(AbstractUpdateBookingInfo $updateBookingInfo) | ||
| 413 | |||
| 414 | /** | ||
| 415 | * @param AbstractUpdatePriceInfo $updatePriceInfo | ||
| 416 | */ | ||
| 417 | private function handleUpdatePriceInfo(AbstractUpdatePriceInfo $updatePriceInfo) | ||
| 427 | |||
| 428 | /** | ||
| 429 | * @param AbstractDeleteOffer $deleteOffer | ||
| 430 | */ | ||
| 431 | private function handleDeleteOffer(AbstractDeleteOffer $deleteOffer) | ||
| 437 | |||
| 438 | /** | ||
| 439 | * @param AbstractPublish $publish | ||
| 440 | */ | ||
| 441 | private function handlePublish(AbstractPublish $publish) | ||
| 447 | |||
| 448 | /** | ||
| 449 | * @param AbstractApprove $approve | ||
| 450 | */ | ||
| 451 | private function handleApprove(AbstractApprove $approve) | ||
| 457 | |||
| 458 | /** | ||
| 459 | * @param AbstractReject $reject | ||
| 460 | */ | ||
| 461 | private function handleReject(AbstractReject $reject) | ||
| 467 | |||
| 468 | /** | ||
| 469 | * @param AbstractFlagAsDuplicate $flagAsDuplicate | ||
| 470 | */ | ||
| 471 | private function handleFlagAsDuplicate(AbstractFlagAsDuplicate $flagAsDuplicate) | ||
| 477 | |||
| 478 | /** | ||
| 479 | * @param AbstractFlagAsInappropriate $flagAsInappropriate | ||
| 480 | */ | ||
| 481 | private function handleFlagAsInappropriate(AbstractFlagAsInappropriate $flagAsInappropriate) | ||
| 487 | |||
| 488 | /** | ||
| 489 | * Makes it easier to type-hint to Offer. | ||
| 490 | * | ||
| 491 | * @param string $id | ||
| 492 | * @return Offer | ||
| 493 | */ | ||
| 494 | private function load($id) | ||
| 498 | |||
| 499 | /** | ||
| 500 | * Makes it easier to type-hint to Organizer. | ||
| 501 | * | ||
| 502 | * @param string $id | ||
| 503 | * @return Organizer | ||
| 504 | */ | ||
| 505 | private function loadOrganizer($id) | ||
| 510 | } | ||
| 511 | 
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..