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 | */ |
||
105 | public function iSpecifyItsCodeAs($code) |
||
109 | |||
110 | /** |
||
111 | * @When I name it :name in :language |
||
112 | */ |
||
113 | public function iNameItIn($name, $language) |
||
117 | |||
118 | /** |
||
119 | * @When I rename it to :name in :language |
||
120 | */ |
||
121 | public function iRenameItIn($name, $language) |
||
125 | |||
126 | /** |
||
127 | * @When I set its slug to :slug |
||
128 | */ |
||
129 | public function iSetItsSlugTo($slug) |
||
140 | |||
141 | /** |
||
142 | * @Then the slug field should not be editable |
||
143 | */ |
||
144 | public function theSlugFieldShouldNotBeEditable() |
||
151 | |||
152 | /** |
||
153 | * @When I enable slug modification |
||
154 | */ |
||
155 | public function iEnableSlugModification() |
||
159 | |||
160 | /** |
||
161 | * @When I change its description to :description in :language |
||
162 | */ |
||
163 | public function iChangeItsDescriptionToIn($description, $language) |
||
167 | |||
168 | /** |
||
169 | * @When I describe it as :description in :language |
||
170 | */ |
||
171 | public function iDescribeItAs($description, $language) |
||
175 | |||
176 | /** |
||
177 | * @When /^I move up ("[^"]+" taxon)$/ |
||
178 | */ |
||
179 | public function iWantToMoveUpTaxon(TaxonInterface $taxon) |
||
183 | |||
184 | /** |
||
185 | * @When /^I move ("[^"]+" taxon) before ("[^"]+" taxon)$/ |
||
186 | */ |
||
187 | public function iMoveTaxonBeforeTaxon(TaxonInterface $taxonToMove, TaxonInterface $targetTaxon) |
||
191 | |||
192 | /** |
||
193 | * @Given /^I choose ("[^"]+" as a parent taxon)$/ |
||
194 | */ |
||
195 | public function iChooseAsAParentTaxon(TaxonInterface $taxon) |
||
199 | |||
200 | /** |
||
201 | * @Given /^I change its (parent taxon to "[^"]+")$/ |
||
202 | */ |
||
203 | public function iChangeItsParentTaxonTo(TaxonInterface $taxon) |
||
207 | |||
208 | /** |
||
209 | * @When I do not specify its code |
||
210 | */ |
||
211 | public function iDoNotSpecifyItsCode() |
||
215 | |||
216 | /** |
||
217 | * @When I do not specify its name |
||
218 | */ |
||
219 | public function iDoNotSpecifyItsName() |
||
223 | |||
224 | /** |
||
225 | * @When I delete taxon named :name |
||
226 | */ |
||
227 | public function iDeleteTaxonNamed($name) |
||
232 | |||
233 | /** |
||
234 | * @When I add it |
||
235 | * @When I try to add it |
||
236 | */ |
||
237 | public function iAddIt() |
||
241 | |||
242 | /** |
||
243 | * @When I save my changes |
||
244 | * @When I try to save my changes |
||
245 | */ |
||
246 | public function iSaveMyChanges() |
||
250 | |||
251 | /** |
||
252 | * @Then /^the ("[^"]+" taxon) should appear in the registry$/ |
||
253 | */ |
||
254 | public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon) |
||
262 | |||
263 | /** |
||
264 | * @Then this taxon :element should be :value |
||
265 | */ |
||
266 | public function thisTaxonElementShouldBe($element, $value) |
||
273 | |||
274 | /** |
||
275 | * @Then the code field should be disabled |
||
276 | */ |
||
277 | public function theCodeFieldShouldBeDisabled() |
||
284 | |||
285 | /** |
||
286 | * @Then /^the slug of the ("[^"]+" taxon) should(?:| still) be "([^"]+)"$/ |
||
287 | */ |
||
288 | public function productSlugShouldBe(TaxonInterface $taxon, $slug) |
||
297 | |||
298 | /** |
||
299 | * @Then /^this taxon should (belongs to "[^"]+")$/ |
||
300 | */ |
||
301 | public function thisTaxonShouldBelongsTo(TaxonInterface $taxon) |
||
308 | |||
309 | /** |
||
310 | * @Given it should not belong to any other taxon |
||
311 | */ |
||
312 | public function itShouldNotBelongToAnyOtherTaxon() |
||
321 | |||
322 | /** |
||
323 | * @Then I should be notified that taxon with this code already exists |
||
324 | */ |
||
325 | public function iShouldBeNotifiedThatTaxonWithThisCodeAlreadyExists() |
||
332 | |||
333 | /** |
||
334 | * @Then I should be notified that :element is required |
||
335 | */ |
||
336 | public function iShouldBeNotifiedThatIsRequired($element) |
||
343 | |||
344 | /** |
||
345 | * @Then /^there should still be only one taxon with code "([^"]+)"$/ |
||
346 | */ |
||
347 | public function thereShouldStillBeOnlyOneTaxonWithCode($code) |
||
354 | |||
355 | /** |
||
356 | * @Then /^Taxon named "([^"]+)" should not be added$/ |
||
357 | * @Then the taxon named :name should no longer exist in the registry |
||
358 | */ |
||
359 | public function taxonNamedShouldNotBeAdded($name) |
||
367 | |||
368 | /** |
||
369 | * @Then /^I should see (\d+) taxons on the list$/ |
||
370 | */ |
||
371 | public function iShouldSeeTaxonsInTheList($number) |
||
381 | |||
382 | /** |
||
383 | * @Then I should see the taxon named :name in the list |
||
384 | */ |
||
385 | public function iShouldSeeTheTaxonNamedInTheList($name) |
||
393 | |||
394 | /** |
||
395 | * @When I attach the :path image with a code :code |
||
396 | */ |
||
397 | public function iAttachImageWithACode($path, $code) |
||
404 | |||
405 | /** |
||
406 | * @When I attach the :path image without a code |
||
407 | */ |
||
408 | public function iAttachImageWithoutACode($path) |
||
412 | |||
413 | /** |
||
414 | * @Then /^this taxon should have(?:| also) an image with a code "([^"]*)"$/ |
||
415 | */ |
||
416 | public function thisTaxonShouldHaveAnImageWithCode($code) |
||
423 | |||
424 | /** |
||
425 | * @Then /^this taxon should not have(?:| also) an image with a code "([^"]*)"$/ |
||
426 | */ |
||
427 | public function thisTaxonShouldNotHaveAnImageWithCode($code) |
||
434 | |||
435 | /** |
||
436 | * @When /^I remove(?:| also) an image with a code "([^"]*)"$/ |
||
437 | */ |
||
438 | public function iRemoveAnImageWithACode($code) |
||
442 | |||
443 | /** |
||
444 | * @When I remove the first image |
||
445 | */ |
||
446 | public function iRemoveTheFirstImage() |
||
450 | |||
451 | /** |
||
452 | * @Then /^(this taxon) should not have any images$/ |
||
453 | */ |
||
454 | public function thisTaxonShouldNotHaveImages(TaxonInterface $taxon) |
||
464 | |||
465 | /** |
||
466 | * @When I change the image with the :code code to :path |
||
467 | */ |
||
468 | public function iChangeItsImageToPathForTheCode($path, $code) |
||
472 | |||
473 | /** |
||
474 | * @Then I should be notified that the image with this code already exists |
||
475 | */ |
||
476 | public function iShouldBeNotifiedThatTheImageWithThisCodeAlreadyExists() |
||
480 | |||
481 | /** |
||
482 | * @Then I should be notified that an image code is required |
||
483 | */ |
||
484 | public function iShouldBeNotifiedThatAnImageCodeIsRequired() |
||
491 | |||
492 | /** |
||
493 | * @Then there should still be only one image in the :taxon taxon |
||
494 | */ |
||
495 | public function thereShouldStillBeOnlyOneImageInThisTaxon(TaxonInterface $taxon) |
||
505 | |||
506 | /** |
||
507 | * @Then the image code field should be disabled |
||
508 | */ |
||
509 | public function theImageCodeFieldShouldBeDisabled() |
||
516 | |||
517 | /** |
||
518 | * @Then I should be notified that the :imageNumber image should have an unique code |
||
519 | */ |
||
520 | public function iShouldBeNotifiedThatTheFirstImageShouldHaveAnUniqueCode($imageNumber) |
||
529 | |||
530 | /** |
||
531 | * @Then the first taxon on the list should be :taxon |
||
532 | */ |
||
533 | public function theFirstTaxonOnTheListShouldBe(TaxonInterface $taxon) |
||
545 | |||
546 | /** |
||
547 | * @Then they should have order like :firstTaxonName, :secondTaxonName, :thirdTaxonName and :fourthTaxonName |
||
548 | */ |
||
549 | public function theyShouldHaveOrderLikeAnd(...$taxonsNames) |
||
557 | } |
||
558 |