Complex classes like AdminContext 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 AdminContext, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class AdminContext extends PageObjectContext implements KernelAwareContext |
||
21 | { |
||
22 | /** |
||
23 | * @var KernelInterface |
||
24 | */ |
||
25 | protected $kernel; |
||
26 | |||
27 | public function setKernel(KernelInterface $kernel) |
||
31 | |||
32 | /** |
||
33 | * @Transform /^"([^"]*)" element/ |
||
34 | */ |
||
35 | public function transformListNameToAdminElement($id) |
||
39 | |||
40 | /** |
||
41 | * @Transform /^(\d+)/ |
||
42 | */ |
||
43 | public function castStringToNumber($number) |
||
47 | |||
48 | /** |
||
49 | * @Transform /^first|second|third$/ |
||
50 | */ |
||
51 | public function castWordToNumber($word) |
||
59 | |||
60 | /** |
||
61 | * @Given /^the following admin elements were registered$/ |
||
62 | */ |
||
63 | public function theFollowingAdminElementsWereRegistered(TableNode $table) |
||
73 | |||
74 | /** |
||
75 | * @Given /^("[^"]*" element) have following options defined$/ |
||
76 | */ |
||
77 | public function elementHaveFollowingOptionsDefined(AbstractElement $adminElement, TableNode $options) |
||
84 | |||
85 | /** |
||
86 | * @Given /^("[^"]*" element) has datasource with fields$/ |
||
87 | */ |
||
88 | public function elementHaveDatasourceWithFields(ListElement $adminElement) |
||
96 | |||
97 | /** |
||
98 | * @Given /^("[^"]*" element) has datasource without filters$/ |
||
99 | */ |
||
100 | public function elementHaveDatasourceWithoutFilters(ListElement $adminElement) |
||
115 | |||
116 | /** |
||
117 | * @Given /^there are following admin elements available$/ |
||
118 | */ |
||
119 | public function thereAreFollowingAdminElementsAvailable(TableNode $table) |
||
128 | |||
129 | /** |
||
130 | * @Given /^I am on the "([^"]*)" page$/ |
||
131 | */ |
||
132 | public function iAmOnThePage($pageName) |
||
136 | |||
137 | /** |
||
138 | * @Given /^I am on the "([^"]*)" page with id (\d+)$/ |
||
139 | */ |
||
140 | public function iAmOnThePageWithId($pageName, $id) |
||
144 | |||
145 | /** |
||
146 | * @When /^I follow "([^"]*)" url from top bar$/ |
||
147 | * @Given /^I follow "([^"]*)" menu element$/ |
||
148 | */ |
||
149 | public function iFollowUrlFromTopBar($menuElement) |
||
153 | |||
154 | /** |
||
155 | * @Then /^I should see "([^"]*)" title at top bar$/ |
||
156 | */ |
||
157 | public function iShouldSeeTitleAtTopBar($navbarBrandText) |
||
161 | |||
162 | /** |
||
163 | * @Then /^menu with following elements should be visible at the top of the page$/ |
||
164 | */ |
||
165 | public function menuWithFollowingElementsShouldBeVisibleAtTheTopOfThePage(TableNode $table) |
||
178 | |||
179 | /** |
||
180 | * @Given /^I should see "([^"]*)" page header "([^"]*)"$/ |
||
181 | */ |
||
182 | public function iShouldSeePageHeader($pageName, $headerContent) |
||
186 | |||
187 | /** |
||
188 | * @Given /^translations are enabled in application$/ |
||
189 | */ |
||
190 | public function translationsAreEnabledInApplication() |
||
194 | |||
195 | |||
196 | /** |
||
197 | * @Then /^I should see language dropdown button in navigation bar with text "([^"]*)"$/ |
||
198 | * @Then /^I should see language dropdown button with text "([^"]*)"$/ |
||
199 | */ |
||
200 | public function iShouldSeeLanguageDropdownButtonInNavigationBarWithText($button) |
||
204 | |||
205 | /** |
||
206 | * @Given /^language dropdown button should have following links$/ |
||
207 | */ |
||
208 | public function languageDropdownButtonShouldHaveFollowingLinks(TableNode $dropdownLinks) |
||
217 | |||
218 | /** |
||
219 | * @When /^I click "([^"]*)" link from language dropdown button$/ |
||
220 | */ |
||
221 | public function iClickLinkFromLanguageDropdownButton($link) |
||
225 | |||
226 | /** |
||
227 | * @Then /^I should see details about news at page$/ |
||
228 | */ |
||
229 | public function iShouldSeeDetailsAboutNewsAtPage() |
||
233 | |||
234 | /** |
||
235 | * @Transform /"([^"]*)" non-editable collection/ |
||
236 | * @Transform /non-editable collection "([^"]*)"/ |
||
237 | */ |
||
238 | public function transformToNoneditableCollection($collectionNames) |
||
242 | |||
243 | |||
244 | /** |
||
245 | * @Transform /^"([^"]*)" collection/ |
||
246 | * @Transform /collection "([^"]*)"/ |
||
247 | */ |
||
248 | public function transformToCollection($collectionNames) |
||
252 | /** |
||
253 | * @Given /^("[^"]*" collection) should have (\d+) elements$/ |
||
254 | * @Given /^(non-editable collection "[^"]*") should have (\d+) elements$/ |
||
255 | */ |
||
256 | public function collectionShouldHaveElements(NodeElement $collection, $elementsCount) |
||
261 | |||
262 | /** |
||
263 | * @Given /^(collection "[^"]*") should have "([^"]*)" button$/ |
||
264 | */ |
||
265 | public function collectionShouldHaveButton(NodeElement $collection, $buttonName) |
||
269 | |||
270 | /** |
||
271 | * @Then /^all buttons for adding and removing items in (non-editable collection "[^"]*") should be disabled$/ |
||
272 | */ |
||
273 | public function allCollectionButtonsDisabled(NodeElement $collection) |
||
286 | |||
287 | |||
288 | /** |
||
289 | * @When /^I press "([^"]*)" in (collection "[^"]*")$/ |
||
290 | */ |
||
291 | public function iPressInCollection($buttonName, NodeElement $collection) |
||
297 | |||
298 | /** |
||
299 | * @Given /^I fill "([^"]*)" with "([^"]*)" in (collection "[^"]*") at position (\d+)$/ |
||
300 | */ |
||
301 | public function iFillWithInCollectionAtPosition($fieldName, $fieldValue, NodeElement $collection, $position) |
||
306 | |||
307 | /** |
||
308 | * @Given /^I remove (\w+) element in (collection "[^"]*")$/ |
||
309 | */ |
||
310 | public function iRemoveElementInCollection($index, NodeElement $collection) |
||
315 | } |
||
316 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.