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 |
||
| 44 | abstract class OfferCommandHandler extends Udb3CommandHandler |
||
| 45 | { |
||
| 46 | /** |
||
| 47 | * @var RepositoryInterface |
||
| 48 | */ |
||
| 49 | protected $offerRepository; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var RepositoryInterface |
||
| 53 | */ |
||
| 54 | protected $organizerRepository; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var RepositoryInterface |
||
| 58 | */ |
||
| 59 | protected $labelRepository; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var MediaManagerInterface|MediaManager |
||
| 63 | */ |
||
| 64 | protected $mediaManager; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param RepositoryInterface $offerRepository |
||
| 68 | * @param RepositoryInterface $organizerRepository |
||
| 69 | * @param ReadRepositoryInterface $labelRepository |
||
| 70 | * @param MediaManagerInterface $mediaManager |
||
| 71 | */ |
||
| 72 | public function __construct( |
||
| 83 | |||
| 84 | /** |
||
| 85 | * {@inheritdoc} |
||
| 86 | */ |
||
| 87 | View Code Duplication | public function handle($command) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * @return string[] |
||
| 102 | * An associative array of commands and their handler methods. |
||
| 103 | */ |
||
| 104 | View Code Duplication | private function getCommandHandlers() |
|
| 123 | |||
| 124 | /** |
||
| 125 | * @return string |
||
| 126 | */ |
||
| 127 | abstract protected function getAddLabelClassName(); |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | abstract protected function getRemoveLabelClassName(); |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return string |
||
| 136 | */ |
||
| 137 | abstract protected function getImportLabelsClassName(); |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | abstract protected function getUpdateTitleClassName(); |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @return string |
||
| 146 | */ |
||
| 147 | abstract protected function getAddImageClassName(); |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @return string |
||
| 151 | */ |
||
| 152 | abstract protected function getUpdateImageClassName(); |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | abstract protected function getRemoveImageClassName(); |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @return string |
||
| 161 | */ |
||
| 162 | abstract protected function getSelectMainImageClassName(); |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | abstract protected function getImportImagesClassName(); |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @return string |
||
| 171 | */ |
||
| 172 | abstract protected function getUpdateDescriptionClassName(); |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | abstract protected function getUpdateCalendarClassName(); |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | abstract protected function getUpdateTypicalAgeRangeClassName(); |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | abstract protected function getDeleteTypicalAgeRangeClassName(); |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @return string |
||
| 191 | */ |
||
| 192 | abstract protected function getUpdateOrganizerClassName(); |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @return string |
||
| 196 | */ |
||
| 197 | abstract protected function getDeleteOrganizerClassName(); |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | abstract protected function getDeleteCurrentOrganizerClassName(); |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return string |
||
| 206 | */ |
||
| 207 | abstract protected function getUpdateContactPointClassName(); |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @return string |
||
| 211 | */ |
||
| 212 | abstract protected function getUpdateBookingInfoClassName(); |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @return string |
||
| 216 | */ |
||
| 217 | abstract protected function getUpdatePriceInfoClassName(); |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | abstract protected function getDeleteOfferClassName(); |
||
| 223 | |||
| 224 | /** |
||
| 225 | * @return string |
||
| 226 | */ |
||
| 227 | abstract protected function getPublishClassName(); |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return string |
||
| 231 | */ |
||
| 232 | abstract protected function getApproveClassName(); |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return string |
||
| 236 | */ |
||
| 237 | abstract protected function getRejectClassName(); |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | abstract protected function getFlagAsDuplicateClassName(); |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @return string |
||
| 246 | */ |
||
| 247 | abstract protected function getFlagAsInappropriateClassName(); |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @return string |
||
| 251 | */ |
||
| 252 | abstract protected function getUpdateTypeClassName(); |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @return string |
||
| 256 | */ |
||
| 257 | abstract protected function getUpdateThemeClassName(); |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @return string |
||
| 261 | */ |
||
| 262 | abstract protected function getUpdateFacilitiesClassName(); |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @param AbstractUpdateType $updateType |
||
| 266 | */ |
||
| 267 | public function handleUpdateType(AbstractUpdateType $updateType) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @param AbstractUpdateTheme $updateTheme |
||
| 278 | */ |
||
| 279 | public function handleUpdateTheme(AbstractUpdateTheme $updateTheme) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param AbstractUpdateFacilities $updateFacilities |
||
| 290 | */ |
||
| 291 | public function handleUpdateFacilities(AbstractUpdateFacilities $updateFacilities) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param AbstractAddLabel $addLabel |
||
| 302 | */ |
||
| 303 | private function handleAddLabel(AbstractAddLabel $addLabel) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @param AbstractRemoveLabel $removeLabel |
||
| 314 | */ |
||
| 315 | private function handleRemoveLabel(AbstractRemoveLabel $removeLabel) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @param AbstractImportLabels $importLabels |
||
| 326 | */ |
||
| 327 | private function handleImportLabels(AbstractImportLabels $importLabels) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @param AbstractLabelCommand $labelCommand |
||
| 338 | * @return Label |
||
| 339 | */ |
||
| 340 | View Code Duplication | private function createLabel(AbstractLabelCommand $labelCommand) |
|
| 350 | |||
| 351 | /** |
||
| 352 | * @param AbstractUpdateTitle $translateTitle |
||
| 353 | */ |
||
| 354 | private function handleUpdateTitle(AbstractUpdateTitle $translateTitle) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Handle an add image command. |
||
| 363 | * @param AbstractAddImage $addImage |
||
| 364 | */ |
||
| 365 | public function handleAddImage(AbstractAddImage $addImage) |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @param AbstractRemoveImage $removeImage |
||
| 377 | */ |
||
| 378 | public function handleRemoveImage(AbstractRemoveImage $removeImage) |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @param AbstractUpdateImage $updateImage |
||
| 387 | */ |
||
| 388 | public function handleUpdateImage(AbstractUpdateImage $updateImage) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @param AbstractSelectMainImage $selectMainImage |
||
| 397 | */ |
||
| 398 | public function handleSelectMainImage(AbstractSelectMainImage $selectMainImage) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @param AbstractImportImages $importImages |
||
| 407 | */ |
||
| 408 | public function handleImportImages(AbstractImportImages $importImages) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Handle the update of description on a place. |
||
| 417 | * @param AbstractUpdateDescription $updateDescription |
||
| 418 | */ |
||
| 419 | public function handleUpdateDescription(AbstractUpdateDescription $updateDescription) |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @param AbstractUpdateCalendar $updateCalendar |
||
| 434 | */ |
||
| 435 | public function handleUpdateCalendar(AbstractUpdateCalendar $updateCalendar) |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Handle the update of typical age range on a place. |
||
| 446 | * @param AbstractUpdateTypicalAgeRange $updateTypicalAgeRange |
||
| 447 | */ |
||
| 448 | public function handleUpdateTypicalAgeRange(AbstractUpdateTypicalAgeRange $updateTypicalAgeRange) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Handle the deletion of typical age range on a place. |
||
| 462 | * @param AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange |
||
| 463 | */ |
||
| 464 | public function handleDeleteTypicalAgeRange(AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Handle an update command to update organizer of a place. |
||
| 476 | * @param AbstractUpdateOrganizer $updateOrganizer |
||
| 477 | */ |
||
| 478 | public function handleUpdateOrganizer(AbstractUpdateOrganizer $updateOrganizer) |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Handle an update command to delete the organizer. |
||
| 492 | * @param AbstractDeleteOrganizer $deleteOrganizer |
||
| 493 | */ |
||
| 494 | public function handleDeleteOrganizer(AbstractDeleteOrganizer $deleteOrganizer) |
||
| 504 | |||
| 505 | /** |
||
| 506 | * @param AbstractDeleteCurrentOrganizer $deleteCurrentOrganizer |
||
| 507 | */ |
||
| 508 | public function handleDeleteCurrentOrganizer(AbstractDeleteCurrentOrganizer $deleteCurrentOrganizer) |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Handle an update command to updated the contact point. |
||
| 519 | * @param AbstractUpdateContactPoint $updateContactPoint |
||
| 520 | */ |
||
| 521 | public function handleUpdateContactPoint(AbstractUpdateContactPoint $updateContactPoint) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Handle an update command to updated the booking info. |
||
| 535 | * @param AbstractUpdateBookingInfo $updateBookingInfo |
||
| 536 | */ |
||
| 537 | public function handleUpdateBookingInfo(AbstractUpdateBookingInfo $updateBookingInfo) |
||
| 547 | |||
| 548 | /** |
||
| 549 | * @param AbstractUpdatePriceInfo $updatePriceInfo |
||
| 550 | */ |
||
| 551 | private function handleUpdatePriceInfo(AbstractUpdatePriceInfo $updatePriceInfo) |
||
| 561 | |||
| 562 | /** |
||
| 563 | * @param AbstractDeleteOffer $deleteOffer |
||
| 564 | */ |
||
| 565 | private function handleDeleteOffer(AbstractDeleteOffer $deleteOffer) |
||
| 571 | |||
| 572 | /** |
||
| 573 | * @param AbstractPublish $publish |
||
| 574 | */ |
||
| 575 | private function handlePublish(AbstractPublish $publish) |
||
| 581 | |||
| 582 | /** |
||
| 583 | * @param AbstractApprove $approve |
||
| 584 | */ |
||
| 585 | private function handleApprove(AbstractApprove $approve) |
||
| 591 | |||
| 592 | /** |
||
| 593 | * @param AbstractReject $reject |
||
| 594 | */ |
||
| 595 | private function handleReject(AbstractReject $reject) |
||
| 601 | |||
| 602 | /** |
||
| 603 | * @param AbstractFlagAsDuplicate $flagAsDuplicate |
||
| 604 | */ |
||
| 605 | private function handleFlagAsDuplicate(AbstractFlagAsDuplicate $flagAsDuplicate) |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @param AbstractFlagAsInappropriate $flagAsInappropriate |
||
| 614 | */ |
||
| 615 | private function handleFlagAsInappropriate(AbstractFlagAsInappropriate $flagAsInappropriate) |
||
| 621 | |||
| 622 | /** |
||
| 623 | * Makes it easier to type-hint to Offer. |
||
| 624 | * |
||
| 625 | * @param string $id |
||
| 626 | * @return Offer |
||
| 627 | */ |
||
| 628 | private function load($id) |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Makes it easier to type-hint to Organizer. |
||
| 635 | * |
||
| 636 | * @param string $id |
||
| 637 | * @return Organizer |
||
| 638 | */ |
||
| 639 | private function loadOrganizer($id) |
||
| 644 | } |
||
| 645 |
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..