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 |
||
| 42 | abstract class OfferCommandHandler extends Udb3CommandHandler |
||
| 43 | { |
||
| 44 | /** |
||
| 45 | * @var RepositoryInterface |
||
| 46 | */ |
||
| 47 | protected $offerRepository; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var RepositoryInterface |
||
| 51 | */ |
||
| 52 | protected $organizerRepository; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var RepositoryInterface |
||
| 56 | */ |
||
| 57 | protected $labelRepository; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var MediaManagerInterface|MediaManager |
||
| 61 | */ |
||
| 62 | protected $mediaManager; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param RepositoryInterface $offerRepository |
||
| 66 | * @param RepositoryInterface $organizerRepository |
||
| 67 | * @param ReadRepositoryInterface $labelRepository |
||
| 68 | * @param MediaManagerInterface $mediaManager |
||
| 69 | */ |
||
| 70 | public function __construct( |
||
| 81 | |||
| 82 | /** |
||
| 83 | * {@inheritdoc} |
||
| 84 | */ |
||
| 85 | View Code Duplication | public function handle($command) |
|
| 97 | |||
| 98 | /** |
||
| 99 | * @return string[] |
||
| 100 | * An associative array of commands and their handler methods. |
||
| 101 | */ |
||
| 102 | View Code Duplication | private function getCommandHandlers() |
|
| 121 | |||
| 122 | /** |
||
| 123 | * @return string |
||
| 124 | */ |
||
| 125 | abstract protected function getAddLabelClassName(); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | abstract protected function getRemoveLabelClassName(); |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @return string |
||
| 134 | */ |
||
| 135 | abstract protected function getUpdateTitleClassName(); |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | abstract protected function getAddImageClassName(); |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @return string |
||
| 144 | */ |
||
| 145 | abstract protected function getUpdateImageClassName(); |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return string |
||
| 149 | */ |
||
| 150 | abstract protected function getRemoveImageClassName(); |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @return string |
||
| 154 | */ |
||
| 155 | abstract protected function getSelectMainImageClassName(); |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return string |
||
| 159 | */ |
||
| 160 | abstract protected function getUpdateDescriptionClassName(); |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return string |
||
| 164 | */ |
||
| 165 | abstract protected function getUpdateCalendarClassName(); |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | abstract protected function getUpdateTypicalAgeRangeClassName(); |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @return string |
||
| 174 | */ |
||
| 175 | abstract protected function getDeleteTypicalAgeRangeClassName(); |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @return string |
||
| 179 | */ |
||
| 180 | abstract protected function getUpdateOrganizerClassName(); |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | abstract protected function getDeleteOrganizerClassName(); |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | abstract protected function getDeleteCurrentOrganizerClassName(); |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | abstract protected function getUpdateContactPointClassName(); |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | abstract protected function getUpdateBookingInfoClassName(); |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @return string |
||
| 204 | */ |
||
| 205 | abstract protected function getUpdatePriceInfoClassName(); |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @return string |
||
| 209 | */ |
||
| 210 | abstract protected function getDeleteOfferClassName(); |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @return string |
||
| 214 | */ |
||
| 215 | abstract protected function getPublishClassName(); |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @return string |
||
| 219 | */ |
||
| 220 | abstract protected function getApproveClassName(); |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @return string |
||
| 224 | */ |
||
| 225 | abstract protected function getRejectClassName(); |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | abstract protected function getFlagAsDuplicateClassName(); |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @return string |
||
| 234 | */ |
||
| 235 | abstract protected function getFlagAsInappropriateClassName(); |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | abstract protected function getUpdateTypeClassName(); |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return string |
||
| 244 | */ |
||
| 245 | abstract protected function getUpdateThemeClassName(); |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @return string |
||
| 249 | */ |
||
| 250 | abstract protected function getUpdateFacilitiesClassName(); |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @param AbstractUpdateType $updateType |
||
| 254 | */ |
||
| 255 | public function handleUpdateType(AbstractUpdateType $updateType) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @param AbstractUpdateTheme $updateTheme |
||
| 266 | */ |
||
| 267 | public function handleUpdateTheme(AbstractUpdateTheme $updateTheme) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @param AbstractUpdateFacilities $updateFacilities |
||
| 278 | */ |
||
| 279 | public function handleUpdateFacilities(AbstractUpdateFacilities $updateFacilities) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param AbstractAddLabel $addLabel |
||
| 290 | */ |
||
| 291 | private function handleAddLabel(AbstractAddLabel $addLabel) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param AbstractRemoveLabel $removeLabel |
||
| 302 | */ |
||
| 303 | private function handleRemoveLabel(AbstractRemoveLabel $removeLabel) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @param AbstractLabelCommand $labelCommand |
||
| 314 | * @return Label |
||
| 315 | */ |
||
| 316 | View Code Duplication | private function createLabel(AbstractLabelCommand $labelCommand) |
|
| 326 | |||
| 327 | /** |
||
| 328 | * @param AbstractUpdateTitle $translateTitle |
||
| 329 | */ |
||
| 330 | private function handleUpdateTitle(AbstractUpdateTitle $translateTitle) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Handle an add image command. |
||
| 339 | * @param AbstractAddImage $addImage |
||
| 340 | */ |
||
| 341 | public function handleAddImage(AbstractAddImage $addImage) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * @param AbstractRemoveImage $removeImage |
||
| 353 | */ |
||
| 354 | public function handleRemoveImage(AbstractRemoveImage $removeImage) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @param AbstractUpdateImage $updateImage |
||
| 363 | */ |
||
| 364 | public function handleUpdateImage(AbstractUpdateImage $updateImage) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @param AbstractSelectMainImage $selectMainImage |
||
| 373 | */ |
||
| 374 | public function handleSelectMainImage(AbstractSelectMainImage $selectMainImage) |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Handle the update of description on a place. |
||
| 383 | * @param AbstractUpdateDescription $updateDescription |
||
| 384 | */ |
||
| 385 | public function handleUpdateDescription(AbstractUpdateDescription $updateDescription) |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @param AbstractUpdateCalendar $updateCalendar |
||
| 400 | */ |
||
| 401 | public function handleUpdateCalendar(AbstractUpdateCalendar $updateCalendar) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Handle the update of typical age range on a place. |
||
| 412 | * @param AbstractUpdateTypicalAgeRange $updateTypicalAgeRange |
||
| 413 | */ |
||
| 414 | public function handleUpdateTypicalAgeRange(AbstractUpdateTypicalAgeRange $updateTypicalAgeRange) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Handle the deletion of typical age range on a place. |
||
| 428 | * @param AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange |
||
| 429 | */ |
||
| 430 | public function handleDeleteTypicalAgeRange(AbstractDeleteTypicalAgeRange $deleteTypicalAgeRange) |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Handle an update command to update organizer of a place. |
||
| 442 | * @param AbstractUpdateOrganizer $updateOrganizer |
||
| 443 | */ |
||
| 444 | public function handleUpdateOrganizer(AbstractUpdateOrganizer $updateOrganizer) |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Handle an update command to delete the organizer. |
||
| 458 | * @param AbstractDeleteOrganizer $deleteOrganizer |
||
| 459 | */ |
||
| 460 | public function handleDeleteOrganizer(AbstractDeleteOrganizer $deleteOrganizer) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * @param AbstractDeleteCurrentOrganizer $deleteCurrentOrganizer |
||
| 473 | */ |
||
| 474 | public function handleDeleteCurrentOrganizer(AbstractDeleteCurrentOrganizer $deleteCurrentOrganizer) |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Handle an update command to updated the contact point. |
||
| 485 | * @param AbstractUpdateContactPoint $updateContactPoint |
||
| 486 | */ |
||
| 487 | public function handleUpdateContactPoint(AbstractUpdateContactPoint $updateContactPoint) |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Handle an update command to updated the booking info. |
||
| 501 | * @param AbstractUpdateBookingInfo $updateBookingInfo |
||
| 502 | */ |
||
| 503 | public function handleUpdateBookingInfo(AbstractUpdateBookingInfo $updateBookingInfo) |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @param AbstractUpdatePriceInfo $updatePriceInfo |
||
| 516 | */ |
||
| 517 | private function handleUpdatePriceInfo(AbstractUpdatePriceInfo $updatePriceInfo) |
||
| 527 | |||
| 528 | /** |
||
| 529 | * @param AbstractDeleteOffer $deleteOffer |
||
| 530 | */ |
||
| 531 | private function handleDeleteOffer(AbstractDeleteOffer $deleteOffer) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @param AbstractPublish $publish |
||
| 540 | */ |
||
| 541 | private function handlePublish(AbstractPublish $publish) |
||
| 547 | |||
| 548 | /** |
||
| 549 | * @param AbstractApprove $approve |
||
| 550 | */ |
||
| 551 | private function handleApprove(AbstractApprove $approve) |
||
| 557 | |||
| 558 | /** |
||
| 559 | * @param AbstractReject $reject |
||
| 560 | */ |
||
| 561 | private function handleReject(AbstractReject $reject) |
||
| 567 | |||
| 568 | /** |
||
| 569 | * @param AbstractFlagAsDuplicate $flagAsDuplicate |
||
| 570 | */ |
||
| 571 | private function handleFlagAsDuplicate(AbstractFlagAsDuplicate $flagAsDuplicate) |
||
| 577 | |||
| 578 | /** |
||
| 579 | * @param AbstractFlagAsInappropriate $flagAsInappropriate |
||
| 580 | */ |
||
| 581 | private function handleFlagAsInappropriate(AbstractFlagAsInappropriate $flagAsInappropriate) |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Makes it easier to type-hint to Offer. |
||
| 590 | * |
||
| 591 | * @param string $id |
||
| 592 | * @return Offer |
||
| 593 | */ |
||
| 594 | private function load($id) |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Makes it easier to type-hint to Organizer. |
||
| 601 | * |
||
| 602 | * @param string $id |
||
| 603 | * @return Organizer |
||
| 604 | */ |
||
| 605 | private function loadOrganizer($id) |
||
| 610 | } |
||
| 611 |
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..