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 |
||
| 68 | class Base implements RequestCreatorInterface |
||
| 69 | { |
||
| 70 | /** |
||
| 71 | * @var RequestCreatorParams |
||
| 72 | */ |
||
| 73 | protected $params; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Associative array of messages (as keys) and versions (as values) that are present in the WSDL. |
||
| 77 | * |
||
| 78 | * @var array |
||
| 79 | */ |
||
| 80 | protected $messagesAndVersions = []; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param $params |
||
| 84 | */ |
||
| 85 | public function __construct(RequestCreatorParams $params) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param string $messageName the message name as named in the WSDL |
||
| 93 | * @param RequestOptionsInterface $params |
||
| 94 | * @throws Struct\InvalidArgumentException When invalid input is detected during message creation. |
||
| 95 | * @throws InvalidMessageException when trying to create a request for a message that is not in your WSDL. |
||
| 96 | * @return mixed the created request |
||
| 97 | */ |
||
| 98 | public function createRequest($messageName, RequestOptionsInterface $params) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @return Struct\Security\SignOut |
||
| 113 | */ |
||
| 114 | protected function createSecuritySignOut() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Create request object for Security_Authenticate message |
||
| 121 | * |
||
| 122 | * @param SecurityAuthenticateOptions $params |
||
| 123 | * @return Struct\Security\Authenticate |
||
| 124 | */ |
||
| 125 | protected function createSecurityAuthenticate(SecurityAuthenticateOptions $params) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Create request object for PNR_Retrieve message |
||
| 132 | * |
||
| 133 | * @param PnrRetrieveOptions $params |
||
| 134 | * @return Struct\Pnr\Retrieve |
||
| 135 | */ |
||
| 136 | protected function createPNRRetrieve(PnrRetrieveOptions $params) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @param PnrRetrieveAndDisplayOptions $params |
||
| 148 | * @return Struct\Pnr\RetrieveAndDisplay |
||
| 149 | */ |
||
| 150 | protected function createPNRRetrieveAndDisplay(PnrRetrieveAndDisplayOptions $params) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @param PnrAddMultiElementsBase $params |
||
| 162 | * @return Struct\Pnr\AddMultiElements |
||
| 163 | */ |
||
| 164 | protected function createPNRAddMultiElements(PnrAddMultiElementsBase $params) |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @param PnrCancelOptions $params |
||
| 178 | * @return Struct\Pnr\Cancel |
||
| 179 | */ |
||
| 180 | protected function createPNRCancel(PnrCancelOptions $params) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @param PnrDisplayHistoryOptions $params |
||
| 187 | * @return Struct\Pnr\DisplayHistory |
||
| 188 | */ |
||
| 189 | protected function createPNRDisplayHistory(PnrDisplayHistoryOptions $params) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @param QueueListOptions $params |
||
| 196 | * @return Struct\Queue\QueueList |
||
| 197 | */ |
||
| 198 | protected function createQueueList(QueueListOptions $params) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @param QueuePlacePnrOptions $params |
||
| 210 | * @return Struct\Queue\PlacePnr |
||
| 211 | */ |
||
| 212 | protected function createQueuePlacePnr(QueuePlacePnrOptions $params) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @param QueueRemoveItemOptions $params |
||
| 225 | * @return Struct\Queue\RemoveItem |
||
| 226 | */ |
||
| 227 | protected function createQueueRemoveItem(QueueRemoveItemOptions $params) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @param QueueMoveItemOptions $params |
||
| 240 | * @return Struct\Queue\MoveItem |
||
| 241 | */ |
||
| 242 | protected function createQueueMoveItem(QueueMoveItemOptions $params) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @param OfferVerifyOptions $params |
||
| 256 | * @return Struct\Offer\Verify |
||
| 257 | */ |
||
| 258 | protected function createOfferVerifyOffer(OfferVerifyOptions $params) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @param OfferConfirmAirOptions $params |
||
| 270 | * @return Struct\Offer\ConfirmAir |
||
| 271 | */ |
||
| 272 | protected function createOfferConfirmAirOffer(OfferConfirmAirOptions $params) |
||
| 276 | |||
| 277 | |||
| 278 | /** |
||
| 279 | * @param OfferConfirmHotelOptions $params |
||
| 280 | * @return Struct\Offer\ConfirmHotel |
||
| 281 | */ |
||
| 282 | protected function createOfferConfirmHotelOffer(OfferConfirmHotelOptions $params) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @param OfferConfirmCarOptions $params |
||
| 289 | * @return Struct\Offer\ConfirmCar |
||
| 290 | */ |
||
| 291 | protected function createOfferConfirmCarOffer(OfferConfirmCarOptions $params) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * createFareMasterPricerTravelBoardSearch |
||
| 298 | * |
||
| 299 | * @param FareMasterPricerTbSearch $params |
||
| 300 | * @return Struct\Fare\MasterPricerTravelBoardSearch |
||
| 301 | */ |
||
| 302 | protected function createFareMasterPricerTravelBoardSearch(FareMasterPricerTbSearch $params) |
||
| 306 | |||
| 307 | |||
| 308 | /** |
||
| 309 | * createFareCheckRules |
||
| 310 | * |
||
| 311 | * @param FareCheckRulesOptions $params |
||
| 312 | * @return Struct\Fare\CheckRules |
||
| 313 | */ |
||
| 314 | protected function createFareCheckRules(FareCheckRulesOptions $params) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * createFareConvertCurrency |
||
| 321 | * |
||
| 322 | * @param FareConvertCurrencyOptions $params |
||
| 323 | * @return Struct\Fare\ConvertCurrency |
||
| 324 | */ |
||
| 325 | protected function createFareConvertCurrency(FareConvertCurrencyOptions $params) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * makeFarePricePnrWithBookingClass |
||
| 332 | * |
||
| 333 | * @param FarePricePnrWithBookingClassOptions $params |
||
| 334 | * @return Struct\Fare\PricePNRWithBookingClass12|Struct\Fare\PricePNRWithBookingClass13 |
||
| 335 | */ |
||
| 336 | protected function createFarePricePnrWithBookingClass(FarePricePnrWithBookingClassOptions $params) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * createFareInformativePricingWithoutPNR |
||
| 348 | * |
||
| 349 | * @param FareInformativePricingWithoutPnrOptions $params |
||
| 350 | * @return Struct\Fare\InformativePricingWithoutPNR12|Struct\Fare\InformativePricingWithoutPNR13 |
||
| 351 | */ |
||
| 352 | protected function createFareInformativePricingWithoutPNR(FareInformativePricingWithoutPnrOptions $params) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Air_MultiAvailability |
||
| 364 | * |
||
| 365 | * @param AirMultiAvailabilityOptions $params |
||
| 366 | * @return Struct\Air\MultiAvailability |
||
| 367 | */ |
||
| 368 | protected function createAirMultiAvailability(AirMultiAvailabilityOptions $params) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Air_SellFromRecommendation |
||
| 375 | * |
||
| 376 | * @param AirSellFromRecommendationOptions $params |
||
| 377 | * @return Struct\Air\SellFromRecommendation |
||
| 378 | */ |
||
| 379 | protected function createAirSellFromRecommendation(AirSellFromRecommendationOptions $params) |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Air_FlightInfo |
||
| 386 | * |
||
| 387 | * @param AirFlightInfoOptions $params |
||
| 388 | * @return Struct\Air\FlightInfo |
||
| 389 | */ |
||
| 390 | protected function createAirFlightInfo(AirFlightInfoOptions $params) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @param AirRetrieveSeatMapOptions $params |
||
| 397 | * @return Struct\Air\RetrieveSeatMap |
||
| 398 | */ |
||
| 399 | protected function createAirRetrieveSeatMap(AirRetrieveSeatMapOptions $params) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Command_Cryptic |
||
| 406 | * |
||
| 407 | * @param CommandCrypticOptions $params |
||
| 408 | * @return Struct\Command\Cryptic |
||
| 409 | */ |
||
| 410 | protected function createCommandCryptic(CommandCrypticOptions $params) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Info_EncodeDecodeCity |
||
| 417 | * |
||
| 418 | * @param InfoEncodeDecodeCityOptions $params |
||
| 419 | * @return Struct\Info\EncodeDecodeCity |
||
| 420 | */ |
||
| 421 | protected function createInfoEncodeDecodeCity(InfoEncodeDecodeCityOptions $params) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * makeMiniRuleGetFromPricingRec |
||
| 428 | * |
||
| 429 | * @param MiniRuleGetFromPricingRecOptions $params |
||
| 430 | * @return Struct\MiniRule\GetFromPricingRec |
||
| 431 | */ |
||
| 432 | protected function createMiniRuleGetFromPricingRec(MiniRuleGetFromPricingRecOptions $params) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Ticket_CreateTstFromPricing |
||
| 439 | * |
||
| 440 | * @param TicketCreateTstFromPricingOptions $params |
||
| 441 | * @return Struct\Ticket\CreateTSTFromPricing |
||
| 442 | */ |
||
| 443 | protected function createTicketCreateTSTFromPricing(TicketCreateTstFromPricingOptions $params) |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Ticket_DeleteTST |
||
| 450 | * |
||
| 451 | * @param TicketDeleteTstOptions $params |
||
| 452 | * @return Struct\Ticket\DeleteTST |
||
| 453 | */ |
||
| 454 | protected function createTicketDeleteTST(TicketDeleteTstOptions $params) |
||
| 458 | |||
| 459 | /** |
||
| 460 | * DocIssuance_IssueTicket |
||
| 461 | * |
||
| 462 | * @param DocIssuanceIssueTicketOptions $params |
||
| 463 | * @return Struct\DocIssuance\IssueTicket |
||
| 464 | */ |
||
| 465 | protected function createDocIssuanceIssueTicket(DocIssuanceIssueTicketOptions $params) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * PriceXplorer_ExtremeSearch |
||
| 472 | * |
||
| 473 | * @param PriceXplorerExtremeSearchOptions $params |
||
| 474 | * @return Struct\PriceXplorer\ExtremeSearch |
||
| 475 | */ |
||
| 476 | protected function createPriceXplorerExtremeSearch(PriceXplorerExtremeSearchOptions $params) |
||
| 480 | |||
| 481 | /** |
||
| 482 | * SalesReports_DisplayQueryReport |
||
| 483 | * |
||
| 484 | * @param SalesReportsDisplayQueryReportOptions $params |
||
| 485 | * @return Struct\SalesReports\DisplayQueryReport |
||
| 486 | */ |
||
| 487 | protected function createSalesReportsDisplayQueryReport(SalesReportsDisplayQueryReportOptions $params) |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Check if a given message is in the active WSDL. Throws exception if it isn't. |
||
| 494 | * |
||
| 495 | * @throws InvalidMessageException if message is not in WSDL. |
||
| 496 | * @param string $messageName |
||
| 497 | */ |
||
| 498 | protected function checkMessageIsInWsdl($messageName) |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Get the version number active in the WSDL for the given message |
||
| 507 | * |
||
| 508 | * @param string $messageName |
||
| 509 | * @return float|string |
||
| 510 | */ |
||
| 511 | protected function getActiveVersionFor($messageName) |
||
| 515 | } |
||
| 516 |