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 |
||
| 71 | class Base implements RequestCreatorInterface |
||
| 72 | { |
||
| 73 | /** |
||
| 74 | * @var RequestCreatorParams |
||
| 75 | */ |
||
| 76 | protected $params; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Associative array of messages (as keys) and versions (as values) that are present in the WSDL. |
||
| 80 | * |
||
| 81 | * @var array |
||
| 82 | */ |
||
| 83 | protected $messagesAndVersions = []; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param $params |
||
| 87 | */ |
||
| 88 | public function __construct(RequestCreatorParams $params) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $messageName the message name as named in the WSDL |
||
| 96 | * @param RequestOptionsInterface $params |
||
| 97 | * @throws Struct\InvalidArgumentException When invalid input is detected during message creation. |
||
| 98 | * @throws InvalidMessageException when trying to create a request for a message that is not in your WSDL. |
||
| 99 | * @return mixed the created request |
||
| 100 | */ |
||
| 101 | public function createRequest($messageName, RequestOptionsInterface $params) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @return Struct\Security\SignOut |
||
| 116 | */ |
||
| 117 | protected function createSecuritySignOut() |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Create request object for Security_Authenticate message |
||
| 124 | * |
||
| 125 | * @param SecurityAuthenticateOptions $params |
||
| 126 | * @return Struct\Security\Authenticate |
||
| 127 | */ |
||
| 128 | protected function createSecurityAuthenticate(SecurityAuthenticateOptions $params) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Create request object for PNR_Retrieve message |
||
| 135 | * |
||
| 136 | * @param PnrRetrieveOptions $params |
||
| 137 | * @return Struct\Pnr\Retrieve |
||
| 138 | */ |
||
| 139 | protected function createPNRRetrieve(PnrRetrieveOptions $params) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param PnrRetrieveAndDisplayOptions $params |
||
| 151 | * @return Struct\Pnr\RetrieveAndDisplay |
||
| 152 | */ |
||
| 153 | protected function createPNRRetrieveAndDisplay(PnrRetrieveAndDisplayOptions $params) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @param PnrAddMultiElementsBase $params |
||
| 165 | * @return Struct\Pnr\AddMultiElements |
||
| 166 | */ |
||
| 167 | protected function createPNRAddMultiElements(PnrAddMultiElementsBase $params) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param PnrCancelOptions $params |
||
| 181 | * @return Struct\Pnr\Cancel |
||
| 182 | */ |
||
| 183 | protected function createPNRCancel(PnrCancelOptions $params) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param PnrDisplayHistoryOptions $params |
||
| 190 | * @return Struct\Pnr\DisplayHistory |
||
| 191 | */ |
||
| 192 | protected function createPNRDisplayHistory(PnrDisplayHistoryOptions $params) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @param PnrTransferOwnershipOptions $params |
||
| 199 | * @return Struct\Pnr\TransferOwnership |
||
| 200 | */ |
||
| 201 | protected function createPNRTransferOwnership(PnrTransferOwnershipOptions $params) |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param QueueListOptions $params |
||
| 208 | * @return Struct\Queue\QueueList |
||
| 209 | */ |
||
| 210 | protected function createQueueList(QueueListOptions $params) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param QueuePlacePnrOptions $params |
||
| 222 | * @return Struct\Queue\PlacePnr |
||
| 223 | */ |
||
| 224 | protected function createQueuePlacePnr(QueuePlacePnrOptions $params) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @param QueueRemoveItemOptions $params |
||
| 237 | * @return Struct\Queue\RemoveItem |
||
| 238 | */ |
||
| 239 | protected function createQueueRemoveItem(QueueRemoveItemOptions $params) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @param QueueMoveItemOptions $params |
||
| 252 | * @return Struct\Queue\MoveItem |
||
| 253 | */ |
||
| 254 | protected function createQueueMoveItem(QueueMoveItemOptions $params) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @param OfferVerifyOptions $params |
||
| 268 | * @return Struct\Offer\Verify |
||
| 269 | */ |
||
| 270 | protected function createOfferVerifyOffer(OfferVerifyOptions $params) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @param OfferConfirmAirOptions $params |
||
| 282 | * @return Struct\Offer\ConfirmAir |
||
| 283 | */ |
||
| 284 | protected function createOfferConfirmAirOffer(OfferConfirmAirOptions $params) |
||
| 288 | |||
| 289 | |||
| 290 | /** |
||
| 291 | * @param OfferConfirmHotelOptions $params |
||
| 292 | * @return Struct\Offer\ConfirmHotel |
||
| 293 | */ |
||
| 294 | protected function createOfferConfirmHotelOffer(OfferConfirmHotelOptions $params) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @param OfferConfirmCarOptions $params |
||
| 301 | * @return Struct\Offer\ConfirmCar |
||
| 302 | */ |
||
| 303 | protected function createOfferConfirmCarOffer(OfferConfirmCarOptions $params) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * createFareMasterPricerTravelBoardSearch |
||
| 310 | * |
||
| 311 | * @param FareMasterPricerTbSearch $params |
||
| 312 | * @return Struct\Fare\MasterPricerTravelBoardSearch |
||
| 313 | */ |
||
| 314 | protected function createFareMasterPricerTravelBoardSearch(FareMasterPricerTbSearch $params) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * createFareMasterPricerCalendar |
||
| 321 | * |
||
| 322 | * @param FareMasterPricerCalendarOptions $params |
||
| 323 | * @return Struct\Fare\MasterPricerCalendar |
||
| 324 | */ |
||
| 325 | protected function createFareMasterPricerCalendar(FareMasterPricerCalendarOptions $params) |
||
| 329 | |||
| 330 | |||
| 331 | /** |
||
| 332 | * createFareCheckRules |
||
| 333 | * |
||
| 334 | * @param FareCheckRulesOptions $params |
||
| 335 | * @return Struct\Fare\CheckRules |
||
| 336 | */ |
||
| 337 | protected function createFareCheckRules(FareCheckRulesOptions $params) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * createFareConvertCurrency |
||
| 344 | * |
||
| 345 | * @param FareConvertCurrencyOptions $params |
||
| 346 | * @return Struct\Fare\ConvertCurrency |
||
| 347 | */ |
||
| 348 | protected function createFareConvertCurrency(FareConvertCurrencyOptions $params) |
||
| 352 | |||
| 353 | /** |
||
| 354 | * makeFarePricePnrWithBookingClass |
||
| 355 | * |
||
| 356 | * @param FarePricePnrWithBookingClassOptions $params |
||
| 357 | * @return Struct\Fare\PricePNRWithBookingClass12|Struct\Fare\PricePNRWithBookingClass13 |
||
| 358 | */ |
||
| 359 | protected function createFarePricePnrWithBookingClass(FarePricePnrWithBookingClassOptions $params) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * createFareInformativePricingWithoutPNR |
||
| 371 | * |
||
| 372 | * @param FareInformativePricingWithoutPnrOptions $params |
||
| 373 | * @return Struct\Fare\InformativePricingWithoutPNR12|Struct\Fare\InformativePricingWithoutPNR13 |
||
| 374 | */ |
||
| 375 | protected function createFareInformativePricingWithoutPNR(FareInformativePricingWithoutPnrOptions $params) |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Air_MultiAvailability |
||
| 387 | * |
||
| 388 | * @param AirMultiAvailabilityOptions $params |
||
| 389 | * @return Struct\Air\MultiAvailability |
||
| 390 | */ |
||
| 391 | protected function createAirMultiAvailability(AirMultiAvailabilityOptions $params) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Air_SellFromRecommendation |
||
| 398 | * |
||
| 399 | * @param AirSellFromRecommendationOptions $params |
||
| 400 | * @return Struct\Air\SellFromRecommendation |
||
| 401 | */ |
||
| 402 | protected function createAirSellFromRecommendation(AirSellFromRecommendationOptions $params) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Air_FlightInfo |
||
| 409 | * |
||
| 410 | * @param AirFlightInfoOptions $params |
||
| 411 | * @return Struct\Air\FlightInfo |
||
| 412 | */ |
||
| 413 | protected function createAirFlightInfo(AirFlightInfoOptions $params) |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @param AirRetrieveSeatMapOptions $params |
||
| 420 | * @return Struct\Air\RetrieveSeatMap |
||
| 421 | */ |
||
| 422 | protected function createAirRetrieveSeatMap(AirRetrieveSeatMapOptions $params) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Command_Cryptic |
||
| 429 | * |
||
| 430 | * @param CommandCrypticOptions $params |
||
| 431 | * @return Struct\Command\Cryptic |
||
| 432 | */ |
||
| 433 | protected function createCommandCryptic(CommandCrypticOptions $params) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Info_EncodeDecodeCity |
||
| 440 | * |
||
| 441 | * @param InfoEncodeDecodeCityOptions $params |
||
| 442 | * @return Struct\Info\EncodeDecodeCity |
||
| 443 | */ |
||
| 444 | protected function createInfoEncodeDecodeCity(InfoEncodeDecodeCityOptions $params) |
||
| 448 | |||
| 449 | /** |
||
| 450 | * makeMiniRuleGetFromPricingRec |
||
| 451 | * |
||
| 452 | * @param MiniRuleGetFromPricingRecOptions $params |
||
| 453 | * @return Struct\MiniRule\GetFromPricingRec |
||
| 454 | */ |
||
| 455 | protected function createMiniRuleGetFromPricingRec(MiniRuleGetFromPricingRecOptions $params) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Ticket_CreateTstFromPricing |
||
| 462 | * |
||
| 463 | * @param TicketCreateTstFromPricingOptions $params |
||
| 464 | * @return Struct\Ticket\CreateTSTFromPricing |
||
| 465 | */ |
||
| 466 | protected function createTicketCreateTSTFromPricing(TicketCreateTstFromPricingOptions $params) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Ticket_DeleteTST |
||
| 473 | * |
||
| 474 | * @param TicketDeleteTstOptions $params |
||
| 475 | * @return Struct\Ticket\DeleteTST |
||
| 476 | */ |
||
| 477 | protected function createTicketDeleteTST(TicketDeleteTstOptions $params) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Ticket_DisplayTST |
||
| 484 | * |
||
| 485 | * @param TicketDisplayTstOptions $params |
||
| 486 | * @return Struct\Ticket\DisplayTST |
||
| 487 | */ |
||
| 488 | protected function createTicketDisplayTST(TicketDisplayTstOptions $params) |
||
| 492 | |||
| 493 | /** |
||
| 494 | * DocIssuance_IssueTicket |
||
| 495 | * |
||
| 496 | * @param DocIssuanceIssueTicketOptions $params |
||
| 497 | * @return Struct\DocIssuance\IssueTicket |
||
| 498 | */ |
||
| 499 | protected function createDocIssuanceIssueTicket(DocIssuanceIssueTicketOptions $params) |
||
| 503 | |||
| 504 | /** |
||
| 505 | * PriceXplorer_ExtremeSearch |
||
| 506 | * |
||
| 507 | * @param PriceXplorerExtremeSearchOptions $params |
||
| 508 | * @return Struct\PriceXplorer\ExtremeSearch |
||
| 509 | */ |
||
| 510 | protected function createPriceXplorerExtremeSearch(PriceXplorerExtremeSearchOptions $params) |
||
| 514 | |||
| 515 | /** |
||
| 516 | * SalesReports_DisplayQueryReport |
||
| 517 | * |
||
| 518 | * @param SalesReportsDisplayQueryReportOptions $params |
||
| 519 | * @return Struct\SalesReports\DisplayQueryReport |
||
| 520 | */ |
||
| 521 | protected function createSalesReportsDisplayQueryReport(SalesReportsDisplayQueryReportOptions $params) |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Check if a given message is in the active WSDL. Throws exception if it isn't. |
||
| 528 | * |
||
| 529 | * @throws InvalidMessageException if message is not in WSDL. |
||
| 530 | * @param string $messageName |
||
| 531 | */ |
||
| 532 | protected function checkMessageIsInWsdl($messageName) |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Get the version number active in the WSDL for the given message |
||
| 541 | * |
||
| 542 | * @param string $messageName |
||
| 543 | * @return float|string |
||
| 544 | */ |
||
| 545 | protected function getActiveVersionFor($messageName) |
||
| 549 | } |
||
| 550 |