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 | * @When I set its slug to :slug in :language  | 
            ||
| 130 | */  | 
            ||
| 131 | public function iSetItsSlugToIn($slug = null, $language = 'en_US')  | 
            ||
| 142 | |||
| 143 | /**  | 
            ||
| 144 | * @Then the slug field should not be editable  | 
            ||
| 145 | * @Then the slug field should (also )not be editable in :language  | 
            ||
| 146 | */  | 
            ||
| 147 | public function theSlugFieldShouldNotBeEditable($language = 'en_US')  | 
            ||
| 154 | |||
| 155 | /**  | 
            ||
| 156 | * @When I enable slug modification  | 
            ||
| 157 | * @When I enable slug modification in :language  | 
            ||
| 158 | */  | 
            ||
| 159 | public function iEnableSlugModification($language = 'en_US')  | 
            ||
| 164 | |||
| 165 | /**  | 
            ||
| 166 | * @When I change its description to :description in :language  | 
            ||
| 167 | */  | 
            ||
| 168 | public function iChangeItsDescriptionToIn($description, $language)  | 
            ||
| 172 | |||
| 173 | /**  | 
            ||
| 174 | * @When I describe it as :description in :language  | 
            ||
| 175 | */  | 
            ||
| 176 | public function iDescribeItAs($description, $language)  | 
            ||
| 180 | |||
| 181 | /**  | 
            ||
| 182 |      * @When /^I move up ("[^"]+" taxon)$/ | 
            ||
| 183 | */  | 
            ||
| 184 | public function iWantToMoveUpTaxon(TaxonInterface $taxon)  | 
            ||
| 188 | |||
| 189 | /**  | 
            ||
| 190 |      * @Given /^I choose ("[^"]+" as a parent taxon)$/ | 
            ||
| 191 | */  | 
            ||
| 192 | public function iChooseAsAParentTaxon(TaxonInterface $taxon)  | 
            ||
| 196 | |||
| 197 | /**  | 
            ||
| 198 | * @Given /^I change its (parent taxon to "[^"]+")$/  | 
            ||
| 199 | */  | 
            ||
| 200 | public function iChangeItsParentTaxonTo(TaxonInterface $taxon)  | 
            ||
| 204 | |||
| 205 | /**  | 
            ||
| 206 | * @When I do not specify its code  | 
            ||
| 207 | */  | 
            ||
| 208 | public function iDoNotSpecifyItsCode()  | 
            ||
| 212 | |||
| 213 | /**  | 
            ||
| 214 | * @When I do not specify its name  | 
            ||
| 215 | */  | 
            ||
| 216 | public function iDoNotSpecifyItsName()  | 
            ||
| 220 | |||
| 221 | /**  | 
            ||
| 222 | * @When I delete taxon named :name  | 
            ||
| 223 | */  | 
            ||
| 224 | public function iDeleteTaxonNamed($name)  | 
            ||
| 229 | |||
| 230 | /**  | 
            ||
| 231 | * @When I add it  | 
            ||
| 232 | * @When I try to add it  | 
            ||
| 233 | */  | 
            ||
| 234 | public function iAddIt()  | 
            ||
| 238 | |||
| 239 | /**  | 
            ||
| 240 | * @When I save my changes  | 
            ||
| 241 | * @When I try to save my changes  | 
            ||
| 242 | */  | 
            ||
| 243 | public function iSaveMyChanges()  | 
            ||
| 247 | |||
| 248 | /**  | 
            ||
| 249 |      * @Then /^the ("[^"]+" taxon) should appear in the registry$/ | 
            ||
| 250 | */  | 
            ||
| 251 | public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon)  | 
            ||
| 259 | |||
| 260 | /**  | 
            ||
| 261 | * @Then this taxon :element should be :value  | 
            ||
| 262 | */  | 
            ||
| 263 | public function thisTaxonElementShouldBe($element, $value)  | 
            ||
| 270 | |||
| 271 | /**  | 
            ||
| 272 | * @Then this taxon should have slug :value in :language  | 
            ||
| 273 | */  | 
            ||
| 274 | public function thisTaxonElementShouldHaveSlugIn($value, $language = null)  | 
            ||
| 286 | |||
| 287 | /**  | 
            ||
| 288 | * @Then the code field should be disabled  | 
            ||
| 289 | */  | 
            ||
| 290 | public function theCodeFieldShouldBeDisabled()  | 
            ||
| 297 | |||
| 298 | /**  | 
            ||
| 299 |      * @Then /^the slug of the ("[^"]+" taxon) should(?:| still) be "([^"]+)"$/ | 
            ||
| 300 | */  | 
            ||
| 301 | public function productSlugShouldBe(TaxonInterface $taxon, $slug)  | 
            ||
| 310 | |||
| 311 | /**  | 
            ||
| 312 | * @Then /^this taxon should (belongs to "[^"]+")$/  | 
            ||
| 313 | */  | 
            ||
| 314 | public function thisTaxonShouldBelongsTo(TaxonInterface $taxon)  | 
            ||
| 321 | |||
| 322 | /**  | 
            ||
| 323 | * @Given it should not belong to any other taxon  | 
            ||
| 324 | */  | 
            ||
| 325 | public function itShouldNotBelongToAnyOtherTaxon()  | 
            ||
| 334 | |||
| 335 | /**  | 
            ||
| 336 | * @Then I should be notified that taxon with this code already exists  | 
            ||
| 337 | */  | 
            ||
| 338 | public function iShouldBeNotifiedThatTaxonWithThisCodeAlreadyExists()  | 
            ||
| 345 | |||
| 346 | /**  | 
            ||
| 347 | * @Then I should be notified that taxon slug must be unique  | 
            ||
| 348 | */  | 
            ||
| 349 | public function iShouldBeNotifiedThatTaxonSlugMustBeUnique()  | 
            ||
| 356 | |||
| 357 | /**  | 
            ||
| 358 | * @Then I should be notified that :element is required  | 
            ||
| 359 | */  | 
            ||
| 360 | public function iShouldBeNotifiedThatIsRequired($element)  | 
            ||
| 367 | |||
| 368 | /**  | 
            ||
| 369 | * @Then /^there should still be only one taxon with code "([^"]+)"$/  | 
            ||
| 370 | */  | 
            ||
| 371 | public function thereShouldStillBeOnlyOneTaxonWithCode($code)  | 
            ||
| 378 | |||
| 379 | /**  | 
            ||
| 380 | * @Then /^Taxon named "([^"]+)" should not be added$/  | 
            ||
| 381 | * @Then the taxon named :name should no longer exist in the registry  | 
            ||
| 382 | */  | 
            ||
| 383 | public function taxonNamedShouldNotBeAdded($name)  | 
            ||
| 391 | |||
| 392 | /**  | 
            ||
| 393 | * @Then /^I should see (\d+) taxons on the list$/  | 
            ||
| 394 | */  | 
            ||
| 395 | public function iShouldSeeTaxonsInTheList($number)  | 
            ||
| 405 | |||
| 406 | /**  | 
            ||
| 407 | * @Then I should see the taxon named :name in the list  | 
            ||
| 408 | */  | 
            ||
| 409 | public function iShouldSeeTheTaxonNamedInTheList($name)  | 
            ||
| 417 | |||
| 418 | /**  | 
            ||
| 419 | * @When I attach the :path image with a code :code  | 
            ||
| 420 | */  | 
            ||
| 421 | public function iAttachImageWithACode($path, $code)  | 
            ||
| 428 | |||
| 429 | /**  | 
            ||
| 430 | * @When I attach the :path image without a code  | 
            ||
| 431 | */  | 
            ||
| 432 | public function iAttachImageWithoutACode($path)  | 
            ||
| 436 | |||
| 437 | /**  | 
            ||
| 438 | * @Then /^this taxon should have(?:| also) an image with a code "([^"]*)"$/  | 
            ||
| 439 | */  | 
            ||
| 440 | public function thisTaxonShouldHaveAnImageWithCode($code)  | 
            ||
| 447 | |||
| 448 | /**  | 
            ||
| 449 | * @Then /^this taxon should not have(?:| also) an image with a code "([^"]*)"$/  | 
            ||
| 450 | */  | 
            ||
| 451 | public function thisTaxonShouldNotHaveAnImageWithCode($code)  | 
            ||
| 458 | |||
| 459 | /**  | 
            ||
| 460 | * @When /^I remove(?:| also) an image with a code "([^"]*)"$/  | 
            ||
| 461 | */  | 
            ||
| 462 | public function iRemoveAnImageWithACode($code)  | 
            ||
| 466 | |||
| 467 | /**  | 
            ||
| 468 | * @When I remove the first image  | 
            ||
| 469 | */  | 
            ||
| 470 | public function iRemoveTheFirstImage()  | 
            ||
| 474 | |||
| 475 | /**  | 
            ||
| 476 | * @Then /^(this taxon) should not have any images$/  | 
            ||
| 477 | */  | 
            ||
| 478 | public function thisTaxonShouldNotHaveImages(TaxonInterface $taxon)  | 
            ||
| 488 | |||
| 489 | /**  | 
            ||
| 490 | * @When I change the image with the :code code to :path  | 
            ||
| 491 | */  | 
            ||
| 492 | public function iChangeItsImageToPathForTheCode($path, $code)  | 
            ||
| 496 | |||
| 497 | /**  | 
            ||
| 498 | * @Then I should be notified that the image with this code already exists  | 
            ||
| 499 | */  | 
            ||
| 500 | public function iShouldBeNotifiedThatTheImageWithThisCodeAlreadyExists()  | 
            ||
| 504 | |||
| 505 | /**  | 
            ||
| 506 | * @Then I should be notified that an image code is required  | 
            ||
| 507 | */  | 
            ||
| 508 | public function iShouldBeNotifiedThatAnImageCodeIsRequired()  | 
            ||
| 515 | |||
| 516 | /**  | 
            ||
| 517 | * @Then there should still be only one image in the :taxon taxon  | 
            ||
| 518 | */  | 
            ||
| 519 | public function thereShouldStillBeOnlyOneImageInThisTaxon(TaxonInterface $taxon)  | 
            ||
| 529 | |||
| 530 | /**  | 
            ||
| 531 | * @Then the image code field should be disabled  | 
            ||
| 532 | */  | 
            ||
| 533 | public function theImageCodeFieldShouldBeDisabled()  | 
            ||
| 540 | |||
| 541 | /**  | 
            ||
| 542 | * @Then I should be notified that the :imageNumber image should have an unique code  | 
            ||
| 543 | */  | 
            ||
| 544 | public function iShouldBeNotifiedThatTheFirstImageShouldHaveAnUniqueCode($imageNumber)  | 
            ||
| 553 | |||
| 554 | /**  | 
            ||
| 555 | * @Then the first taxon on the list should be :taxon  | 
            ||
| 556 | */  | 
            ||
| 557 | public function theFirstTaxonOnTheListShouldBe(TaxonInterface $taxon)  | 
            ||
| 572 | |||
| 573 | /**  | 
            ||
| 574 | * @Then they should have order like :firstTaxonName, :secondTaxonName, :thirdTaxonName and :fourthTaxonName  | 
            ||
| 575 | */  | 
            ||
| 576 | public function theyShouldHaveOrderLikeAnd(...$taxonsNames)  | 
            ||
| 584 | }  | 
            ||
| 585 |