Complex classes like ManagingChannelsContext 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 ManagingChannelsContext, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 28 | final class ManagingChannelsContext implements Context  | 
            ||
| 29 | { | 
            ||
| 30 | /** @var IndexPageInterface */  | 
            ||
| 31 | private $indexPage;  | 
            ||
| 32 | |||
| 33 | /** @var CreatePageInterface */  | 
            ||
| 34 | private $createPage;  | 
            ||
| 35 | |||
| 36 | /** @var UpdatePageInterface */  | 
            ||
| 37 | private $updatePage;  | 
            ||
| 38 | |||
| 39 | /** @var CurrentPageResolverInterface */  | 
            ||
| 40 | private $currentPageResolver;  | 
            ||
| 41 | |||
| 42 | /** @var NotificationCheckerInterface */  | 
            ||
| 43 | private $notificationChecker;  | 
            ||
| 44 | |||
| 45 | public function __construct(  | 
            ||
| 46 | IndexPageInterface $indexPage,  | 
            ||
| 47 | CreatePageInterface $createPage,  | 
            ||
| 48 | UpdatePageInterface $updatePage,  | 
            ||
| 49 | CurrentPageResolverInterface $currentPageResolver,  | 
            ||
| 50 | NotificationCheckerInterface $notificationChecker  | 
            ||
| 51 |     ) { | 
            ||
| 52 | $this->indexPage = $indexPage;  | 
            ||
| 53 | $this->createPage = $createPage;  | 
            ||
| 54 | $this->updatePage = $updatePage;  | 
            ||
| 55 | $this->currentPageResolver = $currentPageResolver;  | 
            ||
| 56 | $this->notificationChecker = $notificationChecker;  | 
            ||
| 57 | }  | 
            ||
| 58 | |||
| 59 | /**  | 
            ||
| 60 | * @Given I want to create a new channel  | 
            ||
| 61 | */  | 
            ||
| 62 | public function iWantToCreateANewChannel()  | 
            ||
| 63 |     { | 
            ||
| 64 | $this->createPage->open();  | 
            ||
| 65 | }  | 
            ||
| 66 | |||
| 67 | /**  | 
            ||
| 68 | * @When I specify its code as :code  | 
            ||
| 69 | * @When I do not specify its code  | 
            ||
| 70 | */  | 
            ||
| 71 | public function iSpecifyItsCodeAs($code = null)  | 
            ||
| 72 |     { | 
            ||
| 73 | $this->createPage->specifyCode($code ?? '');  | 
            ||
| 74 | }  | 
            ||
| 75 | |||
| 76 | /**  | 
            ||
| 77 | * @When I name it :name  | 
            ||
| 78 | * @When I rename it to :name  | 
            ||
| 79 | * @When I do not name it  | 
            ||
| 80 | * @When I remove its name  | 
            ||
| 81 | */  | 
            ||
| 82 | public function iNameIt($name = null)  | 
            ||
| 83 |     { | 
            ||
| 84 | $this->createPage->nameIt($name ?? '');  | 
            ||
| 85 | }  | 
            ||
| 86 | |||
| 87 | /**  | 
            ||
| 88 | * @When I choose :currency as the base currency  | 
            ||
| 89 | * @When I do not choose base currency  | 
            ||
| 90 | */  | 
            ||
| 91 | public function iChooseAsABaseCurrency(?CurrencyInterface $currency = null)  | 
            ||
| 92 |     { | 
            ||
| 93 | $this->createPage->chooseBaseCurrency($currency ? $currency->getName() : null);  | 
            ||
| 94 | }  | 
            ||
| 95 | |||
| 96 | /**  | 
            ||
| 97 | * @When I choose :locale as a default locale  | 
            ||
| 98 | * @When I do not choose default locale  | 
            ||
| 99 | */  | 
            ||
| 100 | public function iChooseAsADefaultLocale($locale = null)  | 
            ||
| 101 |     { | 
            ||
| 102 | $this->createPage->chooseDefaultLocale($locale);  | 
            ||
| 103 | }  | 
            ||
| 104 | |||
| 105 | /**  | 
            ||
| 106 | * @When I specify menu taxon as :menuTaxon  | 
            ||
| 107 | */  | 
            ||
| 108 | public function iSpecifyMenuTaxonAs(string $menuTaxon): void  | 
            ||
| 109 |     { | 
            ||
| 110 | $this->createPage->specifyMenuTaxon($menuTaxon);  | 
            ||
| 111 | }  | 
            ||
| 112 | |||
| 113 | /**  | 
            ||
| 114 | * @When I change its menu taxon to :menuTaxon  | 
            ||
| 115 | */  | 
            ||
| 116 | public function iChangeItsMenuTaxonTo(string $menuTaxon): void  | 
            ||
| 117 |     { | 
            ||
| 118 | $this->updatePage->changeMenuTaxon($menuTaxon);  | 
            ||
| 119 | }  | 
            ||
| 120 | |||
| 121 | /**  | 
            ||
| 122 | * @When I allow to skip shipping step if only one shipping method is available  | 
            ||
| 123 | */  | 
            ||
| 124 | public function iAllowToSkipShippingStepIfOnlyOneShippingMethodIsAvailable()  | 
            ||
| 128 | |||
| 129 | /**  | 
            ||
| 130 | * @When I allow to skip payment step if only one payment method is available  | 
            ||
| 131 | */  | 
            ||
| 132 | public function iAllowToSkipPaymentStepIfOnlyOnePaymentMethodIsAvailable()  | 
            ||
| 136 | |||
| 137 | /**  | 
            ||
| 138 | * @When I add it  | 
            ||
| 139 | * @When I try to add it  | 
            ||
| 140 | */  | 
            ||
| 141 | public function iAddIt()  | 
            ||
| 145 | |||
| 146 | /**  | 
            ||
| 147 | * @Then I should see the channel :channelName in the list  | 
            ||
| 148 | * @Then the channel :channelName should appear in the registry  | 
            ||
| 149 | * @Then the channel :channelName should be in the registry  | 
            ||
| 150 | */  | 
            ||
| 151 | public function theChannelShouldAppearInTheRegistry(string $channelName): void  | 
            ||
| 157 | |||
| 158 | /**  | 
            ||
| 159 | * @Then /^(this channel) should still be in the registry$/  | 
            ||
| 160 | */  | 
            ||
| 161 | public function thisChannelShouldAppearInTheRegistry(ChannelInterface $channel)  | 
            ||
| 165 | |||
| 166 | /**  | 
            ||
| 167 | * @When I describe it as :description  | 
            ||
| 168 | */  | 
            ||
| 169 | public function iDescribeItAs($description)  | 
            ||
| 173 | |||
| 174 | /**  | 
            ||
| 175 | * @When I set its hostname as :hostname  | 
            ||
| 176 | */  | 
            ||
| 177 | public function iSetItsHostnameAs($hostname)  | 
            ||
| 181 | |||
| 182 | /**  | 
            ||
| 183 | * @When I set its contact email as :contactEmail  | 
            ||
| 184 | */  | 
            ||
| 185 | public function iSetItsContactEmailAs($contactEmail)  | 
            ||
| 189 | |||
| 190 | /**  | 
            ||
| 191 | * @When I define its color as :color  | 
            ||
| 192 | */  | 
            ||
| 193 | public function iDefineItsColorAs($color)  | 
            ||
| 197 | |||
| 198 | /**  | 
            ||
| 199 | * @When I enable it  | 
            ||
| 200 | */  | 
            ||
| 201 | public function iEnableIt()  | 
            ||
| 205 | |||
| 206 | /**  | 
            ||
| 207 | * @When I disable it  | 
            ||
| 208 | */  | 
            ||
| 209 | public function iDisableIt()  | 
            ||
| 216 | |||
| 217 | /**  | 
            ||
| 218 | * @Then I should be notified that at least one channel has to be defined  | 
            ||
| 219 | */  | 
            ||
| 220 | public function iShouldBeNotifiedThatAtLeastOneChannelHasToBeDefinedIsRequired()  | 
            ||
| 227 | |||
| 228 | /**  | 
            ||
| 229 | * @Then channel with :element :value should not be added  | 
            ||
| 230 | */  | 
            ||
| 231 | public function channelWithShouldNotBeAdded($element, $value)  | 
            ||
| 237 | |||
| 238 | /**  | 
            ||
| 239 | * @Then /^I should be notified that ([^"]+) is required$/  | 
            ||
| 240 | */  | 
            ||
| 241 | public function iShouldBeNotifiedThatIsRequired($element)  | 
            ||
| 251 | |||
| 252 | /**  | 
            ||
| 253 | * @Given I am modifying a channel :channel  | 
            ||
| 254 | * @When I want to modify a channel :channel  | 
            ||
| 255 | * @When /^I want to modify (this channel)$/  | 
            ||
| 256 | */  | 
            ||
| 257 | public function iWantToModifyChannel(ChannelInterface $channel): void  | 
            ||
| 258 |     { | 
            ||
| 259 | $this->updatePage->open(['id' => $channel->getId()]);  | 
            ||
| 261 | |||
| 262 | /**  | 
            ||
| 263 | * @Then /^(this channel) name should be "([^"]+)"$/  | 
            ||
| 264 | * @Then /^(this channel) should still be named "([^"]+)"$/  | 
            ||
| 265 | */  | 
            ||
| 266 | public function thisChannelNameShouldBe(ChannelInterface $channel, $channelName)  | 
            ||
| 275 | |||
| 276 | /**  | 
            ||
| 277 | * @When I save my changes  | 
            ||
| 278 | * @When I try to save my changes  | 
            ||
| 279 | */  | 
            ||
| 280 | public function iSaveMyChanges()  | 
            ||
| 284 | |||
| 285 | /**  | 
            ||
| 286 | * @When /^I define its type as (mobile|website|pos)$/  | 
            ||
| 287 | */  | 
            ||
| 288 | public function iDefineItsTypeAs(string $type): void  | 
            ||
| 292 | |||
| 293 | /**  | 
            ||
| 294 | * @Then I should be notified that channel with this code already exists  | 
            ||
| 295 | */  | 
            ||
| 296 | public function iShouldBeNotifiedThatChannelWithThisCodeAlreadyExists()  | 
            ||
| 300 | |||
| 301 | /**  | 
            ||
| 302 | * @Then there should still be only one channel with :element :value  | 
            ||
| 303 | */  | 
            ||
| 304 | public function thereShouldStillBeOnlyOneChannelWithCode($element, $value)  | 
            ||
| 310 | |||
| 311 | /**  | 
            ||
| 312 | * @When I browse channels  | 
            ||
| 313 | * @When I want to browse channels  | 
            ||
| 314 | */  | 
            ||
| 315 | public function iWantToBrowseChannels(): void  | 
            ||
| 319 | |||
| 320 | /**  | 
            ||
| 321 | * @When I check (also) the :channelName channel  | 
            ||
| 322 | */  | 
            ||
| 323 | public function iCheckTheChannel(string $channelName): void  | 
            ||
| 327 | |||
| 328 | /**  | 
            ||
| 329 | * @When I delete them  | 
            ||
| 330 | */  | 
            ||
| 331 | public function iDeleteThem(): void  | 
            ||
| 335 | |||
| 336 | /**  | 
            ||
| 337 | * @Then I should see a single channel in the list  | 
            ||
| 338 | * @Then I should see :numberOfChannels channels in the list  | 
            ||
| 339 | */  | 
            ||
| 340 | public function iShouldSeeChannelsInTheList(int $numberOfChannels = 1): void  | 
            ||
| 344 | |||
| 345 | /**  | 
            ||
| 346 | * @Then the code field should be disabled  | 
            ||
| 347 | */  | 
            ||
| 348 | public function theCodeFieldShouldBeDisabled()  | 
            ||
| 352 | |||
| 353 | /**  | 
            ||
| 354 | * @Then /^(this channel) should be disabled$/  | 
            ||
| 355 | */  | 
            ||
| 356 | public function thisChannelShouldBeDisabled(ChannelInterface $channel)  | 
            ||
| 360 | |||
| 361 | /**  | 
            ||
| 362 | * @Then /^(this channel) should be enabled$/  | 
            ||
| 363 | * @Then channel with name :channel should still be enabled  | 
            ||
| 364 | */  | 
            ||
| 365 | public function thisChannelShouldBeEnabled(ChannelInterface $channel)  | 
            ||
| 369 | |||
| 370 | /**  | 
            ||
| 371 | * @When I delete channel :channel  | 
            ||
| 372 | */  | 
            ||
| 373 | public function iDeleteChannel(ChannelInterface $channel)  | 
            ||
| 378 | |||
| 379 | /**  | 
            ||
| 380 | * @Then the :channelName channel should no longer exist in the registry  | 
            ||
| 381 | */  | 
            ||
| 382 | public function thisChannelShouldNoLongerExistInTheRegistry($channelName)  | 
            ||
| 386 | |||
| 387 | /**  | 
            ||
| 388 | * @Then I should be notified that it cannot be deleted  | 
            ||
| 389 | */  | 
            ||
| 390 | public function iShouldBeNotifiedThatItCannotBeDeleted()  | 
            ||
| 397 | |||
| 398 | /**  | 
            ||
| 399 | * @When I make it available (only) in :locale  | 
            ||
| 400 | */  | 
            ||
| 401 | public function iMakeItAvailableIn(string $localeName): void  | 
            ||
| 408 | |||
| 409 | /**  | 
            ||
| 410 | * @Then the channel :channel should be available in :locale  | 
            ||
| 411 | */  | 
            ||
| 412 | public function theChannelShouldBeAvailableIn(ChannelInterface $channel, $locale)  | 
            ||
| 418 | |||
| 419 | /**  | 
            ||
| 420 | * @When I allow for paying in :currencyCode  | 
            ||
| 421 | */  | 
            ||
| 422 | public function iAllowToPayingForThisChannel($currencyCode)  | 
            ||
| 429 | |||
| 430 | /**  | 
            ||
| 431 | * @Then paying in :currencyCode should be possible for the :channel channel  | 
            ||
| 432 | */  | 
            ||
| 433 | public function payingInEuroShouldBePossibleForTheChannel($currencyCode, ChannelInterface $channel)  | 
            ||
| 439 | |||
| 440 | /**  | 
            ||
| 441 | * @When I select the :taxZone as default tax zone  | 
            ||
| 442 | */  | 
            ||
| 443 | public function iSelectDefaultTaxZone($taxZone)  | 
            ||
| 450 | |||
| 451 | /**  | 
            ||
| 452 | * @Given I remove its default tax zone  | 
            ||
| 453 | */  | 
            ||
| 454 | public function iRemoveItsDefaultTaxZone()  | 
            ||
| 458 | |||
| 459 | /**  | 
            ||
| 460 | * @When I select the :taxCalculationStrategy as tax calculation strategy  | 
            ||
| 461 | */  | 
            ||
| 462 | public function iSelectTaxCalculationStrategy($taxCalculationStrategy)  | 
            ||
| 469 | |||
| 470 | /**  | 
            ||
| 471 | * @Then the default tax zone for the :channel channel should be :taxZone  | 
            ||
| 472 | */  | 
            ||
| 473 | public function theDefaultTaxZoneForTheChannelShouldBe(ChannelInterface $channel, $taxZone)  | 
            ||
| 479 | |||
| 480 | /**  | 
            ||
| 481 | * @When /^I change its type to (mobile|website|pos)$/  | 
            ||
| 482 | */  | 
            ||
| 483 | public function iChangeItsTypeTo(string $type): void  | 
            ||
| 487 | |||
| 488 | /**  | 
            ||
| 489 | * @Given channel :channel should not have default tax zone  | 
            ||
| 490 | */  | 
            ||
| 491 | public function channelShouldNotHaveDefaultTaxZone(ChannelInterface $channel)  | 
            ||
| 497 | |||
| 498 | /**  | 
            ||
| 499 | * @Then the tax calculation strategy for the :channel channel should be :taxCalculationStrategy  | 
            ||
| 500 | */  | 
            ||
| 501 | public function theTaxCalculationStrategyForTheChannelShouldBe(ChannelInterface $channel, $taxCalculationStrategy)  | 
            ||
| 507 | |||
| 508 | /**  | 
            ||
| 509 | * @Then the base currency field should be disabled  | 
            ||
| 510 | */  | 
            ||
| 511 | public function theBaseCurrencyFieldShouldBeDisabled()  | 
            ||
| 515 | |||
| 516 | /**  | 
            ||
| 517 | * @Then I should be notified that the default locale has to be enabled  | 
            ||
| 518 | */  | 
            ||
| 519 | public function iShouldBeNotifiedThatTheDefaultLocaleHasToBeEnabled(): void  | 
            ||
| 526 | |||
| 527 | /**  | 
            ||
| 528 | * @Then /^this channel type should be (mobile|website|pos)$/  | 
            ||
| 529 | */  | 
            ||
| 530 | public function thisChannelTypeShouldBe(string $type): void  | 
            ||
| 534 | |||
| 535 | /**  | 
            ||
| 536 | * @Given /^(this channel) menu taxon should be "([^"]+)"$/  | 
            ||
| 537 | * @Given the channel :channel should have :menuTaxon as a menu taxon  | 
            ||
| 538 | */  | 
            ||
| 539 | public function thisChannelMenuTaxonShouldBe(ChannelInterface $channel, string $menuTaxon): void  | 
            ||
| 547 | |||
| 548 | /**  | 
            ||
| 549 | * @param bool $state  | 
            ||
| 550 | */  | 
            ||
| 551 | private function assertChannelState(ChannelInterface $channel, $state)  | 
            ||
| 560 | }  | 
            ||
| 561 |