Complex classes like BookingDetails 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 BookingDetails, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class BookingDetails extends Model |
||
10 | { |
||
11 | /** |
||
12 | * @var int |
||
13 | */ |
||
14 | protected $reservation_id; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $status; |
||
20 | |||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | protected $affiliate_id; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $affiliate_label; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $chain_ids; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | protected $hotel_id; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $hotel_name; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $hotel_fax; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $hotel_address; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $hotel_zipcode; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $destination_ufi; |
||
65 | |||
66 | /** |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $hotel_countrycode; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $booker_firstname; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $booker_lastname; |
||
80 | |||
81 | /** |
||
82 | * @var string|null |
||
83 | */ |
||
84 | protected $booker_phone; |
||
85 | |||
86 | /** |
||
87 | * @var string |
||
88 | */ |
||
89 | protected $booker_email; |
||
90 | |||
91 | /** |
||
92 | * @var string |
||
93 | */ |
||
94 | protected $booker_mailinglist; |
||
95 | |||
96 | /** |
||
97 | * @var string |
||
98 | */ |
||
99 | protected $guest_name; |
||
100 | |||
101 | /** |
||
102 | * @var string |
||
103 | */ |
||
104 | protected $guest_city; |
||
105 | |||
106 | /** |
||
107 | * @var string |
||
108 | */ |
||
109 | protected $guest_country; |
||
110 | |||
111 | /** |
||
112 | * @var string |
||
113 | */ |
||
114 | protected $loyalty_member_id; |
||
115 | |||
116 | /** |
||
117 | * @var string |
||
118 | */ |
||
119 | protected $pincode; |
||
120 | |||
121 | /** |
||
122 | * @var string |
||
123 | */ |
||
124 | protected $language; |
||
125 | |||
126 | /** |
||
127 | * @var string |
||
128 | */ |
||
129 | protected $created; |
||
130 | |||
131 | /** |
||
132 | * @var string|null |
||
133 | */ |
||
134 | protected $checkin; |
||
135 | |||
136 | /** |
||
137 | * @var string|null |
||
138 | */ |
||
139 | protected $checkout; |
||
140 | |||
141 | /** |
||
142 | * @var string |
||
143 | */ |
||
144 | protected $cancellation_date; |
||
145 | |||
146 | /** |
||
147 | * @var string |
||
148 | */ |
||
149 | protected $fee_calculation_date; |
||
150 | |||
151 | /** |
||
152 | * @var int|null |
||
153 | */ |
||
154 | protected $fee_percentage; |
||
155 | |||
156 | /** |
||
157 | * @var float|null |
||
158 | */ |
||
159 | protected $euro_fee; |
||
160 | |||
161 | /** |
||
162 | * @var float|null |
||
163 | */ |
||
164 | protected $local_fee; |
||
165 | |||
166 | /** |
||
167 | * @var string |
||
168 | */ |
||
169 | protected $local_fee_currency; |
||
170 | |||
171 | /** |
||
172 | * @var float|null |
||
173 | */ |
||
174 | protected $price_euro; |
||
175 | |||
176 | /** |
||
177 | * @var float|null |
||
178 | */ |
||
179 | protected $price_local; |
||
180 | |||
181 | /** |
||
182 | * @var string |
||
183 | */ |
||
184 | protected $currency; |
||
185 | |||
186 | /** |
||
187 | * @var int |
||
188 | */ |
||
189 | protected $creditslip; |
||
190 | |||
191 | /** |
||
192 | * @var int |
||
193 | */ |
||
194 | protected $total_room_nights; |
||
195 | |||
196 | /** |
||
197 | * @var int |
||
198 | */ |
||
199 | protected $nr_rooms; |
||
200 | |||
201 | /** |
||
202 | * @var int |
||
203 | */ |
||
204 | protected $nr_guests; |
||
205 | |||
206 | /** |
||
207 | * @var string |
||
208 | */ |
||
209 | protected $url; |
||
210 | |||
211 | /** |
||
212 | * @var float|null |
||
213 | */ |
||
214 | protected $stay_probability; |
||
215 | |||
216 | /** |
||
217 | * @return int |
||
218 | */ |
||
219 | public function getReservationId(): int |
||
223 | |||
224 | /** |
||
225 | * @param int $reservation_id |
||
226 | */ |
||
227 | public function setReservationId(int $reservation_id): void |
||
231 | |||
232 | /** |
||
233 | * @return string |
||
234 | */ |
||
235 | public function getStatus(): string |
||
239 | |||
240 | /** |
||
241 | * @param string $status |
||
242 | */ |
||
243 | public function setStatus(string $status): void |
||
247 | |||
248 | /** |
||
249 | * @return int |
||
250 | */ |
||
251 | public function getAffiliateId(): int |
||
255 | |||
256 | /** |
||
257 | * @param int $affiliate_id |
||
258 | */ |
||
259 | public function setAffiliateId(int $affiliate_id): void |
||
263 | |||
264 | /** |
||
265 | * @return string |
||
266 | */ |
||
267 | public function getAffiliateLabel(): ?string |
||
271 | |||
272 | /** |
||
273 | * @param string $affiliate_label |
||
274 | */ |
||
275 | public function setAffiliateLabel(?string $affiliate_label): void |
||
279 | |||
280 | /** |
||
281 | * @return string |
||
282 | */ |
||
283 | public function getChainIds(): ?string |
||
287 | |||
288 | /** |
||
289 | * @param string $chain_ids |
||
290 | */ |
||
291 | public function setChainIds(?string $chain_ids): void |
||
295 | |||
296 | /** |
||
297 | * @return int |
||
298 | */ |
||
299 | public function getHotelId(): int |
||
303 | |||
304 | /** |
||
305 | * @param int $hotel_id |
||
306 | */ |
||
307 | public function setHotelId(int $hotel_id): void |
||
311 | |||
312 | /** |
||
313 | * @return string |
||
314 | */ |
||
315 | public function getHotelName(): ?string |
||
319 | |||
320 | /** |
||
321 | * @param string $hotel_name |
||
322 | */ |
||
323 | public function setHotelName(?string $hotel_name): void |
||
327 | |||
328 | /** |
||
329 | * @return string |
||
330 | */ |
||
331 | public function getHotelFax(): ?string |
||
335 | |||
336 | /** |
||
337 | * @param string $hotel_fax |
||
338 | */ |
||
339 | public function setHotelFax(?string $hotel_fax): void |
||
343 | |||
344 | /** |
||
345 | * @return string |
||
346 | */ |
||
347 | public function getHotelAddress(): ?string |
||
351 | |||
352 | /** |
||
353 | * @param string $hotel_address |
||
354 | */ |
||
355 | public function setHotelAddress(?string $hotel_address): void |
||
359 | |||
360 | /** |
||
361 | * @return string |
||
362 | */ |
||
363 | public function getHotelZipcode(): ?string |
||
367 | |||
368 | /** |
||
369 | * @param string $hotel_zipcode |
||
370 | */ |
||
371 | public function setHotelZipcode(?string $hotel_zipcode): void |
||
375 | |||
376 | /** |
||
377 | * @return string |
||
378 | */ |
||
379 | public function getDestinationUfi(): ?string |
||
383 | |||
384 | /** |
||
385 | * @param string $destination_ufi |
||
386 | */ |
||
387 | public function setDestinationUfi(?string $destination_ufi): void |
||
391 | |||
392 | /** |
||
393 | * @return string |
||
394 | */ |
||
395 | public function getHotelCountrycode(): ?string |
||
399 | |||
400 | /** |
||
401 | * @param string $hotel_countrycode |
||
402 | */ |
||
403 | public function setHotelCountrycode(?string $hotel_countrycode): void |
||
407 | |||
408 | /** |
||
409 | * @return null|string |
||
410 | */ |
||
411 | public function getBookerFirstname(): ?string |
||
415 | |||
416 | /** |
||
417 | * @param null|string $booker_firstname |
||
418 | */ |
||
419 | public function setBookerFirstname(?string $booker_firstname): void |
||
423 | |||
424 | /** |
||
425 | * @return null|string |
||
426 | */ |
||
427 | public function getBookerLastname(): ?string |
||
431 | |||
432 | /** |
||
433 | * @param null|string $booker_lastname |
||
434 | */ |
||
435 | public function setBookerLastname(?string $booker_lastname): void |
||
439 | |||
440 | /** |
||
441 | * @return string|null |
||
442 | */ |
||
443 | public function getBookerPhone(): ?string |
||
447 | |||
448 | /** |
||
449 | * @param string|null $booker_phone |
||
450 | */ |
||
451 | public function setBookerPhone(?string $booker_phone): void |
||
455 | |||
456 | /** |
||
457 | * @return string |
||
458 | */ |
||
459 | public function getBookerEmail(): string |
||
463 | |||
464 | /** |
||
465 | * @param string $booker_email |
||
466 | */ |
||
467 | public function setBookerEmail(string $booker_email): void |
||
471 | |||
472 | /** |
||
473 | * @return string |
||
474 | */ |
||
475 | public function getBookerMailinglist(): ?string |
||
479 | |||
480 | /** |
||
481 | * @param string $booker_mailinglist |
||
482 | */ |
||
483 | public function setBookerMailinglist(?string $booker_mailinglist): void |
||
487 | |||
488 | /** |
||
489 | * @return string |
||
490 | */ |
||
491 | public function getGuestName(): ?string |
||
495 | |||
496 | /** |
||
497 | * @param string $guest_name |
||
498 | */ |
||
499 | public function setGuestName(?string $guest_name): void |
||
503 | |||
504 | /** |
||
505 | * @return string |
||
506 | */ |
||
507 | public function getGuestCity(): ?string |
||
511 | |||
512 | /** |
||
513 | * @param string $guest_city |
||
514 | */ |
||
515 | public function setGuestCity(?string $guest_city): void |
||
519 | |||
520 | /** |
||
521 | * @return string |
||
522 | */ |
||
523 | public function getGuestCountry(): ?string |
||
527 | |||
528 | /** |
||
529 | * @param string $guest_country |
||
530 | */ |
||
531 | public function setGuestCountry(?string $guest_country): void |
||
535 | |||
536 | /** |
||
537 | * @return string |
||
538 | */ |
||
539 | public function getLoyaltyMemberId(): ?string |
||
543 | |||
544 | /** |
||
545 | * @param string $loyalty_member_id |
||
546 | */ |
||
547 | public function setLoyaltyMemberId(?string $loyalty_member_id): void |
||
551 | |||
552 | /** |
||
553 | * @return string |
||
554 | */ |
||
555 | public function getPincode(): string |
||
559 | |||
560 | /** |
||
561 | * @param string $pincode |
||
562 | */ |
||
563 | public function setPincode(string $pincode): void |
||
567 | |||
568 | /** |
||
569 | * @return string |
||
570 | */ |
||
571 | public function getLanguage(): string |
||
575 | |||
576 | /** |
||
577 | * @param string $language |
||
578 | */ |
||
579 | public function setLanguage(string $language): void |
||
583 | |||
584 | /** |
||
585 | * @return string |
||
586 | */ |
||
587 | public function getCreated(): string |
||
591 | |||
592 | /** |
||
593 | * @param string $created |
||
594 | */ |
||
595 | public function setCreated(string $created): void |
||
599 | |||
600 | /** |
||
601 | * @return string|null |
||
602 | */ |
||
603 | public function getCheckin(): ?string |
||
607 | |||
608 | /** |
||
609 | * @param string|null $checkin |
||
610 | */ |
||
611 | public function setCheckin(?string $checkin): void |
||
615 | |||
616 | /** |
||
617 | * @return string|null |
||
618 | */ |
||
619 | public function getCheckout(): ?string |
||
623 | |||
624 | /** |
||
625 | * @param string|null $checkout |
||
626 | */ |
||
627 | public function setCheckout(?string $checkout): void |
||
631 | |||
632 | /** |
||
633 | * @return string |
||
634 | */ |
||
635 | public function getCancellationDate(): ?string |
||
639 | |||
640 | /** |
||
641 | * @param string $cancellation_date |
||
642 | */ |
||
643 | public function setCancellationDate(?string $cancellation_date): void |
||
647 | |||
648 | /** |
||
649 | * @return string |
||
650 | */ |
||
651 | public function getFeeCalculationDate(): ?string |
||
655 | |||
656 | /** |
||
657 | * @param string $fee_calculation_date |
||
658 | */ |
||
659 | public function setFeeCalculationDate(?string $fee_calculation_date): void |
||
663 | |||
664 | /** |
||
665 | * @return int|null |
||
666 | */ |
||
667 | public function getFeePercentage(): ?int |
||
671 | |||
672 | /** |
||
673 | * @param int|null $fee_percentage |
||
674 | */ |
||
675 | public function setFeePercentage(?int $fee_percentage): void |
||
679 | |||
680 | /** |
||
681 | * @return float|null |
||
682 | */ |
||
683 | public function getEuroFee(): ?float |
||
687 | |||
688 | /** |
||
689 | * @param float|null $euro_fee |
||
690 | */ |
||
691 | public function setEuroFee(?float $euro_fee): void |
||
695 | |||
696 | /** |
||
697 | * @return float |
||
698 | */ |
||
699 | public function getLocalFee(): ?float |
||
703 | |||
704 | /** |
||
705 | * @param float $local_fee |
||
706 | */ |
||
707 | public function setLocalFee(?float $local_fee): void |
||
711 | |||
712 | /** |
||
713 | * @return string |
||
714 | */ |
||
715 | public function getLocalFeeCurrency(): ?string |
||
719 | |||
720 | /** |
||
721 | * @param string $local_fee_currency |
||
722 | */ |
||
723 | public function setLocalFeeCurrency(?string $local_fee_currency): void |
||
727 | |||
728 | /** |
||
729 | * @return float|null |
||
730 | */ |
||
731 | public function getPriceEuro(): ?float |
||
735 | |||
736 | /** |
||
737 | * @param float|null $price_euro |
||
738 | */ |
||
739 | public function setPriceEuro(?float $price_euro): void |
||
743 | |||
744 | /** |
||
745 | * @return float|null |
||
746 | */ |
||
747 | public function getPriceLocal(): ?float |
||
751 | |||
752 | /** |
||
753 | * @param float|null $price_local |
||
754 | */ |
||
755 | public function setPriceLocal(?float $price_local): void |
||
759 | |||
760 | /** |
||
761 | * @return string |
||
762 | */ |
||
763 | public function getCurrency(): string |
||
767 | |||
768 | /** |
||
769 | * @param string $currency |
||
770 | */ |
||
771 | public function setCurrency(string $currency): void |
||
775 | |||
776 | /** |
||
777 | * @return string |
||
778 | */ |
||
779 | public function getCreditslip(): ?string |
||
783 | |||
784 | /** |
||
785 | * @param string $creditslip |
||
786 | */ |
||
787 | public function setCreditslip(?string $creditslip): void |
||
791 | |||
792 | /** |
||
793 | * @return int |
||
794 | */ |
||
795 | public function getTotalRoomNights(): ?int |
||
799 | |||
800 | /** |
||
801 | * @param int $total_room_nights |
||
802 | */ |
||
803 | public function setTotalRoomNights(?int $total_room_nights): void |
||
807 | |||
808 | /** |
||
809 | * @return int |
||
810 | */ |
||
811 | public function getNrRooms(): ?int |
||
815 | |||
816 | /** |
||
817 | * @param int $nr_rooms |
||
818 | */ |
||
819 | public function setNrRooms(?int $nr_rooms): void |
||
823 | |||
824 | /** |
||
825 | * @return int |
||
826 | */ |
||
827 | public function getNrGuests(): ?int |
||
831 | |||
832 | /** |
||
833 | * @param int $nr_guests |
||
834 | */ |
||
835 | public function setNrGuests(?int $nr_guests): void |
||
839 | |||
840 | /** |
||
841 | * @return string |
||
842 | */ |
||
843 | public function getUrl(): ?string |
||
847 | |||
848 | /** |
||
849 | * @param string $url |
||
850 | */ |
||
851 | public function setUrl(?string $url): void |
||
855 | |||
856 | /** |
||
857 | * @return float|null |
||
858 | */ |
||
859 | public function getStayProbability(): ?float |
||
863 | |||
864 | /** |
||
865 | * @param float|null $stay_probability |
||
866 | */ |
||
867 | public function setStayProbability(?float $stay_probability): void |
||
871 | |||
872 | /** |
||
873 | * @return array |
||
874 | */ |
||
875 | protected function getAttributeMap(): array |
||
921 | } |
||
922 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.