Complex classes like FeatureContext 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 FeatureContext, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
39 | class FeatureContext extends RawMinkContext implements KernelAwareInterface |
||
40 | { |
||
41 | /** |
||
42 | * |
||
43 | * Kernel. |
||
44 | * |
||
45 | * @var KernelInterface |
||
46 | */ |
||
47 | private $kernel; |
||
48 | |||
49 | /** |
||
50 | * |
||
51 | * Parameters. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | private $parameters; |
||
56 | |||
57 | /** |
||
58 | * |
||
59 | * Initializes context. |
||
60 | * Every scenario gets it's own context object. |
||
61 | * |
||
62 | * @param array $parameters context parameters (set them up through behat.yml) |
||
63 | */ |
||
64 | public function __construct(array $parameters) |
||
72 | |||
73 | /** |
||
74 | * |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function setKernel(KernelInterface $kernel) |
||
81 | |||
82 | /** |
||
83 | * |
||
84 | * @BeforeScenario |
||
85 | */ |
||
86 | public function purgeDatabase() |
||
93 | |||
94 | private function getPage() |
||
98 | |||
99 | /** |
||
100 | * |
||
101 | * @Given /^I am logged in as "([^"]*)"$/ |
||
102 | */ |
||
103 | public function iAmLoggedInAs($user) |
||
108 | |||
109 | private function getAttributesFromElement(NodeElement $element) |
||
121 | |||
122 | private function isSubstringInArray($attributes, $searchStr) |
||
132 | |||
133 | /** |
||
134 | * |
||
135 | * @Given /^I should see category named "([^"]*)" on category list$/ |
||
136 | */ |
||
137 | public function iShouldSeeCategoryNamedOnCategoryList($categoryId) |
||
141 | |||
142 | /** |
||
143 | * |
||
144 | * @Given /^I should not see category named "([^"]*)" on category list$/ |
||
145 | */ |
||
146 | public function iShouldNotSeeCategoryNamedOnCategoryList($categoryId) |
||
150 | |||
151 | /** |
||
152 | * |
||
153 | * @Given /^I should see board named "([^"]*)" on category list$/ |
||
154 | */ |
||
155 | public function iShouldSeeBoardNamedOnCategoryList($boardId) |
||
159 | |||
160 | /** |
||
161 | * |
||
162 | * @Given /^I should not see board named "([^"]*)" on category list$/ |
||
163 | */ |
||
164 | public function iShouldNotSeeBoardNamedOnCategoryList($boardId) |
||
168 | |||
169 | |||
170 | /** |
||
171 | * |
||
172 | * @Given /^I should see board named "([^"]*)" on topic list$/ |
||
173 | */ |
||
174 | public function iShouldSeeBoardNamedOnTopicList($topicId) |
||
178 | |||
179 | /** |
||
180 | * |
||
181 | * @Given /^I should not see board named "([^"]*)" on topic list$/ |
||
182 | */ |
||
183 | public function iShouldNotSeeBoardNamedOnTopicList($topicId) |
||
187 | |||
188 | /** |
||
189 | * |
||
190 | * @Given /^I should see topic named "([^"]*)" on topic list$/ |
||
191 | */ |
||
192 | public function iShouldSeeTopicNamedOnTopicList($topicId) |
||
196 | |||
197 | /** |
||
198 | * |
||
199 | * @Given /^I should not see topic named "([^"]*)" on topic list$/ |
||
200 | */ |
||
201 | public function iShouldNotSeeTopicNamedOnTopicList($topicId) |
||
205 | |||
206 | /** |
||
207 | * @Given /^I follow "([^"]*)" from the links on post "([^"]*)"$/ |
||
208 | */ |
||
209 | public function iFollowFromTheLinksOnPost($linkText, $postId) |
||
232 | |||
233 | /** |
||
234 | * |
||
235 | * @Given /^I should see "([^"]*)" from the links on post "([^"]*)"$/ |
||
236 | */ |
||
237 | public function shouldSeeFromTheLinksOnPost($text, $postId) |
||
256 | |||
257 | /** |
||
258 | * |
||
259 | * @Given /^I should not see "([^"]*)" from the links on post "([^"]*)"$/ |
||
260 | */ |
||
261 | public function shouldNotSeeFromTheLinksOnPost($text, $postId) |
||
280 | |||
281 | /** |
||
282 | * @Given /^I follow "([^"]*)" for the query "([^"]*)"$/ |
||
283 | */ |
||
284 | public function iFollowForTheQuery($linkText, $cssQuery) |
||
307 | |||
308 | /** |
||
309 | * |
||
310 | * @Then /^"([^"]*)" should precede "([^"]*)" for the query "([^"]*)"$/ |
||
311 | */ |
||
312 | public function shouldPrecedeForTheQuery($textBefore, $textAfter, $cssQuery) |
||
324 | |||
325 | /** |
||
326 | * |
||
327 | * @Given /^I should see "([^"]*)" for the query "([^"]*)"$/ |
||
328 | */ |
||
329 | public function iShouldSeeForTheQuery($text, $cssQuery) |
||
348 | |||
349 | /** |
||
350 | * |
||
351 | * @Given /^I should not see "([^"]*)" for the query "([^"]*)"$/ |
||
352 | */ |
||
353 | public function iShouldNotSeeForTheQuery($text, $cssQuery) |
||
372 | |||
373 | /** |
||
374 | * |
||
375 | * @Given /^I select from "([^"]*)" a date "([^"]*)"$/ |
||
376 | */ |
||
377 | public function iSelectFromADateDaysFromNow($cssQuery, $diff) |
||
426 | |||
427 | /** |
||
428 | * |
||
429 | * @Given /^I dump$/ |
||
430 | */ |
||
431 | public function iDump() |
||
435 | } |
||
436 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.