Complex classes like Place often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Place, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
70 | class Place extends Offer implements UpdateableWithCdbXmlInterface |
||
71 | { |
||
72 | /** |
||
73 | * @var string |
||
74 | */ |
||
75 | private $placeId; |
||
76 | |||
77 | /** |
||
78 | * @var Address[] |
||
79 | */ |
||
80 | private $addresses; |
||
81 | |||
82 | /** |
||
83 | * @var boolean |
||
84 | */ |
||
85 | private $isDuplicate = false; |
||
86 | |||
87 | /** |
||
88 | * @var string[] |
||
89 | */ |
||
90 | private $duplicates = []; |
||
91 | |||
92 | /** |
||
93 | * @var string|null |
||
94 | */ |
||
95 | private $canonicalPlaceId; |
||
96 | |||
97 | public function __construct() |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function getAggregateRootId() |
||
111 | |||
112 | /** |
||
113 | * @todo Rename this method to create() after moving this part of the codebase to udb3-silex |
||
114 | */ |
||
115 | public static function createPlace( |
||
139 | |||
140 | protected function applyPlaceCreated(PlaceCreated $placeCreated): void |
||
153 | |||
154 | public function updateMajorInfo( |
||
172 | |||
173 | protected function applyMajorInfoUpdated(MajorInfoUpdated $majorInfoUpdated): void |
||
177 | |||
178 | public function updateAddress(Address $address, Language $language): void |
||
190 | |||
191 | protected function applyAddressUpdated(AddressUpdated $addressUpdated): void |
||
195 | |||
196 | protected function applyAddressTranslated(AddressTranslated $addressTranslated): void |
||
200 | |||
201 | public function markAsDuplicateOf(string $placeIdOfCanonical): void |
||
213 | |||
214 | public function markAsCanonicalFor(string $placeIdOfDuplicate, array $duplicatesOfDuplicate = []): void |
||
226 | |||
227 | /** |
||
228 | * @return string[] |
||
229 | */ |
||
230 | public function getDuplicates(): array |
||
234 | |||
235 | private function allowAddressUpdate(Address $address, Language $language): bool |
||
249 | |||
250 | public static function importFromUDB2Actor( |
||
266 | |||
267 | protected function applyPlaceImportedFromUDB2(PlaceImportedFromUDB2 $placeImported): void |
||
300 | |||
301 | protected function applyPlaceUpdatedFromUDB2(PlaceUpdatedFromUDB2 $placeUpdatedFromUDB2): void |
||
333 | |||
334 | protected function applyPlaceDeleted(PlaceDeleted $event): void |
||
338 | |||
339 | protected function applyMarkedAsDuplicate(MarkedAsDuplicate $event): void |
||
344 | |||
345 | protected function applyMarkedAsCanonical(MarkedAsCanonical $event): void |
||
352 | |||
353 | public function getCanonicalPlaceId(): ?string |
||
357 | |||
358 | /** |
||
359 | * @inheritdoc |
||
360 | */ |
||
361 | public function updateWithCdbXml($cdbXml, $cdbXmlNamespaceUri) |
||
373 | |||
374 | /** |
||
375 | * @param Label $label |
||
376 | * @return LabelAdded |
||
377 | */ |
||
378 | protected function createLabelAddedEvent(Label $label) |
||
382 | |||
383 | /** |
||
384 | * @param Label $label |
||
385 | * @return LabelRemoved |
||
386 | */ |
||
387 | protected function createLabelRemovedEvent(Label $label) |
||
391 | |||
392 | /** |
||
393 | * @inheritdoc |
||
394 | */ |
||
395 | protected function createLabelsImportedEvent(Labels $labels) |
||
399 | |||
400 | protected function createImageAddedEvent(Image $image) |
||
404 | |||
405 | protected function createImageRemovedEvent(Image $image) |
||
409 | |||
410 | protected function createImageUpdatedEvent( |
||
422 | |||
423 | protected function createMainImageSelectedEvent(Image $image) |
||
427 | |||
428 | /** |
||
429 | * @inheritdoc |
||
430 | */ |
||
431 | protected function createTitleTranslatedEvent(Language $language, Title $title) |
||
435 | |||
436 | /** |
||
437 | * @param Title $title |
||
438 | * @return TitleUpdated |
||
439 | */ |
||
440 | protected function createTitleUpdatedEvent(Title $title) |
||
444 | |||
445 | /** |
||
446 | * @inheritdoc |
||
447 | */ |
||
448 | protected function createDescriptionTranslatedEvent(Language $language, Description $description) |
||
452 | |||
453 | /** |
||
454 | * @inheritdoc |
||
455 | */ |
||
456 | protected function createDescriptionUpdatedEvent(Description $description) |
||
460 | |||
461 | /** |
||
462 | * @inheritdoc |
||
463 | */ |
||
464 | protected function createCalendarUpdatedEvent(Calendar $calendar) |
||
468 | |||
469 | /** |
||
470 | * @param AgeRange $typicalAgeRange |
||
471 | * @return TypicalAgeRangeUpdated |
||
472 | */ |
||
473 | protected function createTypicalAgeRangeUpdatedEvent($typicalAgeRange) |
||
477 | |||
478 | /** |
||
479 | * @return TypicalAgeRangeDeleted |
||
480 | */ |
||
481 | protected function createTypicalAgeRangeDeletedEvent() |
||
485 | |||
486 | /** |
||
487 | * @param string $organizerId |
||
488 | * @return OrganizerUpdated |
||
489 | */ |
||
490 | protected function createOrganizerUpdatedEvent($organizerId) |
||
494 | |||
495 | /** |
||
496 | * @param string $organizerId |
||
497 | * @return OrganizerDeleted |
||
498 | */ |
||
499 | protected function createOrganizerDeletedEvent($organizerId) |
||
503 | |||
504 | /** |
||
505 | * @param ContactPoint $contactPoint |
||
506 | * @return ContactPointUpdated |
||
507 | */ |
||
508 | protected function createContactPointUpdatedEvent(ContactPoint $contactPoint) |
||
512 | |||
513 | /** |
||
514 | * @inheritdoc |
||
515 | */ |
||
516 | protected function createGeoCoordinatesUpdatedEvent(Coordinates $coordinates) |
||
520 | |||
521 | /** |
||
522 | * @param BookingInfo $bookingInfo |
||
523 | * @return BookingInfoUpdated |
||
524 | */ |
||
525 | protected function createBookingInfoUpdatedEvent(BookingInfo $bookingInfo) |
||
529 | |||
530 | /** |
||
531 | * @param PriceInfo $priceInfo |
||
532 | * @return PriceInfoUpdated |
||
533 | */ |
||
534 | protected function createPriceInfoUpdatedEvent(PriceInfo $priceInfo) |
||
538 | |||
539 | /** |
||
540 | * @return PlaceDeleted |
||
541 | */ |
||
542 | protected function createOfferDeletedEvent() |
||
546 | |||
547 | /** |
||
548 | * @inheritDoc |
||
549 | */ |
||
550 | protected function createPublishedEvent(\DateTimeInterface $publicationDate) |
||
554 | |||
555 | /** |
||
556 | * @inheritDoc |
||
557 | */ |
||
558 | protected function createApprovedEvent() |
||
562 | |||
563 | /** |
||
564 | * @inheritDoc |
||
565 | */ |
||
566 | protected function createRejectedEvent(StringLiteral $reason) |
||
570 | |||
571 | /** |
||
572 | * @inheritDoc |
||
573 | */ |
||
574 | protected function createFlaggedAsDuplicate() |
||
578 | |||
579 | /** |
||
580 | * @inheritDoc |
||
581 | */ |
||
582 | protected function createFlaggedAsInappropriate() |
||
586 | |||
587 | /** |
||
588 | * @inheritDoc |
||
589 | * @return ImagesImportedFromUDB2 |
||
590 | */ |
||
591 | protected function createImagesImportedFromUDB2(ImageCollection $images) |
||
595 | |||
596 | /** |
||
597 | * @inheritDoc |
||
598 | * @return ImagesUpdatedFromUDB2 |
||
599 | */ |
||
600 | protected function createImagesUpdatedFromUDB2(ImageCollection $images) |
||
604 | |||
605 | protected function createTypeUpdatedEvent(EventType $type) |
||
609 | |||
610 | protected function createThemeUpdatedEvent(Theme $theme) |
||
614 | |||
615 | /** |
||
616 | * @inheritdoc |
||
617 | */ |
||
618 | protected function createFacilitiesUpdatedEvent(array $facilities) |
||
622 | } |
||
623 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.