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 function getLoadMaskXpath() |
||
89 | |||
90 | /** |
||
91 | * @return string |
||
92 | */ |
||
93 | public function getOrderCancelledMessageXpath() |
||
97 | |||
98 | |||
99 | |||
100 | /** |
||
101 | * @return string |
||
102 | */ |
||
103 | public function getFirstTermsRowXpath() |
||
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getCacheSubmitXpath() |
||
115 | |||
116 | |||
117 | |||
118 | /** |
||
119 | * @return string |
||
120 | */ |
||
121 | public function getCacheMassActionOptionXpath($option) |
||
126 | |||
127 | |||
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getCacheAllTargetsXpath() |
||
136 | |||
137 | |||
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getCacheTargetXpath($type) |
||
147 | |||
148 | |||
149 | |||
150 | /** |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getCacheNavigationPath() |
||
157 | |||
158 | |||
159 | public function getFormButtonXpath($button) |
||
164 | |||
165 | /** |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getShippingCarrierXpath($count) |
||
173 | |||
174 | /** |
||
175 | * @return string |
||
176 | */ |
||
177 | public function getShippingTitleXpath($count) |
||
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | */ |
||
186 | public function getShippingTrackingNumberXpath($count) |
||
191 | |||
192 | |||
193 | |||
194 | /** |
||
195 | * @return string |
||
196 | */ |
||
197 | public function getXTreeChildNodeExpandPrefixXpath() |
||
201 | |||
202 | /** |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getXTreeNamedRootXpath($category) |
||
210 | |||
211 | |||
212 | |||
213 | |||
214 | /** |
||
215 | * @return string |
||
216 | */ |
||
217 | public function getXTreeChildNodePrefixXpath() |
||
221 | |||
222 | /** |
||
223 | * @return string |
||
224 | */ |
||
225 | public function getXTreeChildXpath($name) |
||
230 | |||
231 | /** |
||
232 | * @return string |
||
233 | */ |
||
234 | public function getXTreeRootXpath() |
||
238 | |||
239 | |||
240 | |||
241 | public function set($name, $value) |
||
245 | |||
246 | /** |
||
247 | * @return string |
||
248 | */ |
||
249 | public function getSuccessfulActionXpath() |
||
253 | |||
254 | /** |
||
255 | * @return string |
||
256 | */ |
||
257 | public function getErrorActionXpath() |
||
261 | |||
262 | |||
263 | |||
264 | /** |
||
265 | * @return string |
||
266 | */ |
||
267 | public function getWidgetActionButtonXpath($label) |
||
271 | |||
272 | /** |
||
273 | * @return string |
||
274 | */ |
||
275 | public function getWidgetAttributeByLabelXpath($attribute) |
||
279 | |||
280 | |||
281 | |||
282 | /** |
||
283 | * @return string |
||
284 | */ |
||
285 | public function getWidgetTabHeaderXpath($name) |
||
289 | |||
290 | /** |
||
291 | * @return string |
||
292 | */ |
||
293 | public function getWidgetTabXpath($name) |
||
297 | |||
298 | |||
299 | |||
300 | public function getGuaranteedPageLoadedElementDisplayedXpath() |
||
304 | |||
305 | /** |
||
306 | * @param mixed $guaranteedPageLoadedElementDisplayedXpath |
||
307 | */ |
||
308 | public function setGuaranteedPageLoadedElementDisplayedXpath($guaranteedPageLoadedElementDisplayedXpath) |
||
312 | |||
313 | /** |
||
314 | * @return string |
||
315 | */ |
||
316 | public function getHomeXpath() |
||
320 | |||
321 | /** |
||
322 | * @return string |
||
323 | */ |
||
324 | public function getSystemConfigSettingLabelXpath($label) |
||
329 | |||
330 | /** |
||
331 | * Why is this an option? So you can have a different theme setup for different languages and still use the same code. |
||
332 | * |
||
333 | * @var string |
||
334 | */ |
||
335 | |||
336 | public $searchButtonText = '{{Search}}'; |
||
337 | |||
338 | /** |
||
339 | * @return Translator |
||
340 | */ |
||
341 | public function getTranslator() |
||
345 | |||
346 | /** |
||
347 | * @return string |
||
348 | */ |
||
349 | public function getLoginUsernameField() |
||
353 | |||
354 | /** |
||
355 | * @return string |
||
356 | */ |
||
357 | public function getLoginPasswordField() |
||
361 | |||
362 | /** |
||
363 | * @return string |
||
364 | */ |
||
365 | public function getLoginSubmitButton() |
||
369 | |||
370 | /** |
||
371 | * @return string |
||
372 | */ |
||
373 | public function getNavigationBaseXPathSelector() |
||
377 | |||
378 | /** |
||
379 | * @return string |
||
380 | */ |
||
381 | public function getNavigationChildXPathSelector($text) |
||
386 | |||
387 | /** |
||
388 | * @return mixed |
||
389 | */ |
||
390 | public function getBaseUrl() |
||
394 | |||
395 | /** |
||
396 | * @return string |
||
397 | */ |
||
398 | public function getSearchButtonText() |
||
402 | |||
403 | |||
404 | |||
405 | /** |
||
406 | * @return string |
||
407 | */ |
||
408 | public function getSelectOrderXpath($order) |
||
413 | /** |
||
414 | * @return string |
||
415 | */ |
||
416 | public function getSelectCustomerXpath($value) |
||
421 | |||
422 | /** |
||
423 | * @return string |
||
424 | */ |
||
425 | public function getTableButtonXpath($buttonValue) |
||
430 | |||
431 | |||
432 | |||
433 | /** |
||
434 | * @return string |
||
435 | */ |
||
436 | public function getTestLoggedInAtBaseUrl() |
||
440 | |||
441 | |||
442 | |||
443 | /** |
||
444 | * @return string |
||
445 | */ |
||
446 | public function getSystemConfigSaveSuccessfulXpath() |
||
450 | |||
451 | /** |
||
452 | * @return string |
||
453 | */ |
||
454 | public function getSystemConfigurationSaveButtonXpath() |
||
458 | |||
459 | /** |
||
460 | * @return string |
||
461 | */ |
||
462 | public function getSystemConfigSectionToggleXpath($section) |
||
467 | |||
468 | /** |
||
469 | * @return string |
||
470 | */ |
||
471 | public function getSystemConfigSectionDisplayCheckXpath($section) |
||
476 | |||
477 | /** |
||
478 | * @return string |
||
479 | */ |
||
480 | public function getSystemConfigToggleEnableXpath($section, $option) |
||
485 | |||
486 | /** |
||
487 | * @return string |
||
488 | */ |
||
489 | public function getSystemConfigTabsXpath($tabName) |
||
494 | |||
495 | |||
496 | public function getAdminPopupMessageContainerXpath() |
||
500 | |||
501 | public function getAdminPopupMessageCloseButtonXpath() |
||
505 | |||
506 | public function getUseClicksToNavigate() |
||
510 | |||
511 | public function configure(AbstractTestCase $testCase) |
||
515 | |||
516 | } |
||
517 |