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 | /** @var SharedStorageInterface */ |
||
| 30 | private $sharedStorage; |
||
| 31 | |||
| 32 | /** @var CreatePageInterface */ |
||
| 33 | private $createPage; |
||
| 34 | |||
| 35 | /** @var CreateForParentPageInterface */ |
||
| 36 | private $createForParentPage; |
||
| 37 | |||
| 38 | /** @var UpdatePageInterface */ |
||
| 39 | private $updatePage; |
||
| 40 | |||
| 41 | /** @var CurrentPageResolverInterface */ |
||
| 42 | private $currentPageResolver; |
||
| 43 | |||
| 44 | /** @var NotificationCheckerInterface */ |
||
| 45 | private $notificationChecker; |
||
| 46 | |||
| 47 | public function __construct( |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @Given I want to create a new taxon |
||
| 65 | * @Given I want to see all taxons in store |
||
| 66 | */ |
||
| 67 | public function iWantToCreateANewTaxon() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @Given I want to create a new taxon for :taxon |
||
| 74 | */ |
||
| 75 | public function iWantToCreateANewTaxonForParent(TaxonInterface $taxon) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @Given /^I want to modify the ("[^"]+" taxon)$/ |
||
| 82 | */ |
||
| 83 | public function iWantToModifyATaxon(TaxonInterface $taxon) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @When I specify its code as :code |
||
| 92 | * @When I do not specify its code |
||
| 93 | */ |
||
| 94 | public function iSpecifyItsCodeAs(?string $code = null) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @When I name it :name in :language |
||
| 101 | * @When I rename it to :name in :language |
||
| 102 | * @When I do not specify its name |
||
| 103 | */ |
||
| 104 | public function iNameItIn(?string $name = null, $language = 'en_US') |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @When I set its slug to :slug |
||
| 113 | * @When I do not specify its slug |
||
| 114 | * @When I set its slug to :slug in :language |
||
| 115 | */ |
||
| 116 | public function iSetItsSlugToIn(?string $slug = null, $language = 'en_US') |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @Then the slug field should not be editable |
||
| 125 | * @Then the slug field should (also )not be editable in :language |
||
| 126 | */ |
||
| 127 | public function theSlugFieldShouldNotBeEditable($language = 'en_US') |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @When I enable slug modification |
||
| 134 | * @When I enable slug modification in :language |
||
| 135 | */ |
||
| 136 | public function iEnableSlugModification($language = 'en_US') |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @When I change its description to :description in :language |
||
| 144 | */ |
||
| 145 | public function iChangeItsDescriptionToIn($description, $language) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @When I describe it as :description in :language |
||
| 152 | */ |
||
| 153 | public function iDescribeItAs($description, $language) |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @Given /^I change its (parent taxon to "[^"]+")$/ |
||
| 160 | */ |
||
| 161 | public function iChangeItsParentTaxonTo(TaxonInterface $taxon) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @When I add it |
||
| 168 | * @When I try to add it |
||
| 169 | */ |
||
| 170 | public function iAddIt() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @When I save my changes |
||
| 177 | * @When I try to save my changes |
||
| 178 | */ |
||
| 179 | public function iSaveMyChanges() |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @Then /^the ("[^"]+" taxon) should appear in the registry$/ |
||
| 186 | */ |
||
| 187 | public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @Then this taxon :element should be :value |
||
| 195 | */ |
||
| 196 | public function thisTaxonElementShouldBe($element, $value) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @Then this taxon should have slug :value in :language |
||
| 203 | */ |
||
| 204 | public function thisTaxonElementShouldHaveSlugIn($value, $language = null) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @Then the code field should be disabled |
||
| 215 | */ |
||
| 216 | public function theCodeFieldShouldBeDisabled() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @Then /^the slug of the ("[^"]+" taxon) should(?:| still) be "([^"]+)"$/ |
||
| 223 | */ |
||
| 224 | public function productSlugShouldBe(TaxonInterface $taxon, $slug) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @Then /^this taxon should (belongs to "[^"]+")$/ |
||
| 233 | */ |
||
| 234 | public function thisTaxonShouldBelongsTo(TaxonInterface $taxon) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @Given it should not belong to any other taxon |
||
| 241 | */ |
||
| 242 | public function itShouldNotBelongToAnyOtherTaxon() |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @Then I should be notified that taxon with this code already exists |
||
| 249 | */ |
||
| 250 | public function iShouldBeNotifiedThatTaxonWithThisCodeAlreadyExists() |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @Then I should be notified that taxon slug must be unique |
||
| 259 | */ |
||
| 260 | public function iShouldBeNotifiedThatTaxonSlugMustBeUnique() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @Then I should be notified that :element is required |
||
| 269 | */ |
||
| 270 | public function iShouldBeNotifiedThatIsRequired($element) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @Then /^there should(?:| still) be only one taxon with code "([^"]+)"$/ |
||
| 279 | */ |
||
| 280 | public function thereShouldStillBeOnlyOneTaxonWithCode($code) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @Then /^taxon named "([^"]+)" should not be added$/ |
||
| 287 | * @Then the taxon named :name should no longer exist in the registry |
||
| 288 | */ |
||
| 289 | public function taxonNamedShouldNotBeAdded($name) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @Then /^I should see (\d+) taxons on the list$/ |
||
| 296 | */ |
||
| 297 | public function iShouldSeeTaxonsInTheList($number) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @Then I should see the taxon named :name in the list |
||
| 304 | */ |
||
| 305 | public function iShouldSeeTheTaxonNamedInTheList($name) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @When I attach the :path image with :type type |
||
| 312 | * @When I attach the :path image |
||
| 313 | */ |
||
| 314 | public function iAttachImageWithType($path, $type = null) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @Then /^(?:it|this taxon) should(?:| also) have an image with "([^"]*)" type$/ |
||
| 323 | */ |
||
| 324 | public function thisTaxonShouldHaveAnImageWithType($type) |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @Then /^(?:this taxon|it) should not have(?:| also) any images with "([^"]*)" type$/ |
||
| 331 | */ |
||
| 332 | public function thisTaxonShouldNotHaveAnImageWithType($code) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @When /^I(?:| also) remove an image with "([^"]*)" type$/ |
||
| 339 | */ |
||
| 340 | public function iRemoveAnImageWithType($code) |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @When I remove the first image |
||
| 347 | */ |
||
| 348 | public function iRemoveTheFirstImage() |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @Then /^(this taxon) should not have any images$/ |
||
| 355 | */ |
||
| 356 | public function thisTaxonShouldNotHaveAnyImages(TaxonInterface $taxon) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @When I change the image with the :type type to :path |
||
| 365 | */ |
||
| 366 | public function iChangeItsImageToPathForTheType($path, $type) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @When I change the first image type to :type |
||
| 373 | */ |
||
| 374 | public function iChangeTheFirstImageTypeTo($type) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @Then /^(this taxon) should have only one image$/ |
||
| 381 | * @Then /^(this taxon) should(?:| still) have (\d+) images?$/ |
||
| 382 | */ |
||
| 383 | public function thereShouldStillBeOnlyOneImageInThisTaxon(TaxonInterface $taxon, $count = 1) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @Then I should be notified that I cannot delete a menu taxon of any channel |
||
| 392 | */ |
||
| 393 | public function iShouldBeNotifiedThatICannotDeleteAMenuTaxonOfAnyChannel(): void |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @return CreatePageInterface|CreateForParentPageInterface|UpdatePageInterface |
||
| 403 | */ |
||
| 404 | private function resolveCurrentPage() |
||
| 412 | } |
||
| 413 |