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 | |||
| 130 | /** |
||
| 131 | * @return mixed |
||
| 132 | */ |
||
| 133 | public function getTermsAndConditionsSelectorXpath($term) |
||
| 138 | |||
| 139 | public function getOrderNumberExtractorXpath() |
||
| 143 | |||
| 144 | public function getGuaranteedPageLoadedElementDisplayedXpath() |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param mixed $guaranteedPageLoadedElementDisplayedXpath |
||
| 151 | */ |
||
| 152 | public function setGuaranteedPageLoadedElementDisplayedXpath($guaranteedPageLoadedElementDisplayedXpath) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return string |
||
| 159 | */ |
||
| 160 | public function getBillingNewAddressXpath() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return string |
||
| 167 | */ |
||
| 168 | public function getShippingNewAddressXpath() |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @return mixed |
||
| 175 | */ |
||
| 176 | public function getDoNotUseBillingAddressForShipping() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @return mixed |
||
| 183 | */ |
||
| 184 | public function getUseBillingAddressForShipping() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @return string |
||
| 191 | */ |
||
| 192 | public function getBillingAddressDropdownXpath() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | public function getPasswordInputXpath() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @return string |
||
| 207 | */ |
||
| 208 | public function getConfirmPasswordInputXpath() |
||
| 212 | |||
| 213 | |||
| 214 | |||
| 215 | /** |
||
| 216 | * @return string |
||
| 217 | */ |
||
| 218 | public function getRegisterNewCustomerCheckoutButtonXpath() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @return string |
||
| 225 | */ |
||
| 226 | public function getCustomerEmailInputXpath() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @return string |
||
| 233 | */ |
||
| 234 | public function getCustomerPasswordInputXpath() |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | public function getCustomerButtonXpath() |
||
| 246 | |||
| 247 | |||
| 248 | |||
| 249 | /** |
||
| 250 | * @return string |
||
| 251 | */ |
||
| 252 | public function getShippingMethodFormXpath() |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @return string |
||
| 259 | */ |
||
| 260 | public function getOrderReceivedCompleteXpath() |
||
| 264 | |||
| 265 | |||
| 266 | /** |
||
| 267 | * @return string |
||
| 268 | */ |
||
| 269 | public function getPaymentMethodContinueButtonXpath() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return string |
||
| 276 | */ |
||
| 277 | public function getShippingMethodContinueButtonXpath() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return string |
||
| 284 | */ |
||
| 285 | public function getPlaceOrderButtonXpath() |
||
| 289 | |||
| 290 | |||
| 291 | /** |
||
| 292 | * @return string |
||
| 293 | */ |
||
| 294 | public function getPaymentMethodContinueCompleteXpath() |
||
| 298 | |||
| 299 | |||
| 300 | public function getDefaultShippingXpath() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @return string |
||
| 307 | */ |
||
| 308 | public function getShippingMethodContinueCompletedXpath() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @return string |
||
| 315 | */ |
||
| 316 | public function getShippingFirstNameXpath() |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @param string $shippinFirstNameXpath |
||
|
|
|||
| 323 | */ |
||
| 324 | public function setShippingFirstNameXpath($shippingFirstNameXpath) |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @return string |
||
| 331 | */ |
||
| 332 | public function getShippingLastNameXpath() |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @param string $shippingLastNameXpath |
||
| 339 | */ |
||
| 340 | public function setShippingLastNameXpath($shippingLastNameXpath) |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @return string |
||
| 347 | */ |
||
| 348 | public function getShippingCompanyXpath() |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @param string $shippingCompanyXpath |
||
| 355 | */ |
||
| 356 | public function setShippingCompanyXpath($shippingCompanyXpath) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @return string |
||
| 363 | */ |
||
| 364 | public function getShippingEmailAddressXpath() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @param string $shippingEmailAddressXpath |
||
| 371 | */ |
||
| 372 | public function setShippingEmailAddressXpath($shippingEmailAddressXpath) |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @return string |
||
| 379 | */ |
||
| 380 | public function getShippingAddressXpath() |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @param string $shippingAddressXpath |
||
| 387 | */ |
||
| 388 | public function setShippingAddressXpath($shippingAddressXpath) |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @return string |
||
| 395 | */ |
||
| 396 | public function getShippingAddress2Xpath() |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @param string $shippingAddress2Xpath |
||
| 403 | */ |
||
| 404 | public function setShippingAddress2Xpath($shippingAddress2Xpath) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @return string |
||
| 411 | */ |
||
| 412 | public function getShippingCityXpath() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @param string $shippingCityXpath |
||
| 419 | */ |
||
| 420 | public function setShippingCityXpath($shippingCityXpath) |
||
| 424 | |||
| 425 | /** |
||
| 426 | * @return string |
||
| 427 | */ |
||
| 428 | public function getShippingRegionIdXpath($region) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @param string $shippingRegionIdXpath |
||
| 436 | */ |
||
| 437 | public function setShippingRegionIdXpath($shippingRegionIdXpath) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @return string |
||
| 444 | */ |
||
| 445 | public function getShippingPostCodeXpath() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param string $shippingPostCodeXpath |
||
| 452 | */ |
||
| 453 | public function setShippingPostCodeXpath($shippingPostCodeXpath) |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @return string |
||
| 460 | */ |
||
| 461 | public function getShippingCountryIdXpath($country) |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @param string $shippingCountryIdXpath |
||
| 469 | */ |
||
| 470 | public function setShippingCountryIdXpath($shippingCountryIdXpath) |
||
| 474 | |||
| 475 | /** |
||
| 476 | * @return string |
||
| 477 | */ |
||
| 478 | public function getShippingTelephoneXpath() |
||
| 482 | |||
| 483 | /** |
||
| 484 | * @param string $shippingTelephoneXpath |
||
| 485 | */ |
||
| 486 | public function setShippingTelephoneXpath($shippingTelephoneXpath) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @return string |
||
| 493 | */ |
||
| 494 | public function getShippingFaxXpath() |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @param string $shippingFaxXpath |
||
| 501 | */ |
||
| 502 | public function setShippingFaxXpath($shippingFaxXpath) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * @return string |
||
| 509 | */ |
||
| 510 | public function getShippingContinueButtonXpath() |
||
| 514 | |||
| 515 | /** |
||
| 516 | * @param string $shippingContinueButtonXpath |
||
| 517 | */ |
||
| 518 | public function setShippingContinueButtonXpath($shippingContinueButtonXpath) |
||
| 522 | |||
| 523 | /** |
||
| 524 | * @return string |
||
| 525 | */ |
||
| 526 | public function getShippingContinueCompletedXpath() |
||
| 530 | |||
| 531 | /** |
||
| 532 | * @param string $shippingContinueCompletedXpath |
||
| 533 | */ |
||
| 534 | public function setShippingContinueCompletedXpath($shippingContinueCompletedXpath) |
||
| 538 | |||
| 539 | public function getBillingContinueCompletedXpath() |
||
| 543 | |||
| 544 | public function getContinueButtonXpath() |
||
| 548 | |||
| 549 | public function getGuestCheckoutButtonXpath() |
||
| 553 | |||
| 554 | /** |
||
| 555 | * @return string |
||
| 556 | */ |
||
| 557 | public function getBillingFirstNameXpath() |
||
| 561 | |||
| 562 | /** |
||
| 563 | * @return string |
||
| 564 | */ |
||
| 565 | public function getBillingLastNameXpath() |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @return string |
||
| 572 | */ |
||
| 573 | public function getBillingCompanyXpath() |
||
| 577 | |||
| 578 | /** |
||
| 579 | * @return string |
||
| 580 | */ |
||
| 581 | public function getBillingEmailAddressXpath() |
||
| 585 | |||
| 586 | /** |
||
| 587 | * @return string |
||
| 588 | */ |
||
| 589 | public function getBillingAddressXpath() |
||
| 593 | |||
| 594 | /** |
||
| 595 | * @return string |
||
| 596 | */ |
||
| 597 | public function getBillingAddress2Xpath() |
||
| 601 | |||
| 602 | /** |
||
| 603 | * @return string |
||
| 604 | */ |
||
| 605 | public function getBillingCityXpath() |
||
| 609 | |||
| 610 | /** |
||
| 611 | * @return string |
||
| 612 | */ |
||
| 613 | public function getBillingRegionIdXpath($region) |
||
| 618 | |||
| 619 | /** |
||
| 620 | * @return string |
||
| 621 | */ |
||
| 622 | public function getBillingPostCodeXpath() |
||
| 626 | |||
| 627 | /** |
||
| 628 | * @return string |
||
| 629 | */ |
||
| 630 | public function getBillingCountryIdXpath($country) |
||
| 635 | |||
| 636 | /** |
||
| 637 | * @return string |
||
| 638 | */ |
||
| 639 | public function getBillingTelephoneXpath() |
||
| 643 | |||
| 644 | /** |
||
| 645 | * @return string |
||
| 646 | */ |
||
| 647 | public function getBillingFaxXpath() |
||
| 651 | |||
| 652 | /** |
||
| 653 | * @return string |
||
| 654 | */ |
||
| 655 | public function getBillingContinueButtonXpath() |
||
| 659 | |||
| 660 | /** |
||
| 661 | * @return string |
||
| 662 | */ |
||
| 663 | public function getCartSummaryCheckoutSubTotal() |
||
| 667 | |||
| 668 | /** |
||
| 669 | * @return string |
||
| 670 | */ |
||
| 671 | public function getCartSummaryCheckoutTax() |
||
| 675 | |||
| 676 | /** |
||
| 677 | * @return string |
||
| 678 | */ |
||
| 679 | public function getCartSummaryCheckoutGrandTotal() |
||
| 683 | |||
| 684 | /** |
||
| 685 | * @return string |
||
| 686 | */ |
||
| 687 | public function getCartSummaryCheckoutShippingTotal() |
||
| 691 | |||
| 692 | |||
| 693 | |||
| 694 | /** |
||
| 695 | * @return string |
||
| 696 | */ |
||
| 697 | public function getCartSummaryCheckoutProductLoopPriceXpath($itemCount) |
||
| 702 | |||
| 703 | /** |
||
| 704 | * @return string |
||
| 705 | */ |
||
| 706 | public function getCartSummaryCheckoutProductLoopNameXpath($itemCount) |
||
| 711 | |||
| 712 | /** |
||
| 713 | * @return string |
||
| 714 | */ |
||
| 715 | public function getCartSummaryCheckoutProductLoopQtyXpath($itemCount) |
||
| 720 | |||
| 721 | /** |
||
| 722 | * @return string |
||
| 723 | */ |
||
| 724 | public function getCartSummaryCheckoutProductLoopSubtotalXpath($itemCount) |
||
| 729 | |||
| 730 | } |
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.