Complex classes like ThemeConfiguration 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 ThemeConfiguration, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class ThemeConfiguration extends AbstractConfigurableElement implements NavigableThemeInterface |
||
|
|||
10 | { |
||
11 | |||
12 | const THEME = 'Magium\Magento\Themes\Admin\ThemeConfiguration'; |
||
13 | |||
14 | public $baseUrl = 'http://localhost/admin'; |
||
15 | |||
16 | public $homeXpath = '//img[@class="logo"]'; |
||
17 | |||
18 | public $loginUsernameField = '//input[@type="text" and @id="username"]'; |
||
19 | public $loginPasswordField = '//input[@type="password" and @id="login"]'; |
||
20 | public $loginSubmitButton = '//input[@type="submit" and @value="{{Login}}"]'; |
||
21 | |||
22 | public $navigationBaseXPathSelector = '//ul[@id="nav"]'; |
||
23 | // public $navigationChildXPathSelector1 = 'li/descendant::span[.="{{%s}}"]'; |
||
24 | public $navigationChildXPathSelector = 'a[concat(" ",normalize-space(.)," ") = " {{%s}} "]/..'; |
||
25 | |||
26 | public $adminPopupMessageContainerXpath = '//*[@id="message-popup-window"]'; |
||
27 | public $adminPopupMessageCloseButtonXpath = '//*[@id="message-popup-window"]/descendant::*[@title="close"]'; |
||
28 | |||
29 | public $systemConfigTabsXpath = '//ul[@id="system_config_tabs"]/descendant::a[concat(" ",normalize-space(.)," ") = " {{%s}} "]'; |
||
30 | public $systemConfigSectionToggleXpath = '//form[@id="config_edit_form"]/descendant::div[contains(concat(" ",normalize-space(@class)," ")," section-config ")]/descendant::a[.="{{%s}}"]'; |
||
31 | public $systemConfigSectionDisplayCheckXpath = '//legend[.="{{%s}}"]/ancestor::fieldset'; |
||
32 | public $systemConfigToggleEnableXpath = '//legend[.="{{%s}}"]/../descendant::td[concat(" ",normalize-space(.)," ") = " {{Enabled}} "]/../td/descendant::select/option[@value="%d"]'; |
||
33 | |||
34 | public $xTreeRootXpath = '//ul[contains(concat(" ",normalize-space(@class)," ")," x-tree-root-ct ")]/div/li[contains(concat(" ",normalize-space(@class)," ")," x-tree-node ")]/div/a'; |
||
35 | public $xTreeNamedRootXpath = '//ul[contains(concat(" ",normalize-space(@class)," ")," x-tree-root-ct ")]/div/li[contains(concat(" ",normalize-space(@class)," ")," x-tree-node ")]/div/a[contains(concat("---",normalize-space(.)), "---{{%s}} (")]'; |
||
36 | public $xTreeChildXpath = 'ul/li[contains(concat(" ",normalize-space(@class)," ")," x-tree-node ")]/div/a/span[contains(concat("---",normalize-space(.)), "---{{%s}} (")]/..'; |
||
37 | public $xTreeChildNodePrefixXpath = '/../..'; |
||
38 | public $xTreeChildNodeExpandPrefixXpath = '/../img[contains(concat(" ",normalize-space(@class)," ")," x-tree-ec-icon ")]'; |
||
39 | |||
40 | public $systemConfigurationSaveButtonXpath = '//div[@class="main-col-inner"]/div[@class="content-header"]/descendant::button[@title="{{Save Config}}"]'; |
||
41 | |||
42 | public $systemConfigSaveSuccessfulXpath = '//li[@class="success-msg"]/descendant::span[.="{{The configuration has been saved}}."]'; |
||
43 | |||
44 | public $testLoggedInAtBaseUrl = '//a[@class="active"]/span[.="{{Dashboard}}"]'; |
||
45 | |||
46 | public $tableButtonXpath = '//table[@class="actions"]/descendant::span[.="{{%s}}"]'; |
||
47 | |||
48 | public $selectOrderXpath = '//table[@id="sales_order_grid_table"]/descendant::td[concat(" ",normalize-space(.)," ") = " %s "]/../td/a[.="{{View}}"]'; |
||
49 | public $selectCustomerXpath = '//table[@id="customerGrid_table"]/descendant::td[concat(" ",normalize-space(.)," ") = " %s "]/../td/a[.="{{Edit}}"]'; |
||
50 | |||
51 | public $systemConfigSettingLabelXpath = '//td[@class="label"]/label[.=" {{%s}}"]'; |
||
52 | |||
53 | public $widgetTabXpath = '//a[contains(@class, "tab-item-link")]/span[.="{{%s}}"]'; |
||
54 | public $widgetTabHeaderXpath = '//div[@class="entry-edit-head"]/h4[.="{{%s}}"]'; |
||
55 | public $widgetAttributeByLabelXpath = '//table[@class="form-list"]/descendant::td[@class="label"]/label[.="{{%s}} *" or .="{{%s}}*" or .="{{%s}} " or .="{{%s}}"]/ancestor::tr/td[@class="value"]/*[@name]'; |
||
56 | public $widgetActionButtonXpath = '//div[@class="content-header"]/descendant::button/descendant::span[.="{{%s}}"]'; |
||
57 | |||
58 | public $guaranteedPageLoadedElementDisplayedXpath = '//div[@class="footer"]'; |
||
59 | |||
60 | public $successfulActionXpath = '//li[@class="success-msg"]'; |
||
61 | public $errorActionXpath = '//li[@class="error-msg"]'; |
||
62 | |||
63 | public $shippingCarrierXpath = '//select[@name="tracking[%d][carrier_code]"]'; |
||
64 | public $shippingTitleXpath = '//input[@name="tracking[%d][title]"]'; |
||
65 | public $shippingTrackingNumberXpath = '//input[@name="tracking[%d][number]"]'; |
||
66 | |||
67 | public $formButtonXpath = '//div[@class="content-header"]/p[@class="form-buttons"]/descendant::span[.="{{%s}}"]'; |
||
68 | |||
69 | public $cacheNavigationPath = '{{System}}/{{Cache Management}}'; |
||
70 | |||
71 | public $cacheTargetXpath = '//input[@name="types" and @value="{{%s}}"]'; |
||
72 | |||
73 | public $cacheAllTargetsXpath = '//input[@name="types"]'; |
||
74 | |||
75 | public $cacheMassActionOptionXpath = '//select[@id="cache_grid_massaction-select"]/option[@value="{{%s}}"]'; |
||
76 | |||
77 | public $cacheSubmitXpath = '//button[@title="{{Submit}}"]'; |
||
78 | |||
79 | public $firstTermsRowXpath = '//table[@id="agreementGrid_table"]/tbody/tr/td[not(contains(concat(" ",normalize-space(@class)," ")," empty-text "))]'; |
||
80 | |||
81 | public $orderCancelledMessageXpath = '//div[@id="messages"]/descendant::span[contains(., "{{The order has been cancelled}}")]'; |
||
82 | |||
83 | public $loadingMaskXpath = '//*[@id="loading-mask"]'; |
||
84 | |||
85 | public $defaultAdminTitle = '{{Dashboard}}'; |
||
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getDefaultAdminTitle() |
||
94 | |||
95 | public function getLoadMaskXpath() |
||
99 | |||
100 | /** |
||
101 | * @return string |
||
102 | */ |
||
103 | public function getOrderCancelledMessageXpath() |
||
107 | |||
108 | |||
109 | |||
110 | /** |
||
111 | * @return string |
||
112 | */ |
||
113 | public function getFirstTermsRowXpath() |
||
117 | |||
118 | /** |
||
119 | * @return string |
||
120 | */ |
||
121 | public function getCacheSubmitXpath() |
||
125 | |||
126 | |||
127 | |||
128 | /** |
||
129 | * @return string |
||
130 | */ |
||
131 | public function getCacheMassActionOptionXpath($option) |
||
136 | |||
137 | |||
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getCacheAllTargetsXpath() |
||
146 | |||
147 | |||
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | public function getCacheTargetXpath($type) |
||
157 | |||
158 | |||
159 | |||
160 | /** |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getCacheNavigationPath() |
||
167 | |||
168 | |||
169 | public function getFormButtonXpath($button) |
||
174 | |||
175 | /** |
||
176 | * @return string |
||
177 | */ |
||
178 | public function getShippingCarrierXpath($count) |
||
183 | |||
184 | /** |
||
185 | * @return string |
||
186 | */ |
||
187 | public function getShippingTitleXpath($count) |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | public function getShippingTrackingNumberXpath($count) |
||
201 | |||
202 | |||
203 | |||
204 | /** |
||
205 | * @return string |
||
206 | */ |
||
207 | public function getXTreeChildNodeExpandPrefixXpath() |
||
211 | |||
212 | /** |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getXTreeNamedRootXpath($category) |
||
220 | |||
221 | |||
222 | |||
223 | |||
224 | /** |
||
225 | * @return string |
||
226 | */ |
||
227 | public function getXTreeChildNodePrefixXpath() |
||
231 | |||
232 | /** |
||
233 | * @return string |
||
234 | */ |
||
235 | public function getXTreeChildXpath($name) |
||
240 | |||
241 | /** |
||
242 | * @return string |
||
243 | */ |
||
244 | public function getXTreeRootXpath() |
||
248 | |||
249 | |||
250 | |||
251 | public function set($name, $value) |
||
255 | |||
256 | /** |
||
257 | * @return string |
||
258 | */ |
||
259 | public function getSuccessfulActionXpath() |
||
263 | |||
264 | /** |
||
265 | * @return string |
||
266 | */ |
||
267 | public function getErrorActionXpath() |
||
271 | |||
272 | |||
273 | |||
274 | /** |
||
275 | * @return string |
||
276 | */ |
||
277 | public function getWidgetActionButtonXpath($label) |
||
281 | |||
282 | /** |
||
283 | * @return string |
||
284 | */ |
||
285 | public function getWidgetAttributeByLabelXpath($attribute) |
||
289 | |||
290 | |||
291 | |||
292 | /** |
||
293 | * @return string |
||
294 | */ |
||
295 | public function getWidgetTabHeaderXpath($name) |
||
299 | |||
300 | /** |
||
301 | * @return string |
||
302 | */ |
||
303 | public function getWidgetTabXpath($name) |
||
307 | |||
308 | |||
309 | |||
310 | public function getGuaranteedPageLoadedElementDisplayedXpath() |
||
314 | |||
315 | /** |
||
316 | * @param mixed $guaranteedPageLoadedElementDisplayedXpath |
||
317 | */ |
||
318 | public function setGuaranteedPageLoadedElementDisplayedXpath($guaranteedPageLoadedElementDisplayedXpath) |
||
322 | |||
323 | /** |
||
324 | * @return string |
||
325 | */ |
||
326 | public function getHomeXpath() |
||
330 | |||
331 | /** |
||
332 | * @return string |
||
333 | */ |
||
334 | public function getSystemConfigSettingLabelXpath($label) |
||
339 | |||
340 | /** |
||
341 | * Why is this an option? So you can have a different theme setup for different languages and still use the same code. |
||
342 | * |
||
343 | * @var string |
||
344 | */ |
||
345 | |||
346 | public $searchButtonText = '{{Search}}'; |
||
347 | |||
348 | /** |
||
349 | * @return Translator |
||
350 | */ |
||
351 | public function getTranslator() |
||
355 | |||
356 | /** |
||
357 | * @return string |
||
358 | */ |
||
359 | public function getLoginUsernameField() |
||
363 | |||
364 | /** |
||
365 | * @return string |
||
366 | */ |
||
367 | public function getLoginPasswordField() |
||
371 | |||
372 | /** |
||
373 | * @return string |
||
374 | */ |
||
375 | public function getLoginSubmitButton() |
||
379 | |||
380 | /** |
||
381 | * @return string |
||
382 | */ |
||
383 | public function getNavigationBaseXPathSelector() |
||
387 | |||
388 | /** |
||
389 | * @return string |
||
390 | */ |
||
391 | public function getNavigationChildXPathSelector($text) |
||
396 | |||
397 | /** |
||
398 | * @return mixed |
||
399 | */ |
||
400 | public function getBaseUrl() |
||
404 | |||
405 | /** |
||
406 | * @return string |
||
407 | */ |
||
408 | public function getSearchButtonText() |
||
412 | |||
413 | |||
414 | |||
415 | /** |
||
416 | * @return string |
||
417 | */ |
||
418 | public function getSelectOrderXpath($order) |
||
423 | /** |
||
424 | * @return string |
||
425 | */ |
||
426 | public function getSelectCustomerXpath($value) |
||
431 | |||
432 | /** |
||
433 | * @return string |
||
434 | */ |
||
435 | public function getTableButtonXpath($buttonValue) |
||
440 | |||
441 | |||
442 | |||
443 | /** |
||
444 | * @return string |
||
445 | */ |
||
446 | public function getTestLoggedInAtBaseUrl() |
||
450 | |||
451 | |||
452 | |||
453 | /** |
||
454 | * @return string |
||
455 | */ |
||
456 | public function getSystemConfigSaveSuccessfulXpath() |
||
460 | |||
461 | /** |
||
462 | * @return string |
||
463 | */ |
||
464 | public function getSystemConfigurationSaveButtonXpath() |
||
468 | |||
469 | /** |
||
470 | * @return string |
||
471 | */ |
||
472 | public function getSystemConfigSectionToggleXpath($section) |
||
477 | |||
478 | /** |
||
479 | * @return string |
||
480 | */ |
||
481 | public function getSystemConfigSectionDisplayCheckXpath($section) |
||
486 | |||
487 | /** |
||
488 | * @return string |
||
489 | */ |
||
490 | public function getSystemConfigToggleEnableXpath($section, $option) |
||
495 | |||
496 | /** |
||
497 | * @return string |
||
498 | */ |
||
499 | public function getSystemConfigTabsXpath($tabName) |
||
504 | |||
505 | |||
506 | public function getAdminPopupMessageContainerXpath() |
||
510 | |||
511 | public function getAdminPopupMessageCloseButtonXpath() |
||
515 | |||
516 | public function getUseClicksToNavigate() |
||
520 | |||
521 | public function configure(AbstractTestCase $testCase) |
||
525 | |||
526 | } |
||
527 |