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 |
||
| 26 | final class ManagingTaxonsContext implements Context |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var SharedStorageInterface |
||
| 30 | */ |
||
| 31 | private $sharedStorage; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var CreatePageInterface |
||
| 35 | */ |
||
| 36 | private $createPage; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var CreateForParentPageInterface |
||
| 40 | */ |
||
| 41 | private $createForParentPage; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var UpdatePageInterface |
||
| 45 | */ |
||
| 46 | private $updatePage; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var CurrentPageResolverInterface |
||
| 50 | */ |
||
| 51 | private $currentPageResolver; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param SharedStorageInterface $sharedStorage |
||
| 55 | * @param CreatePageInterface $createPage |
||
| 56 | * @param CreateForParentPageInterface $createForParentPage |
||
| 57 | * @param UpdatePageInterface $updatePage |
||
| 58 | * @param CurrentPageResolverInterface $currentPageResolver |
||
| 59 | */ |
||
| 60 | public function __construct( |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @Given I want to create a new taxon |
||
| 76 | * @Given I want to see all taxons in store |
||
| 77 | */ |
||
| 78 | public function iWantToCreateANewTaxon() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @Given I want to create a new taxon for :taxon |
||
| 85 | */ |
||
| 86 | public function iWantToCreateANewTaxonForParent(TaxonInterface $taxon) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @Given /^I want to modify the ("[^"]+" taxon)$/ |
||
| 93 | */ |
||
| 94 | public function iWantToModifyATaxon(TaxonInterface $taxon) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @When I specify its code as :code |
||
| 103 | */ |
||
| 104 | public function iSpecifyItsCodeAs($code) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @When I name it :name in :language |
||
| 111 | */ |
||
| 112 | public function iNameItIn($name, $language) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @When I rename it to :name in :language |
||
| 119 | */ |
||
| 120 | public function iRenameItIn($name, $language) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @When I change its description to :description in :language |
||
| 127 | */ |
||
| 128 | public function iChangeItsDescriptionToIn($description, $language) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @When I specify its permalink as :permalink in :language |
||
| 135 | */ |
||
| 136 | public function iSpecifyItsPermalinkAs($permalink, $language) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @When I change its permalink to :permalink in :language |
||
| 143 | */ |
||
| 144 | public function iChangeItsPermalinkToIn($permalink, $language) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @When I describe it as :description in :language |
||
| 151 | */ |
||
| 152 | public function iDescribeItAs($description, $language) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @When /^I move up ("[^"]+" taxon)$/ |
||
| 159 | */ |
||
| 160 | public function iWantToMoveUpTaxon(TaxonInterface $taxon) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @When /^I move ("[^"]+" taxon) before ("[^"]+" taxon)$/ |
||
| 167 | */ |
||
| 168 | public function iMoveTaxonBeforeTaxon(TaxonInterface $taxonToMove, TaxonInterface $targetTaxon) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @Given /^I choose ("[^"]+" as a parent taxon)$/ |
||
| 175 | */ |
||
| 176 | public function iChooseAsAParentTaxon(TaxonInterface $taxon) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @Given /^I change its (parent taxon to "[^"]+")$/ |
||
| 183 | */ |
||
| 184 | public function iChangeItsParentTaxonTo(TaxonInterface $taxon) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @When I do not specify its code |
||
| 191 | */ |
||
| 192 | public function iDoNotSpecifyItsCode() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @When I do not specify its name |
||
| 199 | */ |
||
| 200 | public function iDoNotSpecifyItsName() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @When I delete taxon named :name |
||
| 207 | */ |
||
| 208 | public function iDeleteTaxonNamed($name) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @When I add it |
||
| 216 | * @When I try to add it |
||
| 217 | */ |
||
| 218 | public function iAddIt() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @When I save my changes |
||
| 225 | * @When I try to save my changes |
||
| 226 | */ |
||
| 227 | public function iSaveMyChanges() |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @Then /^the ("[^"]+" taxon) should appear in the registry$/ |
||
| 234 | */ |
||
| 235 | public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @Then this taxon :element should be :value |
||
| 246 | */ |
||
| 247 | public function thisTaxonElementShouldBe($element, $value) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @Then the code field should be disabled |
||
| 257 | */ |
||
| 258 | public function theCodeFieldShouldBeDisabled() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @Then /^this taxon should (belongs to "[^"]+")$/ |
||
| 268 | */ |
||
| 269 | public function thisTaxonShouldBelongsTo(TaxonInterface $taxon) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @Given it should not belong to any other taxon |
||
| 279 | */ |
||
| 280 | public function itShouldNotBelongToAnyOtherTaxon() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @Then I should be notified that taxon with this code already exists |
||
| 292 | */ |
||
| 293 | public function iShouldBeNotifiedThatTaxonWithThisCodeAlreadyExists() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @Then I should be notified that :element is required |
||
| 303 | */ |
||
| 304 | public function iShouldBeNotifiedThatIsRequired($element) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @Then /^there should still be only one taxon with code "([^"]+)"$/ |
||
| 314 | */ |
||
| 315 | public function thereShouldStillBeOnlyOneTaxonWithCode($code) |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @Then /^Taxon named "([^"]+)" should not be added$/ |
||
| 325 | * @Then the taxon named :name should no longer exist in the registry |
||
| 326 | */ |
||
| 327 | public function taxonNamedShouldNotBeAdded($name) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @Then /^I should see (\d+) taxons on the list$/ |
||
| 338 | */ |
||
| 339 | public function iShouldSeeTaxonsInTheList($number) |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @Then I should see the taxon named :name in the list |
||
| 352 | */ |
||
| 353 | public function iShouldSeeTheTaxonNamedInTheList($name) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @When I attach the :path image with a code :code |
||
| 364 | */ |
||
| 365 | public function iAttachImageWithACode($path, $code) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @When I attach the :path image without a code |
||
| 375 | */ |
||
| 376 | public function iAttachImageWithoutACode($path) |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @Then /^this taxon should have(?:| also) an image with a code "([^"]*)"$/ |
||
| 383 | */ |
||
| 384 | public function thisTaxonShouldHaveAnImageWithCode($code) |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @Then /^this taxon should not have(?:| also) an image with a code "([^"]*)"$/ |
||
| 394 | */ |
||
| 395 | public function thisTaxonShouldNotHaveAnImageWithCode($code) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * @When /^I remove(?:| also) an image with a code "([^"]*)"$/ |
||
| 405 | */ |
||
| 406 | public function iRemoveAnImageWithACode($code) |
||
| 410 | |||
| 411 | /** |
||
| 412 | * @When I remove the first image |
||
| 413 | */ |
||
| 414 | public function iRemoveTheFirstImage() |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @Then /^(this taxon) should not have any images$/ |
||
| 421 | */ |
||
| 422 | public function thisTaxonShouldNotHaveImages(TaxonInterface $taxon) |
||
| 432 | |||
| 433 | /** |
||
| 434 | * @When I change the image with the :code code to :path |
||
| 435 | */ |
||
| 436 | public function iChangeItsImageToPathForTheCode($path, $code) |
||
| 440 | |||
| 441 | /** |
||
| 442 | * @Then I should be notified that the image with this code already exists |
||
| 443 | */ |
||
| 444 | public function iShouldBeNotifiedThatTheImageWithThisCodeAlreadyExists() |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @Then I should be notified that an image code is required |
||
| 451 | */ |
||
| 452 | public function iShouldBeNotifiedThatAnImageCodeIsRequired() |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @Then there should still be only one image in the :taxon taxon |
||
| 462 | */ |
||
| 463 | public function thereShouldStillBeOnlyOneImageInThisTaxon(TaxonInterface $taxon) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @Then the image code field should be disabled |
||
| 476 | */ |
||
| 477 | public function theImageCodeFieldShouldBeDisabled() |
||
| 484 | |||
| 485 | /** |
||
| 486 | * @Then I should be notified that the :imageNumber image should have an unique code |
||
| 487 | */ |
||
| 488 | public function iShouldBeNotifiedThatTheFirstImageShouldHaveAnUniqueCode($imageNumber) |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @Then the first taxon on the list should be :taxon |
||
| 500 | */ |
||
| 501 | public function theFirstTaxonOnTheListShouldBe(TaxonInterface $taxon) |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @Then they should have order like :firstTaxonName, :secondTaxonName, :thirdTaxonName and :fourthTaxonName |
||
| 516 | */ |
||
| 517 | public function theyShouldHaveOrderLikeAnd(...$taxonsNames) |
||
| 525 | } |
||
| 526 |