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 | * @When I do not specify its slug  | 
            ||
| 129 | */  | 
            ||
| 130 | public function iSetItsSlugTo($slug = null)  | 
            ||
| 141 | |||
| 142 | /**  | 
            ||
| 143 | * @Then the slug field should not be editable  | 
            ||
| 144 | */  | 
            ||
| 145 | public function theSlugFieldShouldNotBeEditable()  | 
            ||
| 152 | |||
| 153 | /**  | 
            ||
| 154 | * @When I enable slug modification  | 
            ||
| 155 | */  | 
            ||
| 156 | public function iEnableSlugModification()  | 
            ||
| 160 | |||
| 161 | /**  | 
            ||
| 162 | * @When I change its description to :description in :language  | 
            ||
| 163 | */  | 
            ||
| 164 | public function iChangeItsDescriptionToIn($description, $language)  | 
            ||
| 168 | |||
| 169 | /**  | 
            ||
| 170 | * @When I describe it as :description in :language  | 
            ||
| 171 | */  | 
            ||
| 172 | public function iDescribeItAs($description, $language)  | 
            ||
| 176 | |||
| 177 | /**  | 
            ||
| 178 |      * @When /^I move up ("[^"]+" taxon)$/ | 
            ||
| 179 | */  | 
            ||
| 180 | public function iWantToMoveUpTaxon(TaxonInterface $taxon)  | 
            ||
| 184 | |||
| 185 | /**  | 
            ||
| 186 |      * @Given /^I choose ("[^"]+" as a parent taxon)$/ | 
            ||
| 187 | */  | 
            ||
| 188 | public function iChooseAsAParentTaxon(TaxonInterface $taxon)  | 
            ||
| 192 | |||
| 193 | /**  | 
            ||
| 194 | * @Given /^I change its (parent taxon to "[^"]+")$/  | 
            ||
| 195 | */  | 
            ||
| 196 | public function iChangeItsParentTaxonTo(TaxonInterface $taxon)  | 
            ||
| 200 | |||
| 201 | /**  | 
            ||
| 202 | * @When I do not specify its code  | 
            ||
| 203 | */  | 
            ||
| 204 | public function iDoNotSpecifyItsCode()  | 
            ||
| 208 | |||
| 209 | /**  | 
            ||
| 210 | * @When I do not specify its name  | 
            ||
| 211 | */  | 
            ||
| 212 | public function iDoNotSpecifyItsName()  | 
            ||
| 216 | |||
| 217 | /**  | 
            ||
| 218 | * @When I delete taxon named :name  | 
            ||
| 219 | */  | 
            ||
| 220 | public function iDeleteTaxonNamed($name)  | 
            ||
| 225 | |||
| 226 | /**  | 
            ||
| 227 | * @When I add it  | 
            ||
| 228 | * @When I try to add it  | 
            ||
| 229 | */  | 
            ||
| 230 | public function iAddIt()  | 
            ||
| 234 | |||
| 235 | /**  | 
            ||
| 236 | * @When I save my changes  | 
            ||
| 237 | * @When I try to save my changes  | 
            ||
| 238 | */  | 
            ||
| 239 | public function iSaveMyChanges()  | 
            ||
| 243 | |||
| 244 | /**  | 
            ||
| 245 |      * @Then /^the ("[^"]+" taxon) should appear in the registry$/ | 
            ||
| 246 | */  | 
            ||
| 247 | public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon)  | 
            ||
| 255 | |||
| 256 | /**  | 
            ||
| 257 | * @Then this taxon :element should be :value  | 
            ||
| 258 | */  | 
            ||
| 259 | public function thisTaxonElementShouldBe($element, $value)  | 
            ||
| 266 | |||
| 267 | /**  | 
            ||
| 268 | * @Then the code field should be disabled  | 
            ||
| 269 | */  | 
            ||
| 270 | public function theCodeFieldShouldBeDisabled()  | 
            ||
| 277 | |||
| 278 | /**  | 
            ||
| 279 |      * @Then /^the slug of the ("[^"]+" taxon) should(?:| still) be "([^"]+)"$/ | 
            ||
| 280 | */  | 
            ||
| 281 | public function productSlugShouldBe(TaxonInterface $taxon, $slug)  | 
            ||
| 290 | |||
| 291 | /**  | 
            ||
| 292 | * @Then /^this taxon should (belongs to "[^"]+")$/  | 
            ||
| 293 | */  | 
            ||
| 294 | public function thisTaxonShouldBelongsTo(TaxonInterface $taxon)  | 
            ||
| 301 | |||
| 302 | /**  | 
            ||
| 303 | * @Given it should not belong to any other taxon  | 
            ||
| 304 | */  | 
            ||
| 305 | public function itShouldNotBelongToAnyOtherTaxon()  | 
            ||
| 314 | |||
| 315 | /**  | 
            ||
| 316 | * @Then I should be notified that taxon with this code already exists  | 
            ||
| 317 | */  | 
            ||
| 318 | public function iShouldBeNotifiedThatTaxonWithThisCodeAlreadyExists()  | 
            ||
| 325 | |||
| 326 | /**  | 
            ||
| 327 | * @Then I should be notified that taxon slug must be unique  | 
            ||
| 328 | */  | 
            ||
| 329 | public function iShouldBeNotifiedThatTaxonSlugMustBeUnique()  | 
            ||
| 336 | |||
| 337 | /**  | 
            ||
| 338 | * @Then I should be notified that :element is required  | 
            ||
| 339 | */  | 
            ||
| 340 | public function iShouldBeNotifiedThatIsRequired($element)  | 
            ||
| 347 | |||
| 348 | /**  | 
            ||
| 349 | * @Then /^there should still be only one taxon with code "([^"]+)"$/  | 
            ||
| 350 | */  | 
            ||
| 351 | public function thereShouldStillBeOnlyOneTaxonWithCode($code)  | 
            ||
| 358 | |||
| 359 | /**  | 
            ||
| 360 | * @Then /^Taxon named "([^"]+)" should not be added$/  | 
            ||
| 361 | * @Then the taxon named :name should no longer exist in the registry  | 
            ||
| 362 | */  | 
            ||
| 363 | public function taxonNamedShouldNotBeAdded($name)  | 
            ||
| 371 | |||
| 372 | /**  | 
            ||
| 373 | * @Then /^I should see (\d+) taxons on the list$/  | 
            ||
| 374 | */  | 
            ||
| 375 | public function iShouldSeeTaxonsInTheList($number)  | 
            ||
| 385 | |||
| 386 | /**  | 
            ||
| 387 | * @Then I should see the taxon named :name in the list  | 
            ||
| 388 | */  | 
            ||
| 389 | public function iShouldSeeTheTaxonNamedInTheList($name)  | 
            ||
| 397 | |||
| 398 | /**  | 
            ||
| 399 | * @When I attach the :path image with a code :code  | 
            ||
| 400 | */  | 
            ||
| 401 | public function iAttachImageWithACode($path, $code)  | 
            ||
| 408 | |||
| 409 | /**  | 
            ||
| 410 | * @When I attach the :path image without a code  | 
            ||
| 411 | */  | 
            ||
| 412 | public function iAttachImageWithoutACode($path)  | 
            ||
| 416 | |||
| 417 | /**  | 
            ||
| 418 | * @Then /^this taxon should have(?:| also) an image with a code "([^"]*)"$/  | 
            ||
| 419 | */  | 
            ||
| 420 | public function thisTaxonShouldHaveAnImageWithCode($code)  | 
            ||
| 427 | |||
| 428 | /**  | 
            ||
| 429 | * @Then /^this taxon should not have(?:| also) an image with a code "([^"]*)"$/  | 
            ||
| 430 | */  | 
            ||
| 431 | public function thisTaxonShouldNotHaveAnImageWithCode($code)  | 
            ||
| 438 | |||
| 439 | /**  | 
            ||
| 440 | * @When /^I remove(?:| also) an image with a code "([^"]*)"$/  | 
            ||
| 441 | */  | 
            ||
| 442 | public function iRemoveAnImageWithACode($code)  | 
            ||
| 446 | |||
| 447 | /**  | 
            ||
| 448 | * @When I remove the first image  | 
            ||
| 449 | */  | 
            ||
| 450 | public function iRemoveTheFirstImage()  | 
            ||
| 454 | |||
| 455 | /**  | 
            ||
| 456 | * @Then /^(this taxon) should not have any images$/  | 
            ||
| 457 | */  | 
            ||
| 458 | public function thisTaxonShouldNotHaveImages(TaxonInterface $taxon)  | 
            ||
| 468 | |||
| 469 | /**  | 
            ||
| 470 | * @When I change the image with the :code code to :path  | 
            ||
| 471 | */  | 
            ||
| 472 | public function iChangeItsImageToPathForTheCode($path, $code)  | 
            ||
| 476 | |||
| 477 | /**  | 
            ||
| 478 | * @Then I should be notified that the image with this code already exists  | 
            ||
| 479 | */  | 
            ||
| 480 | public function iShouldBeNotifiedThatTheImageWithThisCodeAlreadyExists()  | 
            ||
| 484 | |||
| 485 | /**  | 
            ||
| 486 | * @Then I should be notified that an image code is required  | 
            ||
| 487 | */  | 
            ||
| 488 | public function iShouldBeNotifiedThatAnImageCodeIsRequired()  | 
            ||
| 495 | |||
| 496 | /**  | 
            ||
| 497 | * @Then there should still be only one image in the :taxon taxon  | 
            ||
| 498 | */  | 
            ||
| 499 | public function thereShouldStillBeOnlyOneImageInThisTaxon(TaxonInterface $taxon)  | 
            ||
| 509 | |||
| 510 | /**  | 
            ||
| 511 | * @Then the image code field should be disabled  | 
            ||
| 512 | */  | 
            ||
| 513 | public function theImageCodeFieldShouldBeDisabled()  | 
            ||
| 520 | |||
| 521 | /**  | 
            ||
| 522 | * @Then I should be notified that the :imageNumber image should have an unique code  | 
            ||
| 523 | */  | 
            ||
| 524 | public function iShouldBeNotifiedThatTheFirstImageShouldHaveAnUniqueCode($imageNumber)  | 
            ||
| 533 | |||
| 534 | /**  | 
            ||
| 535 | * @Then the first taxon on the list should be :taxon  | 
            ||
| 536 | */  | 
            ||
| 537 | public function theFirstTaxonOnTheListShouldBe(TaxonInterface $taxon)  | 
            ||
| 549 | |||
| 550 | /**  | 
            ||
| 551 | * @Then they should have order like :firstTaxonName, :secondTaxonName, :thirdTaxonName and :fourthTaxonName  | 
            ||
| 552 | */  | 
            ||
| 553 | public function theyShouldHaveOrderLikeAnd(...$taxonsNames)  | 
            ||
| 561 | }  | 
            ||
| 562 |