Complex classes like HotelAvailabilityQuery 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 HotelAvailabilityQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class HotelAvailabilityQuery extends Query |
||
9 | { |
||
10 | public const ORDER_BY_DISTANCE = 'distance'; |
||
11 | public const ORDER_BY_POPULARITY = 'popularity'; |
||
12 | public const ORDER_BY_PRICE = 'price'; |
||
13 | public const ORDER_BY_RANKING = 'ranking'; |
||
14 | public const ORDER_BY_REVIEW_SCORE = 'review_score'; |
||
15 | public const ORDER_BY_STARS = 'stars'; |
||
16 | public const ORDER_DIRECTION_ASC = 'asc'; |
||
17 | public const ORDER_DIRECTION_DESC = 'desc'; |
||
18 | |||
19 | /** |
||
20 | * @var string Shows cheapest breakfast rate for the hotel |
||
21 | */ |
||
22 | public const EXTRAS_ADD_CHEAPEST_BREAKFAST_RATE = 'add_cheapest_breakfast_rate'; |
||
23 | |||
24 | /** |
||
25 | * @var string Show amenities provided by hotel |
||
26 | */ |
||
27 | public const EXTRAS_HOTEL_AMENITIES = 'hotel_amenities'; |
||
28 | |||
29 | /** |
||
30 | * @var string Show extra hotel details |
||
31 | */ |
||
32 | public const EXTRAS_HOTEL_DETAILS = 'hotel_details'; |
||
33 | |||
34 | /** |
||
35 | * @var string Show payment terms like prepay or cancellation for the room |
||
36 | */ |
||
37 | public const EXTRAS_PAYMENT_TERMS = 'payment_terms'; |
||
38 | |||
39 | /** |
||
40 | * @var string Show amenities in the room |
||
41 | */ |
||
42 | public const EXTRAS_ROOM_AMENITIES = 'room_amenities'; |
||
43 | |||
44 | /** |
||
45 | * @var string Show extra room details |
||
46 | */ |
||
47 | public const EXTRAS_ROOM_DETAILS = 'room_details'; |
||
48 | |||
49 | /** |
||
50 | * @var string Show policies for the room |
||
51 | */ |
||
52 | public const EXTRAS_ROOM_POLICIES = 'room_policies'; |
||
53 | |||
54 | /** |
||
55 | * @var string Only show hotels that have a reception that's open 24 hours/day |
||
56 | */ |
||
57 | public const FILTER_IS_24HR = 'is_24hr'; |
||
58 | |||
59 | /** |
||
60 | * @var string Filter to show only no_cc properties in the response. |
||
61 | */ |
||
62 | public const FILTER_NO_CC_FILTER = 'no_cc_filter'; |
||
63 | |||
64 | /** |
||
65 | * @var string Do not show dormitory beds or rooms, or hotels that only have such rooms |
||
66 | */ |
||
67 | public const FILTER_NO_DORMS = 'no_dorms'; |
||
68 | |||
69 | /** |
||
70 | * This is used when debugging or when you are initially setting up your integration. |
||
71 | * A test hotel can be used to test all of our endpoints including making a booking |
||
72 | * @var string |
||
73 | */ |
||
74 | public const FILTER_SHOW_TEST = 'show_test'; |
||
75 | |||
76 | public const ROOM_ADULT_GUEST = 'A'; |
||
77 | |||
78 | /** |
||
79 | * @var string |
||
80 | */ |
||
81 | protected static $uri = '/hotelAvailability'; |
||
82 | |||
83 | /** |
||
84 | * Limit the result list to the specified cities. You can get the list of city_ids from cities. |
||
85 | */ |
||
86 | protected $city_ids; |
||
87 | |||
88 | /** |
||
89 | * Limit the result list to the specified regions. You can get the list of region_ids form regions. |
||
90 | */ |
||
91 | protected $region_ids; |
||
92 | |||
93 | /** |
||
94 | * Limit the result list to the specified districts. You can get the list of district_ids from districts. |
||
95 | */ |
||
96 | protected $district_ids; |
||
97 | |||
98 | /** |
||
99 | * Limit the result list to the specified hotels where they have availability for the specified guests and dates. |
||
100 | */ |
||
101 | protected $hotel_ids; |
||
102 | |||
103 | /** |
||
104 | * The arrival date. Must be within 360 days in the future and in the format yyyy-mm-dd. |
||
105 | */ |
||
106 | protected $checkin; |
||
107 | |||
108 | /** |
||
109 | * The departure date. Must be later than {checkin}. Must be between 1 and 30 days after {checkin}. |
||
110 | * Must be within 360 days in the future and in the format yyyy-mm-dd. |
||
111 | */ |
||
112 | protected $checkout; |
||
113 | |||
114 | /** |
||
115 | * The maximum number of entries to return (less can and often are returned). |
||
116 | * This can be used together with {offset} to paginate through results. The default number returned is 1000. |
||
117 | * When requesting 1000, there can be less than 1000 rows returned, but this does not mean the end of the resultset, |
||
118 | * instead you should keep paginating by increasing the offset by 1000 until you get a page with 0 results - |
||
119 | * that is what signifies the end. |
||
120 | * @var int |
||
121 | */ |
||
122 | protected $rows; |
||
123 | |||
124 | /** |
||
125 | * This is the index of item you wish to use as the starting point for this page (when paginating). |
||
126 | * Used together with {rows} for pagination. Eg. rows=1000&offset=0 will be first 1000 results. |
||
127 | * rows=1000&offset=1000 will be the next 1000. You should continue to increment the offset to paginate, |
||
128 | * and you should use the value of rows as the number you increase by each time. |
||
129 | * @var int |
||
130 | */ |
||
131 | protected $offset; |
||
132 | |||
133 | /** |
||
134 | * Show the results in this language. Note: only some cities are translated. |
||
135 | * @var string |
||
136 | */ |
||
137 | protected $language; |
||
138 | |||
139 | /** |
||
140 | * Returns the price in this currency |
||
141 | * @var string |
||
142 | */ |
||
143 | protected $currency; |
||
144 | |||
145 | /** |
||
146 | * The way to order your results. (distance, popularity, price, ranking, review_score, stars) |
||
147 | * @var string |
||
148 | */ |
||
149 | protected $order_by; |
||
150 | |||
151 | /** |
||
152 | * The direction you wish for your order_by parameter to be ordered in. |
||
153 | * Possible values are order_dir=asc for ascending or order_dir=desc for descending |
||
154 | * @var string |
||
155 | */ |
||
156 | protected $order_dir; |
||
157 | |||
158 | /** |
||
159 | * Returns extra results mentioned in this. |
||
160 | * |
||
161 | * Additional information available (via extras parameter) are: |
||
162 | * add_cheapest_breakfast_rate: Shows cheapest breakfast rate for the hotel |
||
163 | * hotel_amenities: Show amenities provided by hotel |
||
164 | * hotel_details: Show extra hotel details |
||
165 | * payment_terms: Show payment terms like prepay or cancellation for the room |
||
166 | * room_amenities: Show amenities in the room |
||
167 | * room_details: Show extra room details |
||
168 | * room_policies: Show policies for the room |
||
169 | * |
||
170 | * @var array |
||
171 | */ |
||
172 | protected $extras; |
||
173 | |||
174 | /** |
||
175 | * Limit the result list to the items satisfying the specified rules |
||
176 | * |
||
177 | * Available options to filter the output (via options parameter) are: |
||
178 | * is_24hr: Only show hotels that have a reception that's open 24 hours/day |
||
179 | * no_cc_filter: Filter to show only no_cc properties in the response. Added in version 2.1. |
||
180 | * no_dorms: Do not show dormitory beds or rooms, or hotels that only have such rooms |
||
181 | * show_test: This is used when debugging or when you are initially setting up your integration. |
||
182 | * @var array |
||
183 | */ |
||
184 | protected $filter; |
||
185 | |||
186 | /** |
||
187 | * A comma separated array of guests to stay in this room where "A" represents an adult and an integer |
||
188 | * represents a child. eg room1=A,A,4 would be a room with 2 adults and 1 four year-old child. |
||
189 | * Child age numbers are 0..17. |
||
190 | * Similar parameters available for up to 30 rooms - room1..room30. |
||
191 | */ |
||
192 | protected $room1; |
||
193 | protected $room2; |
||
194 | protected $room3; |
||
195 | protected $room4; |
||
196 | protected $room5; |
||
197 | protected $room6; |
||
198 | protected $room7; |
||
199 | protected $room8; |
||
200 | protected $room9; |
||
201 | protected $room10; |
||
202 | protected $room11; |
||
203 | protected $room12; |
||
204 | protected $room13; |
||
205 | protected $room14; |
||
206 | protected $room15; |
||
207 | protected $room16; |
||
208 | protected $room17; |
||
209 | protected $room18; |
||
210 | protected $room19; |
||
211 | protected $room20; |
||
212 | protected $room21; |
||
213 | protected $room22; |
||
214 | protected $room23; |
||
215 | protected $room24; |
||
216 | protected $room25; |
||
217 | protected $room26; |
||
218 | protected $room27; |
||
219 | protected $room28; |
||
220 | protected $room29; |
||
221 | protected $room30; |
||
222 | |||
223 | /** |
||
224 | * @return bool |
||
225 | */ |
||
226 | public function isSecure(): bool |
||
230 | |||
231 | /** |
||
232 | * @return array |
||
233 | */ |
||
234 | public function getCityIds(): ?array |
||
238 | |||
239 | /** |
||
240 | * @param array $city_ids |
||
241 | * @return self |
||
242 | */ |
||
243 | public function setCityIds(array $city_ids): self |
||
249 | |||
250 | /** |
||
251 | * @return array |
||
252 | */ |
||
253 | public function getRegionIds(): ?array |
||
257 | |||
258 | /** |
||
259 | * @param array $region_ids |
||
260 | * @return self |
||
261 | */ |
||
262 | public function setRegionIds(array $region_ids): self |
||
268 | |||
269 | /** |
||
270 | * @return array |
||
271 | */ |
||
272 | public function getDistrictIds(): ?array |
||
276 | |||
277 | /** |
||
278 | * @param array $district_ids |
||
279 | * @return self |
||
280 | */ |
||
281 | public function setDistrictIds(array $district_ids): self |
||
287 | |||
288 | /** |
||
289 | * @return array |
||
290 | */ |
||
291 | public function getHotelIds(): ?array |
||
295 | |||
296 | /** |
||
297 | * @param array $hotel_ids |
||
298 | * @return self |
||
299 | */ |
||
300 | public function setHotelIds(array $hotel_ids): self |
||
306 | |||
307 | /** |
||
308 | * @return string |
||
309 | */ |
||
310 | public function getCheckin(): ?string |
||
314 | |||
315 | /** |
||
316 | * @param DateTime $checkin |
||
317 | * @return self |
||
318 | */ |
||
319 | public function setCheckin(DateTime $checkin): self |
||
325 | |||
326 | /** |
||
327 | * @return string |
||
328 | */ |
||
329 | public function getCheckout(): ?string |
||
333 | |||
334 | /** |
||
335 | * @param DateTime $checkout |
||
336 | * @return self |
||
337 | */ |
||
338 | public function setCheckout(DateTime $checkout): self |
||
344 | |||
345 | /** |
||
346 | * @return int |
||
347 | */ |
||
348 | public function getRows(): ?int |
||
352 | |||
353 | /** |
||
354 | * @param int $rows |
||
355 | * @return self |
||
356 | */ |
||
357 | public function setRows(int $rows): self |
||
363 | |||
364 | /** |
||
365 | * @return string |
||
366 | */ |
||
367 | public function getLanguage(): ?string |
||
371 | |||
372 | /** |
||
373 | * @param string $language |
||
374 | * @return self |
||
375 | */ |
||
376 | public function setLanguage(string $language): self |
||
382 | |||
383 | /** |
||
384 | * @return array |
||
385 | */ |
||
386 | public function getRoom1(): ?array |
||
390 | |||
391 | /** |
||
392 | * @param array $room1 |
||
393 | * @return self |
||
394 | */ |
||
395 | public function setRoom1(array $room1): self |
||
401 | |||
402 | /** |
||
403 | * @return array |
||
404 | */ |
||
405 | public function getRoom2(): ?array |
||
409 | |||
410 | /** |
||
411 | * @param array $room2 |
||
412 | * @return self |
||
413 | */ |
||
414 | public function setRoom2(array $room2): self |
||
420 | |||
421 | /** |
||
422 | * @return array |
||
423 | */ |
||
424 | public function getRoom3(): ?array |
||
428 | |||
429 | /** |
||
430 | * @param array $room3 |
||
431 | * @return self |
||
432 | */ |
||
433 | public function setRoom3(array $room3): self |
||
439 | |||
440 | /** |
||
441 | * @return array |
||
442 | */ |
||
443 | public function getRoom4(): ?array |
||
447 | |||
448 | /** |
||
449 | * @param array $room4 |
||
450 | * @return self |
||
451 | */ |
||
452 | public function setRoom4(array $room4): self |
||
458 | |||
459 | /** |
||
460 | * @return array |
||
461 | */ |
||
462 | public function getRoom5(): ?array |
||
466 | |||
467 | /** |
||
468 | * @param array $room5 |
||
469 | * @return self |
||
470 | */ |
||
471 | public function setRoom5(array $room5): self |
||
477 | |||
478 | /** |
||
479 | * @return array |
||
480 | */ |
||
481 | public function getRoom6(): ?array |
||
485 | |||
486 | /** |
||
487 | * @param array $room6 |
||
488 | * @return self |
||
489 | */ |
||
490 | public function setRoom6(array $room6): self |
||
496 | |||
497 | /** |
||
498 | * @return array |
||
499 | */ |
||
500 | public function getRoom7(): ?array |
||
504 | |||
505 | /** |
||
506 | * @param array $room7 |
||
507 | * @return self |
||
508 | */ |
||
509 | public function setRoom7(array $room7): self |
||
515 | |||
516 | /** |
||
517 | * @return array |
||
518 | */ |
||
519 | public function getRoom8(): ?array |
||
523 | |||
524 | /** |
||
525 | * @param array $room8 |
||
526 | * @return self |
||
527 | */ |
||
528 | public function setRoom8(array $room8): self |
||
534 | |||
535 | /** |
||
536 | * @return array |
||
537 | */ |
||
538 | public function getRoom9(): ?array |
||
542 | |||
543 | /** |
||
544 | * @param array $room9 |
||
545 | * @return self |
||
546 | */ |
||
547 | public function setRoom9(array $room9): self |
||
553 | |||
554 | /** |
||
555 | * @return array |
||
556 | */ |
||
557 | public function getRoom10(): ?array |
||
561 | |||
562 | /** |
||
563 | * @param array $room10 |
||
564 | * @return self |
||
565 | */ |
||
566 | public function setRoom10(array $room10): self |
||
572 | |||
573 | /** |
||
574 | * @return array |
||
575 | */ |
||
576 | public function getRoom11(): ?array |
||
580 | |||
581 | /** |
||
582 | * @param array $room11 |
||
583 | * @return self |
||
584 | */ |
||
585 | public function setRoom11(array $room11): self |
||
591 | |||
592 | /** |
||
593 | * @return array |
||
594 | */ |
||
595 | public function getRoom12(): ?array |
||
599 | |||
600 | /** |
||
601 | * @param array $room12 |
||
602 | * @return self |
||
603 | */ |
||
604 | public function setRoom12(array $room12): self |
||
610 | |||
611 | /** |
||
612 | * @return array |
||
613 | */ |
||
614 | public function getRoom13(): ?array |
||
618 | |||
619 | /** |
||
620 | * @param array $room13 |
||
621 | * @return self |
||
622 | */ |
||
623 | public function setRoom13(array $room13): self |
||
629 | |||
630 | /** |
||
631 | * @return array |
||
632 | */ |
||
633 | public function getRoom14(): ?array |
||
637 | |||
638 | /** |
||
639 | * @param array $room14 |
||
640 | * @return self |
||
641 | */ |
||
642 | public function setRoom14(array $room14): self |
||
648 | |||
649 | /** |
||
650 | * @return array |
||
651 | */ |
||
652 | public function getRoom15(): ?array |
||
656 | |||
657 | /** |
||
658 | * @param array $room15 |
||
659 | * @return self |
||
660 | */ |
||
661 | public function setRoom15(array $room15): self |
||
667 | |||
668 | /** |
||
669 | * @return array |
||
670 | */ |
||
671 | public function getRoom16(): ?array |
||
675 | |||
676 | /** |
||
677 | * @param array $room16 |
||
678 | * @return self |
||
679 | */ |
||
680 | public function setRoom16(array $room16): self |
||
686 | |||
687 | /** |
||
688 | * @return array |
||
689 | */ |
||
690 | public function getRoom17(): ?array |
||
694 | |||
695 | /** |
||
696 | * @param array $room17 |
||
697 | * @return self |
||
698 | */ |
||
699 | public function setRoom17(array $room17): self |
||
705 | |||
706 | /** |
||
707 | * @return array |
||
708 | */ |
||
709 | public function getRoom18(): ?array |
||
713 | |||
714 | /** |
||
715 | * @param array $room18 |
||
716 | * @return self |
||
717 | */ |
||
718 | public function setRoom18(array $room18): self |
||
724 | |||
725 | /** |
||
726 | * @return array |
||
727 | */ |
||
728 | public function getRoom19(): ?array |
||
732 | |||
733 | /** |
||
734 | * @param array $room19 |
||
735 | * @return self |
||
736 | */ |
||
737 | public function setRoom19(array $room19): self |
||
743 | |||
744 | /** |
||
745 | * @return array |
||
746 | */ |
||
747 | public function getRoom20(): ?array |
||
751 | |||
752 | /** |
||
753 | * @param array $room20 |
||
754 | * @return self |
||
755 | */ |
||
756 | public function setRoom20(array $room20): self |
||
762 | |||
763 | /** |
||
764 | * @return array |
||
765 | */ |
||
766 | public function getRoom21(): ?array |
||
770 | |||
771 | /** |
||
772 | * @param array $room21 |
||
773 | * @return self |
||
774 | */ |
||
775 | public function setRoom21(array $room21): self |
||
781 | |||
782 | /** |
||
783 | * @return array |
||
784 | */ |
||
785 | public function getRoom22(): ?array |
||
789 | |||
790 | /** |
||
791 | * @param array $room22 |
||
792 | * @return self |
||
793 | */ |
||
794 | public function setRoom22(array $room22): self |
||
800 | |||
801 | /** |
||
802 | * @return array |
||
803 | */ |
||
804 | public function getRoom23(): ?array |
||
808 | |||
809 | /** |
||
810 | * @param array $room23 |
||
811 | * @return self |
||
812 | */ |
||
813 | public function setRoom23(array $room23): self |
||
819 | |||
820 | /** |
||
821 | * @return array |
||
822 | */ |
||
823 | public function getRoom24(): ?array |
||
827 | |||
828 | /** |
||
829 | * @param array $room24 |
||
830 | * @return self |
||
831 | */ |
||
832 | public function setRoom24(array $room24): self |
||
838 | |||
839 | /** |
||
840 | * @return array |
||
841 | */ |
||
842 | public function getRoom25(): ?array |
||
846 | |||
847 | /** |
||
848 | * @param array $room25 |
||
849 | * @return self |
||
850 | */ |
||
851 | public function setRoom25(array $room25): self |
||
857 | |||
858 | /** |
||
859 | * @return array |
||
860 | */ |
||
861 | public function getRoom26(): ?array |
||
865 | |||
866 | /** |
||
867 | * @param array $room26 |
||
868 | * @return self |
||
869 | */ |
||
870 | public function setRoom26(array $room26): self |
||
876 | |||
877 | /** |
||
878 | * @return array |
||
879 | */ |
||
880 | public function getRoom27(): ?array |
||
884 | |||
885 | /** |
||
886 | * @param array $room27 |
||
887 | * @return self |
||
888 | */ |
||
889 | public function setRoom27(array $room27): self |
||
895 | |||
896 | /** |
||
897 | * @return array |
||
898 | */ |
||
899 | public function getRoom28(): ?array |
||
903 | |||
904 | /** |
||
905 | * @param array $room28 |
||
906 | * @return self |
||
907 | */ |
||
908 | public function setRoom28(array $room28): self |
||
914 | |||
915 | /** |
||
916 | * @return array |
||
917 | */ |
||
918 | public function getRoom29(): ?array |
||
922 | |||
923 | /** |
||
924 | * @param array $room29 |
||
925 | * @return self |
||
926 | */ |
||
927 | public function setRoom29(array $room29): self |
||
933 | |||
934 | /** |
||
935 | * @return array |
||
936 | */ |
||
937 | public function getRoom30(): ?array |
||
941 | |||
942 | /** |
||
943 | * @param array $room30 |
||
944 | * @return self |
||
945 | */ |
||
946 | public function setRoom30(array $room30): self |
||
952 | |||
953 | /** |
||
954 | * @return array |
||
955 | */ |
||
956 | public function getExtras(): ?array |
||
960 | |||
961 | /** |
||
962 | * @param array $extras |
||
963 | * @return self |
||
964 | */ |
||
965 | public function setExtras(array $extras): self |
||
971 | |||
972 | public function withExtras() |
||
986 | |||
987 | /** |
||
988 | * @return int |
||
989 | */ |
||
990 | public function getOffset(): ?int |
||
994 | |||
995 | /** |
||
996 | * @param int $offset |
||
997 | * @return self |
||
998 | */ |
||
999 | public function setOffset(int $offset): self |
||
1005 | |||
1006 | /** |
||
1007 | * @return string |
||
1008 | */ |
||
1009 | public function getCurrency(): ?string |
||
1013 | |||
1014 | /** |
||
1015 | * @param string $currency |
||
1016 | * @return self |
||
1017 | */ |
||
1018 | public function setCurrency(string $currency): self |
||
1024 | |||
1025 | /** |
||
1026 | * @return string |
||
1027 | */ |
||
1028 | public function getOrderBy(): ?string |
||
1032 | |||
1033 | /** |
||
1034 | * @param string $order_by |
||
1035 | * @return self |
||
1036 | */ |
||
1037 | public function setOrderBy(string $order_by): self |
||
1043 | |||
1044 | /** |
||
1045 | * @return string |
||
1046 | */ |
||
1047 | public function getOrderDir(): ?string |
||
1051 | |||
1052 | /** |
||
1053 | * @param string $order_dir |
||
1054 | * @return self |
||
1055 | */ |
||
1056 | public function setOrderDir(string $order_dir): self |
||
1062 | |||
1063 | /** |
||
1064 | * @return array |
||
1065 | */ |
||
1066 | public function getFilter(): ?array |
||
1070 | |||
1071 | /** |
||
1072 | * @param array $filter |
||
1073 | * @return self |
||
1074 | */ |
||
1075 | public function setFilter(array $filter): self |
||
1081 | |||
1082 | protected function getAttributeMap(): array |
||
1131 | |||
1132 | /** |
||
1133 | * Specify Model class name. |
||
1134 | * |
||
1135 | * @return string |
||
1136 | */ |
||
1137 | protected function model(): string |
||
1141 | } |
||
1142 |