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 NavigableThemeInterface |
||
| 10 | { |
||
| 11 | |||
| 12 | public $homeXpath; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var string The Xpath string that finds the base of the navigation menu |
||
| 16 | */ |
||
| 17 | public $navigationBaseXPathSelector; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string The Xpath string that can be used iteratively to find child navigation nodes |
||
| 21 | */ |
||
| 22 | |||
| 23 | public $navigationChildXPathSelector; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string A simple, default path to use for categories. |
||
| 27 | */ |
||
| 28 | |||
| 29 | public $navigationPathToSimpleProductCategory; |
||
| 30 | |||
| 31 | public $navigationPathToConfigurableProductCategory; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string Xpath to add a Simple product to the cart from the product's page |
||
| 35 | */ |
||
| 36 | |||
| 37 | public $addToCartXpath; |
||
| 38 | |||
| 39 | public $defaultSimpleProductName; |
||
| 40 | public $defaultConfigurableProductName; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string Xpath to add a Simple product to the cart from the category page |
||
| 44 | */ |
||
| 45 | |||
| 46 | public $categoryAddToCartButtonXPathSelector; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var string Xpath to find a product's link on a category page. Used to navigate to the product from the category |
||
| 50 | */ |
||
| 51 | |||
| 52 | public $categoryProductPageXpath; |
||
| 53 | |||
| 54 | public $categorySpecificProductPageXpath; |
||
| 55 | |||
| 56 | |||
| 57 | /** |
||
| 58 | * @var string Xpath used after a product has been added to the cart to verify that the product has been added to the cart |
||
| 59 | */ |
||
| 60 | |||
| 61 | public $addToCartSuccessXpath; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string The base URL of the installation |
||
| 65 | */ |
||
| 66 | |||
| 67 | public $baseUrl; |
||
| 68 | |||
| 69 | public $myAccountTitle; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var array Instructions in an Xpath array syntax to get to the login page. |
||
| 73 | */ |
||
| 74 | |||
| 75 | public $navigateToCustomerPageInstructions = []; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var array Instructions in an Xpath array syntax to get to the shopping cart |
||
| 79 | */ |
||
| 80 | |||
| 81 | public $cartNavigationInstructions = []; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var array Instructions in an Xpath array syntax to get to the start of the checkout page |
||
| 85 | */ |
||
| 86 | |||
| 87 | public $checkoutNavigationInstructions = []; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var array Instructions in an Xpath array syntax to get to the customer registration page |
||
| 91 | */ |
||
| 92 | |||
| 93 | public $registrationNavigationInstructions = []; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var array Instructions in an Xpath array syntax to get to the customer registration page |
||
| 97 | */ |
||
| 98 | |||
| 99 | public $logoutNavigationInstructions = []; |
||
| 100 | |||
| 101 | public $registerFirstNameXpath; |
||
| 102 | public $registerLastNameXpath; |
||
| 103 | public $registerEmailXpath; |
||
| 104 | public $registerPasswordXpath; |
||
| 105 | public $registerConfirmPasswordXpath; |
||
| 106 | public $registerNewsletterXpath; |
||
| 107 | public $registerSubmitXpath; |
||
| 108 | |||
| 109 | public $logoutSuccessXpath; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * This is a hard one. Each of the summary checkout products will be iterated over until they cannot be found. Having |
||
| 113 | * this work in a manner that gets all of the products, in all languages, in all themes, is quite difficult and |
||
| 114 | * so the Xpath selector needs to be one that can find each individual column with an incrementing iterator. |
||
| 115 | * |
||
| 116 | * @see Magium\Magento\Actions\Checkout\Extractors\CartSummary for an example on how this is done |
||
| 117 | * |
||
| 118 | * @var string |
||
| 119 | */ |
||
| 120 | |||
| 121 | public $cartSummaryCheckoutProductLoopPriceXpath; |
||
| 122 | public $cartSummaryCheckoutProductLoopNameXpath; |
||
| 123 | public $cartSummaryCheckoutProductLoopQtyXpath; |
||
| 124 | public $cartSummaryCheckoutProductLoopSubtotalXpath; |
||
| 125 | |||
| 126 | public $cartSummaryCheckoutSubTotal; |
||
| 127 | public $cartSummaryCheckoutTax; |
||
| 128 | public $cartSummaryCheckoutGrandTotal; |
||
| 129 | public $cartSummaryCheckoutShippingTotal; |
||
| 130 | |||
| 131 | public $layeredNavigationTestXpath; |
||
| 132 | |||
| 133 | public $breadCrumbXpath; |
||
| 134 | |||
| 135 | public $productListBaseXpath; |
||
| 136 | public $productListDescriptionXpath; |
||
| 137 | public $productListTitleXpath; |
||
| 138 | public $productListCompareLinkXpath; |
||
| 139 | public $productListImageXpath; |
||
| 140 | public $productListLinkXpath; |
||
| 141 | public $productListOriginalPriceXpath; |
||
| 142 | public $productListPriceXpath; |
||
| 143 | public $productListWishlistLinkXpath; |
||
| 144 | public $productListAddToCartLinkXpath; |
||
| 145 | |||
| 146 | public $productGridBaseXpath; |
||
| 147 | public $productGridDescriptionXpath; |
||
| 148 | public $productGridTitleXpath; |
||
| 149 | public $productGridCompareLinkXpath; |
||
| 150 | public $productGridImageXpath; |
||
| 151 | public $productGridLinkXpath; |
||
| 152 | public $productGridOriginalPriceXpath; |
||
| 153 | public $productGridPriceXpath; |
||
| 154 | public $productGridWishlistLinkXpath; |
||
| 155 | public $productGridAddToCartLinkXpath; |
||
| 156 | |||
| 157 | public $productCollectionViewModeXpath; |
||
| 158 | public $productCollectionSortByXpath; |
||
| 159 | public $productCollectionShowCountXpath; |
||
| 160 | public $productCollectionShowCountOptionsXpath; |
||
| 161 | public $productCollectionProductCountXpath; |
||
| 162 | |||
| 163 | public $simpleProductQtyXpath; |
||
| 164 | |||
| 165 | public $layeredNavigationBaseXpath; |
||
| 166 | |||
| 167 | public $searchInputXpath; |
||
| 168 | public $searchSubmitXpath; |
||
| 169 | |||
| 170 | public $searchSuggestionTextXpath; |
||
| 171 | public $searchSuggestionCountXpath; |
||
| 172 | |||
| 173 | public $storeSwitcherInstructionsXpath; |
||
| 174 | |||
| 175 | public $configurableProductLabelXpath; |
||
| 176 | public $configurableSwatchSelectorXpath; |
||
| 177 | public $configurableSwatchImgXpath; |
||
| 178 | public $configurableSwatchNotAvailableXpath; |
||
| 179 | public $configurableSwatchOptionLabelAttributeName; |
||
| 180 | |||
| 181 | public $configurableProductOptionXpath; |
||
| 182 | |||
| 183 | public $viewModeAttributeName; |
||
| 184 | |||
| 185 | public $breadCrumbMemberXpath; |
||
| 186 | public $breadCrumbSelectorXpath; |
||
| 187 | |||
| 188 | public $layeredNavigationFilterNameXpath; |
||
| 189 | |||
| 190 | public $layeredNavigationFilterTypesXpath; |
||
| 191 | public $layeredNavigationFilterLinkXpath; |
||
| 192 | public $layeredNavigationFilterNameElementXpath; |
||
| 193 | public $layeredNavigationSwatchAppliesXpath; |
||
| 194 | public $layeredNavigationSwatchFilterTypesXpath; |
||
| 195 | public $layeredNavigationSwatchTitleAttribute; |
||
| 196 | |||
| 197 | abstract public function getCustomerThemeClass(); |
||
| 199 | |||
| 200 | public $guaranteedPageLoadedElementDisplayedXpath = '//div[contains(concat(" ",normalize-space(@class)," ")," footer ")]'; |
||
| 201 | |||
| 202 | public $contactUsNameXpath = '//form[@id="contactForm"]/descendant::input[@id="name"]'; |
||
| 203 | public $contactUsEmailXpath = '//form[@id="contactForm"]/descendant::input[@id="email"]'; |
||
| 204 | public $contactUsTelephoneXpath = '//form[@id="contactForm"]/descendant::input[@id="telephone"]'; |
||
| 205 | public $contactUsCommentXpath = '//form[@id="contactForm"]/descendant::textarea[@id="comment"]'; |
||
| 206 | public $contactUsSubmitXpath = '//form[@id="contactForm"]/descendant::button'; |
||
| 207 | |||
| 208 | |||
| 209 | public function configure(AbstractTestCase $testCase) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @return mixed |
||
| 216 | */ |
||
| 217 | public function getConfigurableSwatchOptionLabelAttributeName() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @return string |
||
| 224 | */ |
||
| 225 | public function getContactUsSubmitXpath() |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @return string |
||
| 232 | */ |
||
| 233 | public function getContactUsNameXpath() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @return string |
||
| 240 | */ |
||
| 241 | public function getContactUsEmailXpath() |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @return string |
||
| 248 | */ |
||
| 249 | public function getContactUsCommentXpath() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @return string |
||
| 256 | */ |
||
| 257 | public function getContactUsTelephoneXpath() |
||
| 261 | |||
| 262 | |||
| 263 | |||
| 264 | /** |
||
| 265 | * @return array |
||
| 266 | */ |
||
| 267 | public function getCartNavigationInstructions() |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @return string |
||
| 274 | */ |
||
| 275 | public function getLayeredNavigationSwatchTitleAttribute() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @return mixed |
||
| 282 | */ |
||
| 283 | public function getLayeredNavigationSwatchAppliesXpath($name) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @return mixed |
||
| 292 | */ |
||
| 293 | public function getLayeredNavigationSwatchFilterTypesXpath($name) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @return mixed |
||
| 300 | */ |
||
| 301 | public function getLayeredNavigationFilterNameElementXpath($name) |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @return string |
||
| 308 | */ |
||
| 309 | public function getLayeredNavigationFilterTypesXpath($type) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | public function getLayeredNavigationFilterLinkXpath($type) |
||
| 321 | |||
| 322 | |||
| 323 | |||
| 324 | /** |
||
| 325 | * @return mixed |
||
| 326 | */ |
||
| 327 | public function getLayeredNavigationFilterNameXpath() |
||
| 331 | |||
| 332 | public function getBreadCrumbMemberXpath($name) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @return mixed |
||
| 339 | */ |
||
| 340 | public function getBreadCrumbSelectorXpath($test) |
||
| 344 | |||
| 345 | |||
| 346 | |||
| 347 | /** |
||
| 348 | * @return mixed |
||
| 349 | */ |
||
| 350 | public function getConfigurableProductOptionXpath($swatchCount, $label) |
||
| 362 | |||
| 363 | public function getConfigurableSwatchImgXpath($swatchCount, $optionCount) |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @return string |
||
| 377 | */ |
||
| 378 | public function getConfigurableLabelXpath() |
||
| 382 | |||
| 383 | public function filterConfigurableProductOptionName($swatch) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @return string |
||
| 390 | */ |
||
| 391 | public function getConfigurableSwatchNotAvailableXpath($swatchCount, $optionCount) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * @return string |
||
| 405 | */ |
||
| 406 | public function getConfigurableSwatchSelectorXpath($swatchCount, $optionCount) |
||
| 417 | |||
| 418 | |||
| 419 | |||
| 420 | /** |
||
| 421 | * @return mixed |
||
| 422 | */ |
||
| 423 | public function getDefaultSimpleProductName() |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @return mixed |
||
| 430 | */ |
||
| 431 | public function getDefaultConfigurableProductName() |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @return mixed |
||
| 438 | */ |
||
| 439 | public function getSimpleProductQtyXpath() |
||
| 443 | |||
| 444 | public function getGuaranteedPageLoadedElementDisplayedXpath() |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @param mixed $guaranteedPageLoadedElementDisplayedXpath |
||
| 451 | */ |
||
| 452 | public function setGuaranteedPageLoadedElementDisplayedXpath($guaranteedPageLoadedElementDisplayedXpath) |
||
| 456 | |||
| 457 | /** |
||
| 458 | * @return mixed |
||
| 459 | */ |
||
| 460 | public function getStoreSwitcherInstructionsXpath($store) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * @return mixed |
||
| 473 | */ |
||
| 474 | public function getSearchSuggestionTextXpath($count) |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @return mixed |
||
| 482 | */ |
||
| 483 | public function getSearchSuggestionCountXpath($count) |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @return mixed |
||
| 491 | */ |
||
| 492 | public function getSearchSubmitXpath() |
||
| 496 | |||
| 497 | /** |
||
| 498 | * @return mixed |
||
| 499 | */ |
||
| 500 | public function getSearchInputXpath() |
||
| 504 | |||
| 505 | /** |
||
| 506 | * @return mixed |
||
| 507 | */ |
||
| 508 | public function getCategorySpecificProductPageXpath($productName) |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @return mixed |
||
| 516 | */ |
||
| 517 | public function getHomeXpath() |
||
| 521 | |||
| 522 | /** |
||
| 523 | * @return mixed |
||
| 524 | */ |
||
| 525 | public function getLayeredNavigationBaseXpath() |
||
| 529 | |||
| 530 | /** |
||
| 531 | * @return mixed |
||
| 532 | */ |
||
| 533 | public function getProductCollectionViewModeXpath() |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @return mixed |
||
| 540 | */ |
||
| 541 | public function getProductCollectionSortByXpath() |
||
| 545 | |||
| 546 | public function getViewModeAttributeName() |
||
| 550 | |||
| 551 | /** |
||
| 552 | * @return mixed |
||
| 553 | */ |
||
| 554 | public function getProductCollectionShowCountXpath() |
||
| 558 | |||
| 559 | /** |
||
| 560 | * @return mixed |
||
| 561 | */ |
||
| 562 | public function getProductCollectionShowCountOptionsXpath() |
||
| 566 | |||
| 567 | /** |
||
| 568 | * @return mixed |
||
| 569 | */ |
||
| 570 | public function getProductCollectionProductCountXpath() |
||
| 574 | |||
| 575 | |||
| 576 | |||
| 577 | /** |
||
| 578 | * @return mixed |
||
| 579 | */ |
||
| 580 | public function getProductListAddToCartLinkXpath($count) |
||
| 584 | |||
| 585 | /** |
||
| 586 | * @return mixed |
||
| 587 | */ |
||
| 588 | public function getProductGridAddToCartLinkXpath($count) |
||
| 592 | |||
| 593 | /** |
||
| 594 | * @return mixed |
||
| 595 | */ |
||
| 596 | public function getProductListDescriptionXpath($count) |
||
| 600 | |||
| 601 | /** |
||
| 602 | * @return mixed |
||
| 603 | */ |
||
| 604 | public function getProductListTitleXpath($count) |
||
| 608 | |||
| 609 | /** |
||
| 610 | * @return mixed |
||
| 611 | */ |
||
| 612 | public function getProductListCompareLinkXpath($count) |
||
| 616 | |||
| 617 | /** |
||
| 618 | * @return mixed |
||
| 619 | */ |
||
| 620 | public function getProductListImageXpath($count) |
||
| 624 | |||
| 625 | /** |
||
| 626 | * @return mixed |
||
| 627 | */ |
||
| 628 | public function getProductListLinkXpath($count) |
||
| 632 | |||
| 633 | /** |
||
| 634 | * @return mixed |
||
| 635 | */ |
||
| 636 | public function getProductListOriginalPriceXpath($count) |
||
| 640 | |||
| 641 | /** |
||
| 642 | * @return mixed |
||
| 643 | */ |
||
| 644 | public function getProductListPriceXpath($count) |
||
| 648 | |||
| 649 | /** |
||
| 650 | * @return mixed |
||
| 651 | */ |
||
| 652 | public function getProductListWishlistLinkXpath($count) |
||
| 656 | |||
| 657 | /** |
||
| 658 | * @return mixed |
||
| 659 | */ |
||
| 660 | public function getProductGridDescriptionXpath($count) |
||
| 664 | |||
| 665 | /** |
||
| 666 | * @return mixed |
||
| 667 | */ |
||
| 668 | public function getProductGridTitleXpath($count) |
||
| 672 | |||
| 673 | /** |
||
| 674 | * @return mixed |
||
| 675 | */ |
||
| 676 | public function getProductGridCompareLinkXpath($count) |
||
| 680 | |||
| 681 | /** |
||
| 682 | * @return mixed |
||
| 683 | */ |
||
| 684 | public function getProductGridImageXpath($count) |
||
| 688 | |||
| 689 | /** |
||
| 690 | * @return mixed |
||
| 691 | */ |
||
| 692 | public function getProductGridLinkXpath($count) |
||
| 696 | |||
| 697 | /** |
||
| 698 | * @return mixed |
||
| 699 | */ |
||
| 700 | public function getProductGridOriginalPriceXpath($count) |
||
| 704 | |||
| 705 | /** |
||
| 706 | * @return mixed |
||
| 707 | */ |
||
| 708 | public function getProductGridPriceXpath($count) |
||
| 712 | |||
| 713 | /** |
||
| 714 | * @return mixed |
||
| 715 | */ |
||
| 716 | public function getProductGridWishlistLinkXpath($count) |
||
| 720 | |||
| 721 | /** |
||
| 722 | * @return mixed |
||
| 723 | */ |
||
| 724 | public function getBreadCrumbXpath() |
||
| 728 | |||
| 729 | /** |
||
| 730 | * @return mixed |
||
| 731 | */ |
||
| 732 | public function getLayeredNavigationTestXpath() |
||
| 736 | |||
| 737 | public function getBaseUrl() |
||
| 741 | |||
| 742 | /** |
||
| 743 | * @return string |
||
| 744 | */ |
||
| 745 | public function getLogoutSuccessXpath() |
||
| 749 | |||
| 750 | /** |
||
| 751 | * @return array |
||
| 752 | */ |
||
| 753 | public function getLogoutNavigationInstructions() |
||
| 757 | |||
| 758 | |||
| 759 | /** |
||
| 760 | * @return string |
||
| 761 | */ |
||
| 762 | public function getMyAccountTitle() |
||
| 766 | |||
| 767 | /** |
||
| 768 | * @return string |
||
| 769 | */ |
||
| 770 | public function getRegisterFirstNameXpath() |
||
| 774 | |||
| 775 | /** |
||
| 776 | * @return string |
||
| 777 | */ |
||
| 778 | public function getRegisterLastNameXpath() |
||
| 782 | |||
| 783 | /** |
||
| 784 | * @return string |
||
| 785 | */ |
||
| 786 | public function getRegisterEmailXpath() |
||
| 790 | |||
| 791 | /** |
||
| 792 | * @return string |
||
| 793 | */ |
||
| 794 | public function getRegisterPasswordXpath() |
||
| 798 | |||
| 799 | /** |
||
| 800 | * @return string |
||
| 801 | */ |
||
| 802 | public function getRegisterConfirmPasswordXpath() |
||
| 806 | |||
| 807 | /** |
||
| 808 | * @return string |
||
| 809 | */ |
||
| 810 | public function getRegisterNewsletterXpath() |
||
| 814 | |||
| 815 | /** |
||
| 816 | * @return string |
||
| 817 | */ |
||
| 818 | public function getRegisterSubmitXpath() |
||
| 822 | |||
| 823 | /** |
||
| 824 | * @return array |
||
| 825 | */ |
||
| 826 | public function getRegistrationNavigationInstructions() |
||
| 830 | |||
| 831 | public function getCheckoutNavigationInstructions() |
||
| 835 | |||
| 836 | public function getProductPageForCategory() |
||
| 840 | |||
| 841 | public function getAddToCartSuccessXpath() |
||
| 845 | |||
| 846 | public function getNavigateToCustomerPageInstructions() |
||
| 850 | |||
| 851 | public function getNavigationBaseXPathSelector() |
||
| 855 | |||
| 856 | public function getNavigationChildXPathSelector($text) |
||
| 861 | |||
| 862 | public function getNavigationPathToSimpleProductCategory() |
||
| 866 | |||
| 867 | public function getNavigationPathToConfigurableProductCategory() |
||
| 871 | |||
| 872 | public function getCategoryAddToCartButtonXPathSelector() |
||
| 876 | |||
| 877 | |||
| 878 | public function getAddToCartXpath() |
||
| 882 | |||
| 883 | |||
| 884 | |||
| 885 | } |