Complex classes like Base 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 Base, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 72 | class Base implements RequestCreatorInterface |
||
| 73 | { |
||
| 74 | /** |
||
| 75 | * @var RequestCreatorParams |
||
| 76 | */ |
||
| 77 | protected $params; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Associative array of messages (as keys) and versions (as values) that are present in the WSDL. |
||
| 81 | * |
||
| 82 | * @var array |
||
| 83 | */ |
||
| 84 | protected $messagesAndVersions = []; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param $params |
||
| 88 | */ |
||
| 89 | public function __construct(RequestCreatorParams $params) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param string $messageName the message name as named in the WSDL |
||
| 97 | * @param RequestOptionsInterface $params |
||
| 98 | * @throws Struct\InvalidArgumentException When invalid input is detected during message creation. |
||
| 99 | * @throws InvalidMessageException when trying to create a request for a message that is not in your WSDL. |
||
| 100 | * @return mixed the created request |
||
| 101 | */ |
||
| 102 | public function createRequest($messageName, RequestOptionsInterface $params) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return Struct\Security\SignOut |
||
| 117 | */ |
||
| 118 | protected function createSecuritySignOut() |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Create request object for Security_Authenticate message |
||
| 125 | * |
||
| 126 | * @param SecurityAuthenticateOptions $params |
||
| 127 | * @return Struct\Security\Authenticate |
||
| 128 | */ |
||
| 129 | protected function createSecurityAuthenticate(SecurityAuthenticateOptions $params) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Create request object for PNR_Retrieve message |
||
| 136 | * |
||
| 137 | * @param PnrRetrieveOptions $params |
||
| 138 | * @return Struct\Pnr\Retrieve |
||
| 139 | */ |
||
| 140 | protected function createPNRRetrieve(PnrRetrieveOptions $params) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @param PnrRetrieveAndDisplayOptions $params |
||
| 152 | * @return Struct\Pnr\RetrieveAndDisplay |
||
| 153 | */ |
||
| 154 | protected function createPNRRetrieveAndDisplay(PnrRetrieveAndDisplayOptions $params) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param PnrAddMultiElementsBase $params |
||
| 166 | * @return Struct\Pnr\AddMultiElements |
||
| 167 | */ |
||
| 168 | protected function createPNRAddMultiElements(PnrAddMultiElementsBase $params) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param PnrCancelOptions $params |
||
| 182 | * @return Struct\Pnr\Cancel |
||
| 183 | */ |
||
| 184 | protected function createPNRCancel(PnrCancelOptions $params) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @param PnrDisplayHistoryOptions $params |
||
| 191 | * @return Struct\Pnr\DisplayHistory |
||
| 192 | */ |
||
| 193 | protected function createPNRDisplayHistory(PnrDisplayHistoryOptions $params) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param PnrTransferOwnershipOptions $params |
||
| 200 | * @return Struct\Pnr\TransferOwnership |
||
| 201 | */ |
||
| 202 | protected function createPNRTransferOwnership(PnrTransferOwnershipOptions $params) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param QueueListOptions $params |
||
| 209 | * @return Struct\Queue\QueueList |
||
| 210 | */ |
||
| 211 | protected function createQueueList(QueueListOptions $params) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @param QueuePlacePnrOptions $params |
||
| 223 | * @return Struct\Queue\PlacePnr |
||
| 224 | */ |
||
| 225 | protected function createQueuePlacePnr(QueuePlacePnrOptions $params) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @param QueueRemoveItemOptions $params |
||
| 238 | * @return Struct\Queue\RemoveItem |
||
| 239 | */ |
||
| 240 | protected function createQueueRemoveItem(QueueRemoveItemOptions $params) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @param QueueMoveItemOptions $params |
||
| 253 | * @return Struct\Queue\MoveItem |
||
| 254 | */ |
||
| 255 | protected function createQueueMoveItem(QueueMoveItemOptions $params) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @param OfferVerifyOptions $params |
||
| 269 | * @return Struct\Offer\Verify |
||
| 270 | */ |
||
| 271 | protected function createOfferVerifyOffer(OfferVerifyOptions $params) |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @param OfferConfirmAirOptions $params |
||
| 283 | * @return Struct\Offer\ConfirmAir |
||
| 284 | */ |
||
| 285 | protected function createOfferConfirmAirOffer(OfferConfirmAirOptions $params) |
||
| 289 | |||
| 290 | |||
| 291 | /** |
||
| 292 | * @param OfferConfirmHotelOptions $params |
||
| 293 | * @return Struct\Offer\ConfirmHotel |
||
| 294 | */ |
||
| 295 | protected function createOfferConfirmHotelOffer(OfferConfirmHotelOptions $params) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param OfferConfirmCarOptions $params |
||
| 302 | * @return Struct\Offer\ConfirmCar |
||
| 303 | */ |
||
| 304 | protected function createOfferConfirmCarOffer(OfferConfirmCarOptions $params) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * createFareMasterPricerTravelBoardSearch |
||
| 311 | * |
||
| 312 | * @param FareMasterPricerTbSearch $params |
||
| 313 | * @return Struct\Fare\MasterPricerTravelBoardSearch |
||
| 314 | */ |
||
| 315 | protected function createFareMasterPricerTravelBoardSearch(FareMasterPricerTbSearch $params) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * createFareMasterPricerCalendar |
||
| 322 | * |
||
| 323 | * @param FareMasterPricerCalendarOptions $params |
||
| 324 | * @return Struct\Fare\MasterPricerCalendar |
||
| 325 | */ |
||
| 326 | protected function createFareMasterPricerCalendar(FareMasterPricerCalendarOptions $params) |
||
| 330 | |||
| 331 | |||
| 332 | /** |
||
| 333 | * createFareCheckRules |
||
| 334 | * |
||
| 335 | * @param FareCheckRulesOptions $params |
||
| 336 | * @return Struct\Fare\CheckRules |
||
| 337 | */ |
||
| 338 | protected function createFareCheckRules(FareCheckRulesOptions $params) |
||
| 342 | |||
| 343 | /** |
||
| 344 | * createFareConvertCurrency |
||
| 345 | * |
||
| 346 | * @param FareConvertCurrencyOptions $params |
||
| 347 | * @return Struct\Fare\ConvertCurrency |
||
| 348 | */ |
||
| 349 | protected function createFareConvertCurrency(FareConvertCurrencyOptions $params) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * makeFarePricePnrWithBookingClass |
||
| 356 | * |
||
| 357 | * @param FarePricePnrWithBookingClassOptions $params |
||
| 358 | * @return Struct\Fare\PricePNRWithBookingClass12|Struct\Fare\PricePNRWithBookingClass13 |
||
| 359 | */ |
||
| 360 | protected function createFarePricePnrWithBookingClass(FarePricePnrWithBookingClassOptions $params) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * createFareInformativePricingWithoutPNR |
||
| 372 | * |
||
| 373 | * @param FareInformativePricingWithoutPnrOptions $params |
||
| 374 | * @return Struct\Fare\InformativePricingWithoutPNR12|Struct\Fare\InformativePricingWithoutPNR13 |
||
| 375 | */ |
||
| 376 | protected function createFareInformativePricingWithoutPNR(FareInformativePricingWithoutPnrOptions $params) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * createFareInformativeBestPricingWithoutPNR |
||
| 388 | * |
||
| 389 | * @param FareInformativeBestPricingWithoutPnrOptions $params |
||
| 390 | * @return Struct\Fare\InformativeBestPricingWithoutPNR12|Struct\Fare\InformativeBestPricingWithoutPNR13 |
||
| 391 | */ |
||
| 392 | protected function createFareInformativeBestPricingWithoutPNR(FareInformativeBestPricingWithoutPnrOptions $params) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Air_MultiAvailability |
||
| 404 | * |
||
| 405 | * @param AirMultiAvailabilityOptions $params |
||
| 406 | * @return Struct\Air\MultiAvailability |
||
| 407 | */ |
||
| 408 | protected function createAirMultiAvailability(AirMultiAvailabilityOptions $params) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Air_SellFromRecommendation |
||
| 415 | * |
||
| 416 | * @param AirSellFromRecommendationOptions $params |
||
| 417 | * @return Struct\Air\SellFromRecommendation |
||
| 418 | */ |
||
| 419 | protected function createAirSellFromRecommendation(AirSellFromRecommendationOptions $params) |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Air_FlightInfo |
||
| 426 | * |
||
| 427 | * @param AirFlightInfoOptions $params |
||
| 428 | * @return Struct\Air\FlightInfo |
||
| 429 | */ |
||
| 430 | protected function createAirFlightInfo(AirFlightInfoOptions $params) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @param AirRetrieveSeatMapOptions $params |
||
| 437 | * @return Struct\Air\RetrieveSeatMap |
||
| 438 | */ |
||
| 439 | protected function createAirRetrieveSeatMap(AirRetrieveSeatMapOptions $params) |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Command_Cryptic |
||
| 446 | * |
||
| 447 | * @param CommandCrypticOptions $params |
||
| 448 | * @return Struct\Command\Cryptic |
||
| 449 | */ |
||
| 450 | protected function createCommandCryptic(CommandCrypticOptions $params) |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Info_EncodeDecodeCity |
||
| 457 | * |
||
| 458 | * @param InfoEncodeDecodeCityOptions $params |
||
| 459 | * @return Struct\Info\EncodeDecodeCity |
||
| 460 | */ |
||
| 461 | protected function createInfoEncodeDecodeCity(InfoEncodeDecodeCityOptions $params) |
||
| 465 | |||
| 466 | /** |
||
| 467 | * makeMiniRuleGetFromPricingRec |
||
| 468 | * |
||
| 469 | * @param MiniRuleGetFromPricingRecOptions $params |
||
| 470 | * @return Struct\MiniRule\GetFromPricingRec |
||
| 471 | */ |
||
| 472 | protected function createMiniRuleGetFromPricingRec(MiniRuleGetFromPricingRecOptions $params) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Ticket_CreateTstFromPricing |
||
| 479 | * |
||
| 480 | * @param TicketCreateTstFromPricingOptions $params |
||
| 481 | * @return Struct\Ticket\CreateTSTFromPricing |
||
| 482 | */ |
||
| 483 | protected function createTicketCreateTSTFromPricing(TicketCreateTstFromPricingOptions $params) |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Ticket_DeleteTST |
||
| 490 | * |
||
| 491 | * @param TicketDeleteTstOptions $params |
||
| 492 | * @return Struct\Ticket\DeleteTST |
||
| 493 | */ |
||
| 494 | protected function createTicketDeleteTST(TicketDeleteTstOptions $params) |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Ticket_DisplayTST |
||
| 501 | * |
||
| 502 | * @param TicketDisplayTstOptions $params |
||
| 503 | * @return Struct\Ticket\DisplayTST |
||
| 504 | */ |
||
| 505 | protected function createTicketDisplayTST(TicketDisplayTstOptions $params) |
||
| 509 | |||
| 510 | /** |
||
| 511 | * DocIssuance_IssueTicket |
||
| 512 | * |
||
| 513 | * @param DocIssuanceIssueTicketOptions $params |
||
| 514 | * @return Struct\DocIssuance\IssueTicket |
||
| 515 | */ |
||
| 516 | protected function createDocIssuanceIssueTicket(DocIssuanceIssueTicketOptions $params) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * PriceXplorer_ExtremeSearch |
||
| 523 | * |
||
| 524 | * @param PriceXplorerExtremeSearchOptions $params |
||
| 525 | * @return Struct\PriceXplorer\ExtremeSearch |
||
| 526 | */ |
||
| 527 | protected function createPriceXplorerExtremeSearch(PriceXplorerExtremeSearchOptions $params) |
||
| 531 | |||
| 532 | /** |
||
| 533 | * SalesReports_DisplayQueryReport |
||
| 534 | * |
||
| 535 | * @param SalesReportsDisplayQueryReportOptions $params |
||
| 536 | * @return Struct\SalesReports\DisplayQueryReport |
||
| 537 | */ |
||
| 538 | protected function createSalesReportsDisplayQueryReport(SalesReportsDisplayQueryReportOptions $params) |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Check if a given message is in the active WSDL. Throws exception if it isn't. |
||
| 545 | * |
||
| 546 | * @throws InvalidMessageException if message is not in WSDL. |
||
| 547 | * @param string $messageName |
||
| 548 | */ |
||
| 549 | protected function checkMessageIsInWsdl($messageName) |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Get the version number active in the WSDL for the given message |
||
| 558 | * |
||
| 559 | * @param string $messageName |
||
| 560 | * @return float|string |
||
| 561 | */ |
||
| 562 | protected function getActiveVersionFor($messageName) |
||
| 566 | } |
||
| 567 |