Complex classes like Client 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 Client, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
50 | class Client |
||
51 | { |
||
52 | /** |
||
53 | * Amadeus SOAP header version 1 |
||
54 | */ |
||
55 | const HEADER_V1 = "1"; |
||
56 | /** |
||
57 | * Amadeus SOAP header version 2 |
||
58 | */ |
||
59 | const HEADER_V2 = "2"; |
||
60 | /** |
||
61 | * Amadeus SOAP header version 4 |
||
62 | */ |
||
63 | const HEADER_V4 = "4"; |
||
64 | |||
65 | /** |
||
66 | * Version string |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | const version = "0.0.1dev"; |
||
71 | |||
72 | /** |
||
73 | * An identifier string for the library (to be used in Received From entries) |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | const receivedFromIdentifier = "amabnl-amadeus-ws-client"; |
||
78 | |||
79 | /** |
||
80 | * Session Handler will be sending all the messages and handling all session-related things. |
||
81 | * |
||
82 | * @var HandlerInterface |
||
83 | */ |
||
84 | protected $sessionHandler; |
||
85 | |||
86 | /** |
||
87 | * Request Creator is will create the correct message structure to send to the SOAP server. |
||
88 | * |
||
89 | * @var RequestCreatorInterface |
||
90 | */ |
||
91 | protected $requestCreator; |
||
92 | |||
93 | /** |
||
94 | * Response Handler will check the received response for errors. |
||
95 | * |
||
96 | * @var ResponseHandlerInterface |
||
97 | */ |
||
98 | protected $responseHandler; |
||
99 | |||
100 | /** |
||
101 | * Authentication parameters |
||
102 | * |
||
103 | * @var Params\AuthParams |
||
104 | */ |
||
105 | protected $authParams; |
||
106 | |||
107 | /** |
||
108 | * @var string |
||
109 | */ |
||
110 | protected $lastMessage; |
||
111 | |||
112 | /** |
||
113 | * Set the session as stateful (true) or stateless (false) |
||
114 | * |
||
115 | * @param bool $newStateful |
||
116 | */ |
||
117 | public function setStateful($newStateful) |
||
121 | |||
122 | /** |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function isStateful() |
||
129 | |||
130 | /** |
||
131 | * Get the last raw XML message that was sent out |
||
132 | * |
||
133 | * @return string|null |
||
134 | */ |
||
135 | public function getLastRequest() |
||
139 | |||
140 | /** |
||
141 | * Get the last raw XML message that was received |
||
142 | * |
||
143 | * @return string|null |
||
144 | */ |
||
145 | public function getLastResponse() |
||
149 | |||
150 | /** |
||
151 | * Get session information for authenticated session |
||
152 | * |
||
153 | * - sessionId |
||
154 | * - sequenceNr |
||
155 | * - securityToken |
||
156 | * |
||
157 | * @return array|null |
||
158 | */ |
||
159 | public function getSessionData() |
||
163 | |||
164 | /** |
||
165 | * Restore a previously used session |
||
166 | * |
||
167 | * To be used when implementing your own session pooling system on legacy Soap Header 2 applications. |
||
168 | * |
||
169 | * @param array $sessionData |
||
170 | * @return bool |
||
171 | */ |
||
172 | public function setSessionData(array $sessionData) |
||
176 | |||
177 | /** |
||
178 | * Construct Amadeus Web Services client |
||
179 | * |
||
180 | * @param Params $params |
||
181 | */ |
||
182 | public function __construct($params) |
||
208 | |||
209 | /** |
||
210 | * Authenticate. |
||
211 | * |
||
212 | * Parameters were provided at construction time (sessionhandlerparams) |
||
213 | * |
||
214 | * @return Result |
||
215 | * @throws Exception |
||
216 | */ |
||
217 | public function securityAuthenticate() |
||
230 | |||
231 | /** |
||
232 | * Terminate a session - only applicable to non-stateless mode. |
||
233 | * |
||
234 | * @return Result |
||
235 | * @throws Exception |
||
236 | */ |
||
237 | public function securitySignOut() |
||
248 | |||
249 | /** |
||
250 | * PNR_Retrieve - Retrieve an Amadeus PNR by record locator |
||
251 | * |
||
252 | * By default, the result will be the PNR_Reply XML as string. |
||
253 | * That way you can easily parse the PNR's contents with XPath. |
||
254 | * |
||
255 | * https://webservices.amadeus.com/extranet/viewService.do?id=27&flavourId=1&menuId=functional |
||
256 | * |
||
257 | * @param RequestOptions\PnrRetrieveOptions $options |
||
258 | * @param array $messageOptions (OPTIONAL) Set ['asString'] = 'false' to get PNR_Reply as a PHP object. |
||
259 | * @return Result |
||
260 | * @throws Exception |
||
261 | */ |
||
262 | public function pnrRetrieve(RequestOptions\PnrRetrieveOptions $options, $messageOptions = []) |
||
268 | |||
269 | /** |
||
270 | * Create a PNR using PNR_AddMultiElements |
||
271 | * |
||
272 | * @param RequestOptions\PnrCreatePnrOptions $options |
||
273 | * @param array $messageOptions |
||
274 | * @return Result |
||
275 | */ |
||
276 | public function pnrCreatePnr(RequestOptions\PnrCreatePnrOptions $options, $messageOptions = []) |
||
282 | |||
283 | /** |
||
284 | * PNR_AddMultiElements - Create a new PNR or update an existing PNR. |
||
285 | * |
||
286 | * https://webservices.amadeus.com/extranet/viewService.do?id=25&flavourId=1&menuId=functional |
||
287 | * |
||
288 | * @todo implement message creation - maybe split up in separate Create & Modify PNR? |
||
289 | * @param RequestOptions\PnrAddMultiElementsOptions $options |
||
290 | * @param array $messageOptions |
||
291 | * @return Result |
||
292 | */ |
||
293 | public function pnrAddMultiElements(RequestOptions\PnrAddMultiElementsOptions $options, $messageOptions = []) |
||
299 | |||
300 | /** |
||
301 | * PNR_RetrieveAndDisplay - Retrieve an Amadeus PNR by record locator including extra info |
||
302 | * |
||
303 | * This extra info is info you cannot see in the regular PNR, like Offers. |
||
304 | * |
||
305 | * By default, the result will be the PNR_RetrieveAndDisplayReply XML as string. |
||
306 | * That way you can easily parse the PNR's contents with XPath. |
||
307 | * |
||
308 | * Set $messageOptions['asString'] = FALSE to get the response as a PHP object. |
||
309 | * |
||
310 | * https://webservices.amadeus.com/extranet/viewService.do?id=1922&flavourId=1&menuId=functional |
||
311 | * |
||
312 | * @param RequestOptions\PnrRetrieveAndDisplayOptions $options Amadeus Record Locator for PNR |
||
313 | * @param array $messageOptions (OPTIONAL) Set ['asString'] = 'false' to get PNR_RetrieveAndDisplayReply as a PHP object. |
||
314 | * @return Result |
||
315 | * @throws Exception |
||
316 | **/ |
||
317 | public function pnrRetrieveAndDisplay(RequestOptions\PnrRetrieveAndDisplayOptions $options, $messageOptions = []) |
||
323 | |||
324 | /** |
||
325 | * PNR_Cancel |
||
326 | * |
||
327 | * @param RequestOptions\PnrCancelOptions $options |
||
328 | * @param array $messageOptions |
||
329 | * @return Result |
||
330 | */ |
||
331 | public function pnrCancel(RequestOptions\PnrCancelOptions $options, $messageOptions = []) |
||
337 | |||
338 | /** |
||
339 | * PNR_DisplayHistory |
||
340 | * |
||
341 | * @param RequestOptions\PnrDisplayHistoryOptions $options |
||
342 | * @param array $messageOptions |
||
343 | * @return Result |
||
344 | */ |
||
345 | public function pnrDisplayHistory(RequestOptions\PnrDisplayHistoryOptions $options, $messageOptions = []) |
||
351 | |||
352 | /** |
||
353 | * Queue_List - get a list of all PNR's on a given queue |
||
354 | * |
||
355 | * https://webservices.amadeus.com/extranet/viewService.do?id=52&flavourId=1&menuId=functional |
||
356 | * |
||
357 | * @param RequestOptions\QueueListOptions $options |
||
358 | * @param array $messageOptions |
||
359 | * @return Result |
||
360 | */ |
||
361 | public function queueList(RequestOptions\QueueListOptions $options, $messageOptions = []) |
||
367 | |||
368 | /** |
||
369 | * Queue_PlacePNR - Place a PNR on a given queue |
||
370 | * |
||
371 | * @param RequestOptions\QueuePlacePnrOptions $options |
||
372 | * @param array $messageOptions |
||
373 | * @return Result |
||
374 | */ |
||
375 | public function queuePlacePnr(RequestOptions\QueuePlacePnrOptions $options, $messageOptions = []) |
||
381 | |||
382 | /** |
||
383 | * Queue_RemoveItem - remove an item (a PNR) from a given queue |
||
384 | * |
||
385 | * @param RequestOptions\QueueRemoveItemOptions $options |
||
386 | * @param array $messageOptions |
||
387 | * @return Result |
||
388 | */ |
||
389 | public function queueRemoveItem(RequestOptions\QueueRemoveItemOptions $options, $messageOptions = []) |
||
395 | |||
396 | /** |
||
397 | * Queue_MoveItem - move an item (a PNR) from one queue to another. |
||
398 | * |
||
399 | * @param RequestOptions\QueueMoveItemOptions $options |
||
400 | * @param array $messageOptions |
||
401 | * @return Result |
||
402 | */ |
||
403 | public function queueMoveItem(RequestOptions\QueueMoveItemOptions $options, $messageOptions = []) |
||
409 | |||
410 | /** |
||
411 | * Offer_VerifyOffer |
||
412 | * |
||
413 | * To be called in the context of an open PNR |
||
414 | * |
||
415 | * @param RequestOptions\OfferVerifyOptions $options |
||
416 | * @param array $messageOptions |
||
417 | * @return Result |
||
418 | */ |
||
419 | public function offerVerify(RequestOptions\OfferVerifyOptions $options, $messageOptions = []) |
||
425 | |||
426 | /** |
||
427 | * Offer_ConfirmAirOffer |
||
428 | * |
||
429 | * @param RequestOptions\OfferConfirmAirOptions $options |
||
430 | * @param array $messageOptions |
||
431 | * @return Result |
||
432 | */ |
||
433 | public function offerConfirmAir(RequestOptions\OfferConfirmAirOptions $options, $messageOptions = []) |
||
439 | |||
440 | /** |
||
441 | * Offer_ConfirmHotelOffer |
||
442 | * |
||
443 | * @param RequestOptions\OfferConfirmHotelOptions $options |
||
444 | * @param array $messageOptions |
||
445 | * @return Result |
||
446 | */ |
||
447 | public function offerConfirmHotel(RequestOptions\OfferConfirmHotelOptions $options, $messageOptions = []) |
||
453 | |||
454 | /** |
||
455 | * Offer_ConfirmCarOffer |
||
456 | * |
||
457 | * @param RequestOptions\OfferConfirmCarOptions $options |
||
458 | * @param array $messageOptions |
||
459 | * @return Result |
||
460 | */ |
||
461 | public function offerConfirmCar(RequestOptions\OfferConfirmCarOptions $options, $messageOptions = []) |
||
467 | |||
468 | /** |
||
469 | * Fare_MasterPricerTravelBoardSearch |
||
470 | * |
||
471 | * @param RequestOptions\FareMasterPricerTbSearch $options |
||
472 | * @param array $messageOptions |
||
473 | * @return Result |
||
474 | */ |
||
475 | public function fareMasterPricerTravelBoardSearch(RequestOptions\FareMasterPricerTbSearch $options, $messageOptions = []) |
||
481 | |||
482 | /** |
||
483 | * Fare_PricePnrWithBookingClass |
||
484 | * |
||
485 | * @param RequestOptions\FarePricePnrWithBookingClassOptions $options |
||
486 | * @param array $messageOptions |
||
487 | * @return Result |
||
488 | */ |
||
489 | public function farePricePnrWithBookingClass(RequestOptions\FarePricePnrWithBookingClassOptions $options, $messageOptions = []) |
||
495 | |||
496 | /** |
||
497 | * Fare_InformativePricingWithoutPNR |
||
498 | * |
||
499 | * @param RequestOptions\FareInformativePricingWithoutPnrOptions $options |
||
500 | * @param array $messageOptions |
||
501 | * @return Result |
||
502 | */ |
||
503 | public function fareInformativePricingWithoutPnr(RequestOptions\FareInformativePricingWithoutPnrOptions $options, $messageOptions = []) |
||
509 | |||
510 | /** |
||
511 | * Fare_CheckRules |
||
512 | * |
||
513 | * @param RequestOptions\FareCheckRulesOptions $options |
||
514 | * @param array $messageOptions |
||
515 | * @return Result |
||
516 | */ |
||
517 | public function fareCheckRules(RequestOptions\FareCheckRulesOptions $options, $messageOptions = []) |
||
523 | |||
524 | /** |
||
525 | * Fare_ConvertCurrency |
||
526 | * |
||
527 | * @param RequestOptions\FareConvertCurrencyOptions $options |
||
528 | * @param array $messageOptions |
||
529 | * @return Result |
||
530 | */ |
||
531 | public function fareConvertCurrency(RequestOptions\FareConvertCurrencyOptions $options, $messageOptions = []) |
||
537 | |||
538 | /** |
||
539 | * Air_SellFromRecommendation |
||
540 | * |
||
541 | * @param RequestOptions\AirSellFromRecommendationOptions $options |
||
542 | * @param array $messageOptions |
||
543 | * @return Result |
||
544 | */ |
||
545 | public function airSellFromRecommendation(RequestOptions\AirSellFromRecommendationOptions $options, $messageOptions = []) |
||
551 | |||
552 | /** |
||
553 | * Air_FlightInfo |
||
554 | * |
||
555 | * @param RequestOptions\AirFlightInfoOptions $options |
||
556 | * @param array $messageOptions |
||
557 | * @return Result |
||
558 | */ |
||
559 | public function airFlightInfo(RequestOptions\AirFlightInfoOptions $options, $messageOptions = []) |
||
565 | |||
566 | /** |
||
567 | * Air_RetrieveSeatMap |
||
568 | * |
||
569 | * @param RequestOptions\AirRetrieveSeatMapOptions $options |
||
570 | * @param array $messageOptions |
||
571 | * @return Result |
||
572 | */ |
||
573 | public function airRetrieveSeatMap(RequestOptions\AirRetrieveSeatMapOptions $options, $messageOptions = []) |
||
579 | |||
580 | /** |
||
581 | * Command_Cryptic |
||
582 | * |
||
583 | * @param RequestOptions\CommandCrypticOptions $options |
||
584 | * @param array $messageOptions |
||
585 | * @return Result |
||
586 | */ |
||
587 | public function commandCryptic(RequestOptions\CommandCrypticOptions $options, $messageOptions = []) |
||
593 | |||
594 | /** |
||
595 | * MiniRule_GetFromPricingRec |
||
596 | * |
||
597 | * @param RequestOptions\MiniRuleGetFromPricingRecOptions $options |
||
598 | * @param array $messageOptions |
||
599 | * @return Result |
||
600 | */ |
||
601 | public function miniRuleGetFromPricingRec(RequestOptions\MiniRuleGetFromPricingRecOptions $options, $messageOptions = []) |
||
607 | |||
608 | /** |
||
609 | * Info_EncodeDecodeCity |
||
610 | * |
||
611 | * @param RequestOptions\InfoEncodeDecodeCityOptions $options |
||
612 | * @param array $messageOptions |
||
613 | * @return Result |
||
614 | */ |
||
615 | public function infoEncodeDecodeCity(RequestOptions\InfoEncodeDecodeCityOptions $options, $messageOptions = []) |
||
621 | |||
622 | |||
623 | /** |
||
624 | * Ticket_CreateTSTFromPricing |
||
625 | * |
||
626 | * @param RequestOptions\TicketCreateTstFromPricingOptions $options |
||
627 | * @param array $messageOptions |
||
628 | * @return Result |
||
629 | */ |
||
630 | public function ticketCreateTSTFromPricing(RequestOptions\TicketCreateTstFromPricingOptions $options, $messageOptions = []) |
||
636 | |||
637 | /** |
||
638 | * DocIssuance_IssueTicket |
||
639 | * |
||
640 | * @param RequestOptions\DocIssuanceIssueTicketOptions $options |
||
641 | * @param array $messageOptions |
||
642 | * @return Result |
||
643 | */ |
||
644 | public function docIssuanceIssueTicket(RequestOptions\DocIssuanceIssueTicketOptions $options, $messageOptions = []) |
||
650 | |||
651 | /** |
||
652 | * PriceXplorer_ExtremeSearch |
||
653 | * |
||
654 | * @param RequestOptions\PriceXplorerExtremeSearchOptions $options |
||
655 | * @param array $messageOptions |
||
656 | * @return Result |
||
657 | */ |
||
658 | public function priceXplorerExtremeSearch(RequestOptions\PriceXplorerExtremeSearchOptions $options, $messageOptions = []) |
||
664 | |||
665 | /** |
||
666 | * SalesReports_DisplayQueryReport |
||
667 | * |
||
668 | * @param RequestOptions\SalesReportsDisplayQueryReportOptions $options |
||
669 | * @param array $messageOptions |
||
670 | * @return Result |
||
671 | */ |
||
672 | public function salesReportsDisplayQueryReport(RequestOptions\SalesReportsDisplayQueryReportOptions $options, $messageOptions = []) |
||
678 | |||
679 | /** |
||
680 | * Call a message with the given parameters |
||
681 | * |
||
682 | * @param string $messageName |
||
683 | * @param RequestOptions\RequestOptionsInterface $options |
||
684 | * @param array $messageOptions |
||
685 | * @param bool $endSession |
||
686 | * @return Result |
||
687 | * @throws Client\Exception |
||
688 | * @throws Client\Struct\InvalidArgumentException |
||
689 | * @throws Client\InvalidMessageException |
||
690 | * @throws Client\RequestCreator\MessageVersionUnsupportedException |
||
691 | * @throws \RuntimeException |
||
692 | * @throws \InvalidArgumentException |
||
693 | * @throws \SoapFault |
||
694 | */ |
||
695 | protected function callMessage($messageName, $options, $messageOptions, $endSession = false) |
||
715 | |||
716 | /** |
||
717 | * Make message options |
||
718 | * |
||
719 | * Message options are meta options when sending a message to the amadeus web services |
||
720 | * - (if stateful) should we end the current session after sending this call? |
||
721 | * - ... ? |
||
722 | * |
||
723 | * @param array $incoming The Message options chosen by the caller - if any. |
||
724 | * @param bool $endSession Switch if you want to terminate the current session after making the call. |
||
725 | * @return array |
||
726 | */ |
||
727 | protected function makeMessageOptions(array $incoming, $endSession = false) |
||
739 | |||
740 | /** |
||
741 | * Load the session handler |
||
742 | * |
||
743 | * Either load the provided session handler or create one depending on incoming parameters. |
||
744 | * |
||
745 | * @param HandlerInterface|null $sessionHandler |
||
746 | * @param Params\SessionHandlerParams $params |
||
747 | * @return HandlerInterface |
||
748 | */ |
||
749 | protected function loadSessionHandler($sessionHandler, $params) |
||
761 | |||
762 | /** |
||
763 | * Load a request creator |
||
764 | * |
||
765 | * A request creator is responsible for generating the correct request to send. |
||
766 | * |
||
767 | * @param RequestCreatorInterface|null $requestCreator |
||
768 | * @param Params\RequestCreatorParams $params |
||
769 | * @param string $libIdentifier Library identifier & version string (for Received From) |
||
770 | * @param string $originatorOffice The Office we are signed in with. |
||
771 | * @param array $mesVer Messages & Versions array of active messages in the WSDL |
||
772 | * @return RequestCreatorInterface |
||
773 | * @throws \RuntimeException |
||
774 | */ |
||
775 | protected function loadRequestCreator($requestCreator, $params, $libIdentifier, $originatorOffice, $mesVer) |
||
793 | |||
794 | /** |
||
795 | * Load a response handler |
||
796 | * |
||
797 | * @param ResponseHandlerInterface|null $responseHandler |
||
798 | * |
||
799 | * @return ResponseHandlerInterface |
||
800 | * @throws \RuntimeException |
||
801 | */ |
||
802 | protected function loadResponseHandler($responseHandler) |
||
814 | } |
||
815 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.