Complex classes like AbstractThemeConfiguration 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 AbstractThemeConfiguration, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | abstract class AbstractThemeConfiguration extends AbstractConfigurableElement implements ThemeConfigurationInterface // ThemeConfigurationInterface is here simply for compatibility for extractors |
||
| 10 | { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var string The continue button when choosing the checkout type |
||
| 14 | */ |
||
| 15 | |||
| 16 | public $continueButtonXpath; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var string The checkbox (typically) that sets the guest checkout |
||
| 20 | */ |
||
| 21 | |||
| 22 | public $guestCheckoutButtonXpath; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string The checkbox (typically) that sets the new customer checkout |
||
| 26 | */ |
||
| 27 | |||
| 28 | public $registerNewCustomerCheckoutButtonXpath; |
||
| 29 | |||
| 30 | public $billingAddressDropdownXpath; |
||
| 31 | |||
| 32 | public $customerEmailInputXpath; |
||
| 33 | public $customerPasswordInputXpath; |
||
| 34 | public $customerButtonXpath; |
||
| 35 | |||
| 36 | public $billingFirstNameXpath; |
||
| 37 | public $billingLastNameXpath; |
||
| 38 | public $billingCompanyXpath; |
||
| 39 | public $billingEmailAddressXpath; |
||
| 40 | public $billingAddressXpath; |
||
| 41 | public $billingAddress2Xpath; |
||
| 42 | public $billingCityXpath; |
||
| 43 | /** |
||
| 44 | * @var string The Xpath string for the region_id OPTION to click. Must be sprintf() compatible |
||
| 45 | */ |
||
| 46 | public $billingRegionIdXpath; |
||
| 47 | public $billingPostCodeXpath; |
||
| 48 | /** |
||
| 49 | * @var string The Xpath string for the country OPTION to click. Must be sprintf() compatible |
||
| 50 | */ |
||
| 51 | public $billingCountryIdXpath; |
||
| 52 | public $billingTelephoneXpath; |
||
| 53 | public $billingFaxXpath; |
||
| 54 | |||
| 55 | public $useBillingAddressForShipping; |
||
| 56 | public $doNotUseBillingAddressForShipping; |
||
| 57 | |||
| 58 | public $billingContinueButtonXpath; |
||
| 59 | public $billingContinueCompletedXpath; |
||
| 60 | |||
| 61 | |||
| 62 | public $shippingFirstNameXpath; |
||
| 63 | public $shippingLastNameXpath; |
||
| 64 | public $shippingCompanyXpath; |
||
| 65 | public $shippingEmailAddressXpath; |
||
| 66 | public $shippingAddressXpath; |
||
| 67 | public $shippingAddress2Xpath; |
||
| 68 | public $shippingCityXpath; |
||
| 69 | /** |
||
| 70 | * @var string The Xpath string for the region_id OPTION to click. Must be sprintf() compatible |
||
| 71 | */ |
||
| 72 | public $shippingRegionIdXpath; |
||
| 73 | public $shippingPostCodeXpath; |
||
| 74 | /** |
||
| 75 | * @var string The Xpath string for the country OPTION to click. Must be sprintf() compatible |
||
| 76 | */ |
||
| 77 | public $shippingCountryIdXpath; |
||
| 78 | public $shippingTelephoneXpath; |
||
| 79 | public $shippingFaxXpath; |
||
| 80 | public $shippingContinueButtonXpath; |
||
| 81 | public $shippingContinueCompletedXpath; |
||
| 82 | public $shippingMethodContinueCompletedXpath; |
||
| 83 | |||
| 84 | public $shippingMethodContinueButtonXpath; |
||
| 85 | public $defaultShippingXpath; |
||
| 86 | |||
| 87 | public $paymentMethodContinueCompleteXpath; |
||
| 88 | |||
| 89 | public $paymentMethodContinueButtonXpath; |
||
| 90 | |||
| 91 | public $placeOrderButtonXpath; |
||
| 92 | |||
| 93 | public $orderReceivedCompleteXpath; |
||
| 94 | |||
| 95 | public $shippingMethodFormXpath; |
||
| 96 | |||
| 97 | public $passwordInputXpath; |
||
| 98 | public $confirmPasswordInputXpath; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * This is a hard one. Each of the summary checkout products will be iterated over until they cannot be found. Having |
||
| 102 | * this work in a manner that gets all of the products, in all languages, in all themes, is quite difficult and |
||
| 103 | * so the Xpath selector needs to be one that can find each individual column with an incrementing iterator. |
||
| 104 | * |
||
| 105 | * @see Magium\Magento\Actions\Checkout\Extractors\CartSummary for an example on how this is done |
||
| 106 | * |
||
| 107 | * @var string |
||
| 108 | */ |
||
| 109 | |||
| 110 | public $cartSummaryCheckoutProductLoopPriceXpath; |
||
| 111 | public $cartSummaryCheckoutProductLoopNameXpath; |
||
| 112 | public $cartSummaryCheckoutProductLoopQtyXpath; |
||
| 113 | public $cartSummaryCheckoutProductLoopSubtotalXpath; |
||
| 114 | |||
| 115 | public $cartSummaryCheckoutSubTotal; |
||
| 116 | public $cartSummaryCheckoutTax; |
||
| 117 | public $cartSummaryCheckoutGrandTotal; |
||
| 118 | public $cartSummaryCheckoutShippingTotal; |
||
| 119 | |||
| 120 | public $billingNewAddressXpath; |
||
| 121 | public $shippingNewAddressXpath; |
||
| 122 | |||
| 123 | public $guaranteedPageLoadedElementDisplayedXpath = '//*[contains(concat(" ",normalize-space(@class)," ")," footer ")]'; |
||
| 124 | |||
| 125 | public $orderNumberExtractorXpath; |
||
| 126 | |||
| 127 | public $termsAndConditionsSelectorXpath; |
||
| 128 | |||
| 129 | public $shippingByNameXpath; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @return mixed |
||
| 133 | */ |
||
| 134 | public function getShippingByNameXpath($name) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @return mixed |
||
| 142 | */ |
||
| 143 | public function getTermsAndConditionsSelectorXpath($term) |
||
| 148 | |||
| 149 | public function getOrderNumberExtractorXpath() |
||
| 153 | |||
| 154 | public function getGuaranteedPageLoadedElementDisplayedXpath() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @param mixed $guaranteedPageLoadedElementDisplayedXpath |
||
| 161 | */ |
||
| 162 | public function setGuaranteedPageLoadedElementDisplayedXpath($guaranteedPageLoadedElementDisplayedXpath) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | public function getBillingNewAddressXpath() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return string |
||
| 177 | */ |
||
| 178 | public function getShippingNewAddressXpath() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @return mixed |
||
| 185 | */ |
||
| 186 | public function getDoNotUseBillingAddressForShipping() |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @return mixed |
||
| 193 | */ |
||
| 194 | public function getUseBillingAddressForShipping() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | public function getBillingAddressDropdownXpath() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @return string |
||
| 209 | */ |
||
| 210 | public function getPasswordInputXpath() |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @return string |
||
| 217 | */ |
||
| 218 | public function getConfirmPasswordInputXpath() |
||
| 222 | |||
| 223 | |||
| 224 | |||
| 225 | /** |
||
| 226 | * @return string |
||
| 227 | */ |
||
| 228 | public function getRegisterNewCustomerCheckoutButtonXpath() |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return string |
||
| 235 | */ |
||
| 236 | public function getCustomerEmailInputXpath() |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @return string |
||
| 243 | */ |
||
| 244 | public function getCustomerPasswordInputXpath() |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @return string |
||
| 251 | */ |
||
| 252 | public function getCustomerButtonXpath() |
||
| 256 | |||
| 257 | |||
| 258 | |||
| 259 | /** |
||
| 260 | * @return string |
||
| 261 | */ |
||
| 262 | public function getShippingMethodFormXpath() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @return string |
||
| 269 | */ |
||
| 270 | public function getOrderReceivedCompleteXpath() |
||
| 274 | |||
| 275 | |||
| 276 | /** |
||
| 277 | * @return string |
||
| 278 | */ |
||
| 279 | public function getPaymentMethodContinueButtonXpath() |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @return string |
||
| 286 | */ |
||
| 287 | public function getShippingMethodContinueButtonXpath() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @return string |
||
| 294 | */ |
||
| 295 | public function getPlaceOrderButtonXpath() |
||
| 299 | |||
| 300 | |||
| 301 | /** |
||
| 302 | * @return string |
||
| 303 | */ |
||
| 304 | public function getPaymentMethodContinueCompleteXpath() |
||
| 308 | |||
| 309 | |||
| 310 | public function getDefaultShippingXpath() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @return string |
||
| 317 | */ |
||
| 318 | public function getShippingMethodContinueCompletedXpath() |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @return string |
||
| 325 | */ |
||
| 326 | public function getShippingFirstNameXpath() |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @param string $shippinFirstNameXpath |
||
|
|
|||
| 333 | */ |
||
| 334 | public function setShippingFirstNameXpath($shippingFirstNameXpath) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @return string |
||
| 341 | */ |
||
| 342 | public function getShippingLastNameXpath() |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @param string $shippingLastNameXpath |
||
| 349 | */ |
||
| 350 | public function setShippingLastNameXpath($shippingLastNameXpath) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @return string |
||
| 357 | */ |
||
| 358 | public function getShippingCompanyXpath() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @param string $shippingCompanyXpath |
||
| 365 | */ |
||
| 366 | public function setShippingCompanyXpath($shippingCompanyXpath) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @return string |
||
| 373 | */ |
||
| 374 | public function getShippingEmailAddressXpath() |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @param string $shippingEmailAddressXpath |
||
| 381 | */ |
||
| 382 | public function setShippingEmailAddressXpath($shippingEmailAddressXpath) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * @return string |
||
| 389 | */ |
||
| 390 | public function getShippingAddressXpath() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @param string $shippingAddressXpath |
||
| 397 | */ |
||
| 398 | public function setShippingAddressXpath($shippingAddressXpath) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * @return string |
||
| 405 | */ |
||
| 406 | public function getShippingAddress2Xpath() |
||
| 410 | |||
| 411 | /** |
||
| 412 | * @param string $shippingAddress2Xpath |
||
| 413 | */ |
||
| 414 | public function setShippingAddress2Xpath($shippingAddress2Xpath) |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @return string |
||
| 421 | */ |
||
| 422 | public function getShippingCityXpath() |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @param string $shippingCityXpath |
||
| 429 | */ |
||
| 430 | public function setShippingCityXpath($shippingCityXpath) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @return string |
||
| 437 | */ |
||
| 438 | public function getShippingRegionIdXpath($region) |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @param string $shippingRegionIdXpath |
||
| 446 | */ |
||
| 447 | public function setShippingRegionIdXpath($shippingRegionIdXpath) |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @return string |
||
| 454 | */ |
||
| 455 | public function getShippingPostCodeXpath() |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @param string $shippingPostCodeXpath |
||
| 462 | */ |
||
| 463 | public function setShippingPostCodeXpath($shippingPostCodeXpath) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * @return string |
||
| 470 | */ |
||
| 471 | public function getShippingCountryIdXpath($country) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * @param string $shippingCountryIdXpath |
||
| 479 | */ |
||
| 480 | public function setShippingCountryIdXpath($shippingCountryIdXpath) |
||
| 484 | |||
| 485 | /** |
||
| 486 | * @return string |
||
| 487 | */ |
||
| 488 | public function getShippingTelephoneXpath() |
||
| 492 | |||
| 493 | /** |
||
| 494 | * @param string $shippingTelephoneXpath |
||
| 495 | */ |
||
| 496 | public function setShippingTelephoneXpath($shippingTelephoneXpath) |
||
| 500 | |||
| 501 | /** |
||
| 502 | * @return string |
||
| 503 | */ |
||
| 504 | public function getShippingFaxXpath() |
||
| 508 | |||
| 509 | /** |
||
| 510 | * @param string $shippingFaxXpath |
||
| 511 | */ |
||
| 512 | public function setShippingFaxXpath($shippingFaxXpath) |
||
| 516 | |||
| 517 | /** |
||
| 518 | * @return string |
||
| 519 | */ |
||
| 520 | public function getShippingContinueButtonXpath() |
||
| 524 | |||
| 525 | /** |
||
| 526 | * @param string $shippingContinueButtonXpath |
||
| 527 | */ |
||
| 528 | public function setShippingContinueButtonXpath($shippingContinueButtonXpath) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * @return string |
||
| 535 | */ |
||
| 536 | public function getShippingContinueCompletedXpath() |
||
| 540 | |||
| 541 | /** |
||
| 542 | * @param string $shippingContinueCompletedXpath |
||
| 543 | */ |
||
| 544 | public function setShippingContinueCompletedXpath($shippingContinueCompletedXpath) |
||
| 548 | |||
| 549 | public function getBillingContinueCompletedXpath() |
||
| 553 | |||
| 554 | public function getContinueButtonXpath() |
||
| 558 | |||
| 559 | public function getGuestCheckoutButtonXpath() |
||
| 563 | |||
| 564 | /** |
||
| 565 | * @return string |
||
| 566 | */ |
||
| 567 | public function getBillingFirstNameXpath() |
||
| 571 | |||
| 572 | /** |
||
| 573 | * @return string |
||
| 574 | */ |
||
| 575 | public function getBillingLastNameXpath() |
||
| 579 | |||
| 580 | /** |
||
| 581 | * @return string |
||
| 582 | */ |
||
| 583 | public function getBillingCompanyXpath() |
||
| 587 | |||
| 588 | /** |
||
| 589 | * @return string |
||
| 590 | */ |
||
| 591 | public function getBillingEmailAddressXpath() |
||
| 595 | |||
| 596 | /** |
||
| 597 | * @return string |
||
| 598 | */ |
||
| 599 | public function getBillingAddressXpath() |
||
| 603 | |||
| 604 | /** |
||
| 605 | * @return string |
||
| 606 | */ |
||
| 607 | public function getBillingAddress2Xpath() |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @return string |
||
| 614 | */ |
||
| 615 | public function getBillingCityXpath() |
||
| 619 | |||
| 620 | /** |
||
| 621 | * @return string |
||
| 622 | */ |
||
| 623 | public function getBillingRegionIdXpath($region) |
||
| 628 | |||
| 629 | /** |
||
| 630 | * @return string |
||
| 631 | */ |
||
| 632 | public function getBillingPostCodeXpath() |
||
| 636 | |||
| 637 | /** |
||
| 638 | * @return string |
||
| 639 | */ |
||
| 640 | public function getBillingCountryIdXpath($country) |
||
| 645 | |||
| 646 | /** |
||
| 647 | * @return string |
||
| 648 | */ |
||
| 649 | public function getBillingTelephoneXpath() |
||
| 653 | |||
| 654 | /** |
||
| 655 | * @return string |
||
| 656 | */ |
||
| 657 | public function getBillingFaxXpath() |
||
| 661 | |||
| 662 | /** |
||
| 663 | * @return string |
||
| 664 | */ |
||
| 665 | public function getBillingContinueButtonXpath() |
||
| 669 | |||
| 670 | /** |
||
| 671 | * @return string |
||
| 672 | */ |
||
| 673 | public function getCartSummaryCheckoutSubTotal() |
||
| 677 | |||
| 678 | /** |
||
| 679 | * @return string |
||
| 680 | */ |
||
| 681 | public function getCartSummaryCheckoutTax() |
||
| 685 | |||
| 686 | /** |
||
| 687 | * @return string |
||
| 688 | */ |
||
| 689 | public function getCartSummaryCheckoutGrandTotal() |
||
| 693 | |||
| 694 | /** |
||
| 695 | * @return string |
||
| 696 | */ |
||
| 697 | public function getCartSummaryCheckoutShippingTotal() |
||
| 701 | |||
| 702 | |||
| 703 | |||
| 704 | /** |
||
| 705 | * @return string |
||
| 706 | */ |
||
| 707 | public function getCartSummaryCheckoutProductLoopPriceXpath($itemCount) |
||
| 712 | |||
| 713 | /** |
||
| 714 | * @return string |
||
| 715 | */ |
||
| 716 | public function getCartSummaryCheckoutProductLoopNameXpath($itemCount) |
||
| 721 | |||
| 722 | /** |
||
| 723 | * @return string |
||
| 724 | */ |
||
| 725 | public function getCartSummaryCheckoutProductLoopQtyXpath($itemCount) |
||
| 730 | |||
| 731 | /** |
||
| 732 | * @return string |
||
| 733 | */ |
||
| 734 | public function getCartSummaryCheckoutProductLoopSubtotalXpath($itemCount) |
||
| 739 | |||
| 740 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.