Complex classes like ManagingTaxonsContext 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 ManagingTaxonsContext, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | final class ManagingTaxonsContext implements Context |
||
28 | { |
||
29 | /** |
||
30 | * @var SharedStorageInterface |
||
31 | */ |
||
32 | private $sharedStorage; |
||
33 | |||
34 | /** |
||
35 | * @var CreatePageInterface |
||
36 | */ |
||
37 | private $createPage; |
||
38 | |||
39 | /** |
||
40 | * @var CreateForParentPageInterface |
||
41 | */ |
||
42 | private $createForParentPage; |
||
43 | |||
44 | /** |
||
45 | * @var UpdatePageInterface |
||
46 | */ |
||
47 | private $updatePage; |
||
48 | |||
49 | /** |
||
50 | * @var CurrentPageResolverInterface |
||
51 | */ |
||
52 | private $currentPageResolver; |
||
53 | |||
54 | /** |
||
55 | * @param SharedStorageInterface $sharedStorage |
||
56 | * @param CreatePageInterface $createPage |
||
57 | * @param CreateForParentPageInterface $createForParentPage |
||
58 | * @param UpdatePageInterface $updatePage |
||
59 | * @param CurrentPageResolverInterface $currentPageResolver |
||
60 | */ |
||
61 | public function __construct( |
||
74 | |||
75 | /** |
||
76 | * @Given I want to create a new taxon |
||
77 | * @Given I want to see all taxons in store |
||
78 | */ |
||
79 | public function iWantToCreateANewTaxon() |
||
83 | |||
84 | /** |
||
85 | * @Given I want to create a new taxon for :taxon |
||
86 | */ |
||
87 | public function iWantToCreateANewTaxonForParent(TaxonInterface $taxon) |
||
91 | |||
92 | /** |
||
93 | * @Given /^I want to modify the ("[^"]+" taxon)$/ |
||
94 | */ |
||
95 | public function iWantToModifyATaxon(TaxonInterface $taxon) |
||
101 | |||
102 | /** |
||
103 | * @When I specify its code as :code |
||
104 | * @When I do not specify its code |
||
105 | */ |
||
106 | public function iSpecifyItsCodeAs($code = null) |
||
110 | |||
111 | /** |
||
112 | * @When I name it :name in :language |
||
113 | * @When I rename it to :name in :language |
||
114 | * @When I do not specify its name |
||
115 | */ |
||
116 | public function iNameItIn($name = null, $language = 'en_US') |
||
122 | |||
123 | /** |
||
124 | * @When I set its slug to :slug |
||
125 | * @When I do not specify its slug |
||
126 | * @When I set its slug to :slug in :language |
||
127 | */ |
||
128 | public function iSetItsSlugToIn($slug = null, $language = 'en_US') |
||
134 | |||
135 | /** |
||
136 | * @Then the slug field should not be editable |
||
137 | * @Then the slug field should (also )not be editable in :language |
||
138 | */ |
||
139 | public function theSlugFieldShouldNotBeEditable($language = 'en_US') |
||
143 | |||
144 | /** |
||
145 | * @When I enable slug modification |
||
146 | * @When I enable slug modification in :language |
||
147 | */ |
||
148 | public function iEnableSlugModification($language = 'en_US') |
||
153 | |||
154 | /** |
||
155 | * @When I change its description to :description in :language |
||
156 | */ |
||
157 | public function iChangeItsDescriptionToIn($description, $language) |
||
161 | |||
162 | /** |
||
163 | * @When I describe it as :description in :language |
||
164 | */ |
||
165 | public function iDescribeItAs($description, $language) |
||
169 | |||
170 | /** |
||
171 | * @Given /^I change its (parent taxon to "[^"]+")$/ |
||
172 | */ |
||
173 | public function iChangeItsParentTaxonTo(TaxonInterface $taxon) |
||
177 | |||
178 | /** |
||
179 | * @When I delete taxon named :name |
||
180 | */ |
||
181 | public function iDeleteTaxonNamed($name) |
||
186 | |||
187 | /** |
||
188 | * @When I add it |
||
189 | * @When I try to add it |
||
190 | */ |
||
191 | public function iAddIt() |
||
195 | |||
196 | /** |
||
197 | * @When I save my changes |
||
198 | * @When I try to save my changes |
||
199 | */ |
||
200 | public function iSaveMyChanges() |
||
204 | |||
205 | /** |
||
206 | * @Then /^the ("[^"]+" taxon) should appear in the registry$/ |
||
207 | */ |
||
208 | public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon) |
||
213 | |||
214 | /** |
||
215 | * @Then this taxon :element should be :value |
||
216 | */ |
||
217 | public function thisTaxonElementShouldBe($element, $value) |
||
221 | |||
222 | /** |
||
223 | * @Then this taxon should have slug :value in :language |
||
224 | */ |
||
225 | public function thisTaxonElementShouldHaveSlugIn($value, $language = null) |
||
233 | |||
234 | /** |
||
235 | * @Then the code field should be disabled |
||
236 | */ |
||
237 | public function theCodeFieldShouldBeDisabled() |
||
241 | |||
242 | /** |
||
243 | * @Then /^the slug of the ("[^"]+" taxon) should(?:| still) be "([^"]+)"$/ |
||
244 | */ |
||
245 | public function productSlugShouldBe(TaxonInterface $taxon, $slug) |
||
251 | |||
252 | /** |
||
253 | * @Then /^this taxon should (belongs to "[^"]+")$/ |
||
254 | */ |
||
255 | public function thisTaxonShouldBelongsTo(TaxonInterface $taxon) |
||
259 | |||
260 | /** |
||
261 | * @Given it should not belong to any other taxon |
||
262 | */ |
||
263 | public function itShouldNotBelongToAnyOtherTaxon() |
||
267 | |||
268 | /** |
||
269 | * @Then I should be notified that taxon with this code already exists |
||
270 | */ |
||
271 | public function iShouldBeNotifiedThatTaxonWithThisCodeAlreadyExists() |
||
277 | |||
278 | /** |
||
279 | * @Then I should be notified that taxon slug must be unique |
||
280 | */ |
||
281 | public function iShouldBeNotifiedThatTaxonSlugMustBeUnique() |
||
287 | |||
288 | /** |
||
289 | * @Then I should be notified that :element is required |
||
290 | */ |
||
291 | public function iShouldBeNotifiedThatIsRequired($element) |
||
297 | |||
298 | /** |
||
299 | * @Then /^there should(?:| still) be only one taxon with code "([^"]+)"$/ |
||
300 | */ |
||
301 | public function thereShouldStillBeOnlyOneTaxonWithCode($code) |
||
305 | |||
306 | /** |
||
307 | * @Then /^taxon named "([^"]+)" should not be added$/ |
||
308 | * @Then the taxon named :name should no longer exist in the registry |
||
309 | */ |
||
310 | public function taxonNamedShouldNotBeAdded($name) |
||
314 | |||
315 | /** |
||
316 | * @Then /^I should see (\d+) taxons on the list$/ |
||
317 | */ |
||
318 | public function iShouldSeeTaxonsInTheList($number) |
||
322 | |||
323 | /** |
||
324 | * @Then I should see the taxon named :name in the list |
||
325 | */ |
||
326 | public function iShouldSeeTheTaxonNamedInTheList($name) |
||
330 | |||
331 | /** |
||
332 | * @When I attach the :path image with :type type |
||
333 | * @When I attach the :path image |
||
334 | */ |
||
335 | public function iAttachImageWithType($path, $type = null) |
||
341 | |||
342 | /** |
||
343 | * @Then /^(?:it|this taxon) should(?:| also) have an image with "([^"]*)" type$/ |
||
344 | */ |
||
345 | public function thisTaxonShouldHaveAnImageWithType($type) |
||
349 | |||
350 | /** |
||
351 | * @Then /^(?:this taxon|it) should not have(?:| also) any images with "([^"]*)" type$/ |
||
352 | */ |
||
353 | public function thisTaxonShouldNotHaveAnImageWithType($code) |
||
357 | |||
358 | /** |
||
359 | * @When /^I(?:| also) remove an image with "([^"]*)" type$/ |
||
360 | */ |
||
361 | public function iRemoveAnImageWithType($code) |
||
365 | |||
366 | /** |
||
367 | * @When I remove the first image |
||
368 | */ |
||
369 | public function iRemoveTheFirstImage() |
||
373 | |||
374 | /** |
||
375 | * @Then /^(this taxon) should not have any images$/ |
||
376 | */ |
||
377 | public function thisTaxonShouldNotHaveAnyImages(TaxonInterface $taxon) |
||
383 | |||
384 | /** |
||
385 | * @When I change the image with the :type type to :path |
||
386 | */ |
||
387 | public function iChangeItsImageToPathForTheType($path, $type) |
||
391 | |||
392 | /** |
||
393 | * @When I change the first image type to :type |
||
394 | */ |
||
395 | public function iChangeTheFirstImageTypeTo($type) |
||
399 | |||
400 | /** |
||
401 | * @Then /^(this taxon) should have only one image$/ |
||
402 | * @Then /^(this taxon) should(?:| still) have (\d+) images?$/ |
||
403 | */ |
||
404 | public function thereShouldStillBeOnlyOneImageInThisTaxon(TaxonInterface $taxon, $count = 1) |
||
410 | |||
411 | /** |
||
412 | * @return SymfonyPageInterface|CreatePageInterface|CreateForParentPageInterface|UpdatePageInterface |
||
413 | */ |
||
414 | private function resolveCurrentPage() |
||
422 | } |
||
423 |