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