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 |
||
| 51 | class Client |
||
| 52 | { |
||
| 53 | /** |
||
| 54 | * Amadeus SOAP header version 1 |
||
| 55 | */ |
||
| 56 | const HEADER_V1 = "1"; |
||
| 57 | /** |
||
| 58 | * Amadeus SOAP header version 2 |
||
| 59 | */ |
||
| 60 | const HEADER_V2 = "2"; |
||
| 61 | /** |
||
| 62 | * Amadeus SOAP header version 4 |
||
| 63 | */ |
||
| 64 | const HEADER_V4 = "4"; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Version string |
||
| 68 | * |
||
| 69 | * @var string |
||
| 70 | */ |
||
| 71 | const version = "0.0.1dev"; |
||
| 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 | * Set the session as stateful (true) or stateless (false) |
||
| 109 | * |
||
| 110 | * @param bool $newStateful |
||
| 111 | */ |
||
| 112 | public function setStateful($newStateful) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return bool |
||
| 119 | */ |
||
| 120 | public function isStateful() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Get the last raw XML message that was sent out |
||
| 127 | * |
||
| 128 | * @return string|null |
||
| 129 | */ |
||
| 130 | public function getLastRequest() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Get the last raw XML message that was received |
||
| 137 | * |
||
| 138 | * @return string|null |
||
| 139 | */ |
||
| 140 | public function getLastResponse() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Get session information for authenticated session |
||
| 147 | * |
||
| 148 | * - sessionId |
||
| 149 | * - sequenceNr |
||
| 150 | * - securityToken |
||
| 151 | * |
||
| 152 | * @return array|null |
||
| 153 | */ |
||
| 154 | public function getSessionData() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Restore a previously used session |
||
| 161 | * |
||
| 162 | * To be used when implementing your own session pooling system on legacy Soap Header 2 applications. |
||
| 163 | * |
||
| 164 | * @param array $sessionData |
||
| 165 | * @return bool |
||
| 166 | */ |
||
| 167 | public function setSessionData(array $sessionData) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Construct Amadeus Web Services client |
||
| 174 | * |
||
| 175 | * @param Params $params |
||
| 176 | */ |
||
| 177 | public function __construct($params) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Authenticate. |
||
| 206 | * |
||
| 207 | * Parameters were provided at construction time (sessionhandlerparams) |
||
| 208 | * |
||
| 209 | * @return Result |
||
| 210 | * @throws Exception |
||
| 211 | */ |
||
| 212 | public function securityAuthenticate() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Terminate a session - only applicable to non-stateless mode. |
||
| 228 | * |
||
| 229 | * @return Result |
||
| 230 | * @throws Exception |
||
| 231 | */ |
||
| 232 | public function securitySignOut() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * PNR_Retrieve - Retrieve an Amadeus PNR by record locator |
||
| 246 | * |
||
| 247 | * By default, the result will be the PNR_Reply XML as string. |
||
| 248 | * That way you can easily parse the PNR's contents with XPath. |
||
| 249 | * |
||
| 250 | * https://webservices.amadeus.com/extranet/viewService.do?id=27&flavourId=1&menuId=functional |
||
| 251 | * |
||
| 252 | * @param RequestOptions\PnrRetrieveOptions $options |
||
| 253 | * @param array $messageOptions (OPTIONAL) Set ['asString'] = 'false' to get PNR_Reply as a PHP object. |
||
| 254 | * @return Result |
||
| 255 | * @throws Exception |
||
| 256 | */ |
||
| 257 | public function pnrRetrieve(RequestOptions\PnrRetrieveOptions $options, $messageOptions = []) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Create a PNR using PNR_AddMultiElements |
||
| 266 | * |
||
| 267 | * @param RequestOptions\PnrCreatePnrOptions $options |
||
| 268 | * @param array $messageOptions |
||
| 269 | * @return Result |
||
| 270 | */ |
||
| 271 | public function pnrCreatePnr(RequestOptions\PnrCreatePnrOptions $options, $messageOptions = []) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * PNR_AddMultiElements - Create a new PNR or update an existing PNR. |
||
| 280 | * |
||
| 281 | * https://webservices.amadeus.com/extranet/viewService.do?id=25&flavourId=1&menuId=functional |
||
| 282 | * |
||
| 283 | * @todo implement message creation - maybe split up in separate Create & Modify PNR? |
||
| 284 | * @param RequestOptions\PnrAddMultiElementsOptions $options |
||
| 285 | * @param array $messageOptions |
||
| 286 | * @return Result |
||
| 287 | */ |
||
| 288 | public function pnrAddMultiElements(RequestOptions\PnrAddMultiElementsOptions $options, $messageOptions = []) |
||
| 294 | |||
| 295 | /** |
||
| 296 | * PNR_RetrieveAndDisplay - Retrieve an Amadeus PNR by record locator including extra info |
||
| 297 | * |
||
| 298 | * This extra info is info you cannot see in the regular PNR, like Offers. |
||
| 299 | * |
||
| 300 | * By default, the result will be the PNR_RetrieveAndDisplayReply XML as string. |
||
| 301 | * That way you can easily parse the PNR's contents with XPath. |
||
| 302 | * |
||
| 303 | * Set $messageOptions['asString'] = FALSE to get the response as a PHP object. |
||
| 304 | * |
||
| 305 | * https://webservices.amadeus.com/extranet/viewService.do?id=1922&flavourId=1&menuId=functional |
||
| 306 | * |
||
| 307 | * @param RequestOptions\PnrRetrieveAndDisplayOptions $options Amadeus Record Locator for PNR |
||
| 308 | * @param array $messageOptions (OPTIONAL) Set ['asString'] = 'false' to get PNR_RetrieveAndDisplayReply as a PHP object. |
||
| 309 | * @return Result |
||
| 310 | * @throws Exception |
||
| 311 | **/ |
||
| 312 | public function pnrRetrieveAndDisplay(RequestOptions\PnrRetrieveAndDisplayOptions $options, $messageOptions = []) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * PNR_Cancel |
||
| 321 | * |
||
| 322 | * @param RequestOptions\PnrCancelOptions $options |
||
| 323 | * @param array $messageOptions |
||
| 324 | * @return Result |
||
| 325 | */ |
||
| 326 | public function pnrCancel(RequestOptions\PnrCancelOptions $options, $messageOptions = []) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * PNR_DisplayHistory |
||
| 335 | * |
||
| 336 | * @param RequestOptions\PnrDisplayHistoryOptions $options |
||
| 337 | * @param array $messageOptions |
||
| 338 | * @return Result |
||
| 339 | */ |
||
| 340 | public function pnrDisplayHistory(RequestOptions\PnrDisplayHistoryOptions $options, $messageOptions = []) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Queue_List - get a list of all PNR's on a given queue |
||
| 349 | * |
||
| 350 | * https://webservices.amadeus.com/extranet/viewService.do?id=52&flavourId=1&menuId=functional |
||
| 351 | * |
||
| 352 | * @param RequestOptions\QueueListOptions $options |
||
| 353 | * @param array $messageOptions |
||
| 354 | * @return Result |
||
| 355 | */ |
||
| 356 | public function queueList(RequestOptions\QueueListOptions $options, $messageOptions = []) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Queue_PlacePNR - Place a PNR on a given queue |
||
| 365 | * |
||
| 366 | * @param RequestOptions\QueuePlacePnrOptions $options |
||
| 367 | * @param array $messageOptions |
||
| 368 | * @return Result |
||
| 369 | */ |
||
| 370 | public function queuePlacePnr(RequestOptions\QueuePlacePnrOptions $options, $messageOptions = []) |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Queue_RemoveItem - remove an item (a PNR) from a given queue |
||
| 379 | * |
||
| 380 | * @param RequestOptions\QueueRemoveItemOptions $options |
||
| 381 | * @param array $messageOptions |
||
| 382 | * @return Result |
||
| 383 | */ |
||
| 384 | public function queueRemoveItem(RequestOptions\QueueRemoveItemOptions $options, $messageOptions = []) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Queue_MoveItem - move an item (a PNR) from one queue to another. |
||
| 393 | * |
||
| 394 | * @param RequestOptions\QueueMoveItemOptions $options |
||
| 395 | * @param array $messageOptions |
||
| 396 | * @return Result |
||
| 397 | */ |
||
| 398 | public function queueMoveItem(RequestOptions\QueueMoveItemOptions $options, $messageOptions = []) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Offer_VerifyOffer |
||
| 407 | * |
||
| 408 | * To be called in the context of an open PNR |
||
| 409 | * |
||
| 410 | * @param RequestOptions\OfferVerifyOptions $options |
||
| 411 | * @param array $messageOptions |
||
| 412 | * @return Result |
||
| 413 | */ |
||
| 414 | public function offerVerify(RequestOptions\OfferVerifyOptions $options, $messageOptions = []) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Offer_ConfirmAirOffer |
||
| 423 | * |
||
| 424 | * @param RequestOptions\OfferConfirmAirOptions $options |
||
| 425 | * @param array $messageOptions |
||
| 426 | * @return Result |
||
| 427 | */ |
||
| 428 | public function offerConfirmAir(RequestOptions\OfferConfirmAirOptions $options, $messageOptions = []) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Offer_ConfirmHotelOffer |
||
| 437 | * |
||
| 438 | * @param RequestOptions\OfferConfirmHotelOptions $options |
||
| 439 | * @param array $messageOptions |
||
| 440 | * @return Result |
||
| 441 | */ |
||
| 442 | public function offerConfirmHotel(RequestOptions\OfferConfirmHotelOptions $options, $messageOptions = []) |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Offer_ConfirmCarOffer |
||
| 451 | * |
||
| 452 | * @param RequestOptions\OfferConfirmCarOptions $options |
||
| 453 | * @param array $messageOptions |
||
| 454 | * @return Result |
||
| 455 | */ |
||
| 456 | public function offerConfirmCar(RequestOptions\OfferConfirmCarOptions $options, $messageOptions = []) |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Fare_MasterPricerTravelBoardSearch |
||
| 465 | * |
||
| 466 | * @param RequestOptions\FareMasterPricerTbSearch $options |
||
| 467 | * @param array $messageOptions |
||
| 468 | * @return Result |
||
| 469 | */ |
||
| 470 | public function fareMasterPricerTravelBoardSearch(RequestOptions\FareMasterPricerTbSearch $options, $messageOptions = []) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Fare_PricePnrWithBookingClass |
||
| 479 | * |
||
| 480 | * @param RequestOptions\FarePricePnrWithBookingClassOptions $options |
||
| 481 | * @param array $messageOptions |
||
| 482 | * @return Result |
||
| 483 | */ |
||
| 484 | public function farePricePnrWithBookingClass(RequestOptions\FarePricePnrWithBookingClassOptions $options, $messageOptions = []) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Fare_InformativePricingWithoutPNR |
||
| 493 | * |
||
| 494 | * @param RequestOptions\FareInformativePricingWithoutPnrOptions $options |
||
| 495 | * @param array $messageOptions |
||
| 496 | * @return Result |
||
| 497 | */ |
||
| 498 | public function fareInformativePricingWithoutPnr(RequestOptions\FareInformativePricingWithoutPnrOptions $options, $messageOptions = []) |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Fare_CheckRules |
||
| 507 | * |
||
| 508 | * @param RequestOptions\FareCheckRulesOptions $options |
||
| 509 | * @param array $messageOptions |
||
| 510 | * @return Result |
||
| 511 | */ |
||
| 512 | public function fareCheckRules(RequestOptions\FareCheckRulesOptions $options, $messageOptions = []) |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Fare_ConvertCurrency |
||
| 521 | * |
||
| 522 | * @param RequestOptions\FareConvertCurrencyOptions $options |
||
| 523 | * @param array $messageOptions |
||
| 524 | * @return Result |
||
| 525 | */ |
||
| 526 | public function fareConvertCurrency(RequestOptions\FareConvertCurrencyOptions $options, $messageOptions = []) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Air_SellFromRecommendation |
||
| 535 | * |
||
| 536 | * @param RequestOptions\AirSellFromRecommendationOptions $options |
||
| 537 | * @param array $messageOptions |
||
| 538 | * @return Result |
||
| 539 | */ |
||
| 540 | public function airSellFromRecommendation(RequestOptions\AirSellFromRecommendationOptions $options, $messageOptions = []) |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Air_FlightInfo |
||
| 549 | * |
||
| 550 | * @param RequestOptions\AirFlightInfoOptions $options |
||
| 551 | * @param array $messageOptions |
||
| 552 | * @return Result |
||
| 553 | */ |
||
| 554 | public function airFlightInfo(RequestOptions\AirFlightInfoOptions $options, $messageOptions = []) |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Air_RetrieveSeatMap |
||
| 563 | * |
||
| 564 | * @param RequestOptions\AirRetrieveSeatMapOptions $options |
||
| 565 | * @param array $messageOptions |
||
| 566 | * @return Result |
||
| 567 | */ |
||
| 568 | public function airRetrieveSeatMap(RequestOptions\AirRetrieveSeatMapOptions $options, $messageOptions = []) |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Command_Cryptic |
||
| 577 | * |
||
| 578 | * @param RequestOptions\CommandCrypticOptions $options |
||
| 579 | * @param array $messageOptions |
||
| 580 | * @return Result |
||
| 581 | */ |
||
| 582 | public function commandCryptic(RequestOptions\CommandCrypticOptions $options, $messageOptions = []) |
||
| 588 | |||
| 589 | /** |
||
| 590 | * MiniRule_GetFromPricingRec |
||
| 591 | * |
||
| 592 | * @param RequestOptions\MiniRuleGetFromPricingRecOptions $options |
||
| 593 | * @param array $messageOptions |
||
| 594 | * @return Result |
||
| 595 | */ |
||
| 596 | public function miniRuleGetFromPricingRec(RequestOptions\MiniRuleGetFromPricingRecOptions $options, $messageOptions = []) |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Info_EncodeDecodeCity |
||
| 605 | * |
||
| 606 | * @param RequestOptions\InfoEncodeDecodeCityOptions $options |
||
| 607 | * @param array $messageOptions |
||
| 608 | * @return Result |
||
| 609 | */ |
||
| 610 | public function infoEncodeDecodeCity(RequestOptions\InfoEncodeDecodeCityOptions $options, $messageOptions = []) |
||
| 616 | |||
| 617 | |||
| 618 | /** |
||
| 619 | * Ticket_CreateTSTFromPricing |
||
| 620 | * |
||
| 621 | * @param RequestOptions\TicketCreateTstFromPricingOptions $options |
||
| 622 | * @param array $messageOptions |
||
| 623 | * @return Result |
||
| 624 | */ |
||
| 625 | public function ticketCreateTSTFromPricing(RequestOptions\TicketCreateTstFromPricingOptions $options, $messageOptions = []) |
||
| 631 | |||
| 632 | /** |
||
| 633 | * DocIssuance_IssueTicket |
||
| 634 | * |
||
| 635 | * @param RequestOptions\DocIssuanceIssueTicketOptions $options |
||
| 636 | * @param array $messageOptions |
||
| 637 | * @return Result |
||
| 638 | */ |
||
| 639 | public function docIssuanceIssueTicket(RequestOptions\DocIssuanceIssueTicketOptions $options, $messageOptions = []) |
||
| 645 | |||
| 646 | /** |
||
| 647 | * PriceXplorer_ExtremeSearch |
||
| 648 | * |
||
| 649 | * @param RequestOptions\PriceXplorerExtremeSearchOptions $options |
||
| 650 | * @param array $messageOptions |
||
| 651 | * @return Result |
||
| 652 | */ |
||
| 653 | public function priceXplorerExtremeSearch(RequestOptions\PriceXplorerExtremeSearchOptions $options, $messageOptions = []) |
||
| 659 | |||
| 660 | /** |
||
| 661 | * Call a message with the given parameters |
||
| 662 | * |
||
| 663 | * @param string $messageName |
||
| 664 | * @param RequestOptions\RequestOptionsInterface $options |
||
| 665 | * @param array $messageOptions |
||
| 666 | * @param bool $endSession |
||
| 667 | * @return Result |
||
| 668 | * @throws Client\Exception |
||
| 669 | * @throws Client\Struct\InvalidArgumentException |
||
| 670 | * @throws Client\InvalidMessageException |
||
| 671 | * @throws Client\RequestCreator\MessageVersionUnsupportedException |
||
| 672 | * @throws \RuntimeException |
||
| 673 | * @throws \InvalidArgumentException |
||
| 674 | * @throws \SoapFault |
||
| 675 | */ |
||
| 676 | protected function callMessage($messageName, $options, $messageOptions, $endSession = false) |
||
| 694 | |||
| 695 | /** |
||
| 696 | * Make message options |
||
| 697 | * |
||
| 698 | * Message options are meta options when sending a message to the amadeus web services |
||
| 699 | * - (if stateful) should we end the current session after sending this call? |
||
| 700 | * - do you want the response as a PHP object or as a string? |
||
| 701 | * - ... ? |
||
| 702 | * |
||
| 703 | * @param array $incoming The Message options chosen by the caller - if any. |
||
| 704 | * @param bool $endSession Switch if you want to terminate the current session after making the call. |
||
| 705 | * @return array |
||
| 706 | */ |
||
| 707 | protected function makeMessageOptions(array $incoming, $endSession = false) |
||
| 719 | |||
| 720 | /** |
||
| 721 | * Load the session handler |
||
| 722 | * |
||
| 723 | * Either load the provided session handler or create one depending on incoming parameters. |
||
| 724 | * |
||
| 725 | * @param HandlerInterface|null $sessionHandler |
||
| 726 | * @param Params\SessionHandlerParams $params |
||
| 727 | * @return HandlerInterface |
||
| 728 | */ |
||
| 729 | protected function loadSessionHandler($sessionHandler, $params) |
||
| 741 | |||
| 742 | /** |
||
| 743 | * Load a request creator |
||
| 744 | * |
||
| 745 | * A request creator is responsible for generating the correct request to send. |
||
| 746 | * |
||
| 747 | * @param RequestCreatorInterface|null $requestCreator |
||
| 748 | * @param Params\RequestCreatorParams $params |
||
| 749 | * @param string $libIdentifier Library identifier & version string (for Received From) |
||
| 750 | * @param string $originatorOffice The Office we are signed in with. |
||
| 751 | * @param array $mesVer Messages & Versions array of active messages in the WSDL |
||
| 752 | * @return RequestCreatorInterface |
||
| 753 | * @throws \RuntimeException |
||
| 754 | */ |
||
| 755 | protected function loadRequestCreator($requestCreator, $params, $libIdentifier, $originatorOffice, $mesVer) |
||
| 773 | |||
| 774 | /** |
||
| 775 | * Load a response handler |
||
| 776 | * |
||
| 777 | * @param ResponseHandlerInterface|null $responseHandler |
||
| 778 | * |
||
| 779 | * @return ResponseHandlerInterface |
||
| 780 | * @throws \RuntimeException |
||
| 781 | */ |
||
| 782 | protected function loadResponseHandler($responseHandler) |
||
| 794 | } |
||
| 795 |
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.