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(  | 
            ||
| 58 | |||
| 59 | /**  | 
            ||
| 60 | * @Given I want to create a new channel  | 
            ||
| 61 | */  | 
            ||
| 62 | public function iWantToCreateANewChannel()  | 
            ||
| 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)  | 
            ||
| 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)  | 
            ||
| 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)  | 
            ||
| 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)  | 
            ||
| 104 | |||
| 105 | /**  | 
            ||
| 106 | * @When I allow to skip shipping step if only one shipping method is available  | 
            ||
| 107 | */  | 
            ||
| 108 | public function iAllowToSkipShippingStepIfOnlyOneShippingMethodIsAvailable()  | 
            ||
| 112 | |||
| 113 | /**  | 
            ||
| 114 | * @When I allow to skip payment step if only one payment method is available  | 
            ||
| 115 | */  | 
            ||
| 116 | public function iAllowToSkipPaymentStepIfOnlyOnePaymentMethodIsAvailable()  | 
            ||
| 120 | |||
| 121 | /**  | 
            ||
| 122 | * @When I add it  | 
            ||
| 123 | * @When I try to add it  | 
            ||
| 124 | */  | 
            ||
| 125 | public function iAddIt()  | 
            ||
| 129 | |||
| 130 | /**  | 
            ||
| 131 | * @Then I should see the channel :channelName in the list  | 
            ||
| 132 | * @Then the channel :channelName should appear in the registry  | 
            ||
| 133 | * @Then the channel :channelName should be in the registry  | 
            ||
| 134 | */  | 
            ||
| 135 | public function theChannelShouldAppearInTheRegistry(string $channelName): void  | 
            ||
| 141 | |||
| 142 | /**  | 
            ||
| 143 | * @Then /^(this channel) should still be in the registry$/  | 
            ||
| 144 | */  | 
            ||
| 145 | public function thisChannelShouldAppearInTheRegistry(ChannelInterface $channel)  | 
            ||
| 149 | |||
| 150 | /**  | 
            ||
| 151 | * @When I describe it as :description  | 
            ||
| 152 | */  | 
            ||
| 153 | public function iDescribeItAs($description)  | 
            ||
| 157 | |||
| 158 | /**  | 
            ||
| 159 | * @When I set its hostname as :hostname  | 
            ||
| 160 | */  | 
            ||
| 161 | public function iSetItsHostnameAs($hostname)  | 
            ||
| 165 | |||
| 166 | /**  | 
            ||
| 167 | * @When I set its contact email as :contactEmail  | 
            ||
| 168 | */  | 
            ||
| 169 | public function iSetItsContactEmailAs($contactEmail)  | 
            ||
| 173 | |||
| 174 | /**  | 
            ||
| 175 | * @When I define its color as :color  | 
            ||
| 176 | */  | 
            ||
| 177 | public function iDefineItsColorAs($color)  | 
            ||
| 181 | |||
| 182 | /**  | 
            ||
| 183 | * @When I enable it  | 
            ||
| 184 | */  | 
            ||
| 185 | public function iEnableIt()  | 
            ||
| 189 | |||
| 190 | /**  | 
            ||
| 191 | * @When I disable it  | 
            ||
| 192 | */  | 
            ||
| 193 | public function iDisableIt()  | 
            ||
| 200 | |||
| 201 | /**  | 
            ||
| 202 | * @Then I should be notified that at least one channel has to be defined  | 
            ||
| 203 | */  | 
            ||
| 204 | public function iShouldBeNotifiedThatAtLeastOneChannelHasToBeDefinedIsRequired()  | 
            ||
| 211 | |||
| 212 | /**  | 
            ||
| 213 | * @Then channel with :element :value should not be added  | 
            ||
| 214 | */  | 
            ||
| 215 | public function channelWithShouldNotBeAdded($element, $value)  | 
            ||
| 221 | |||
| 222 | /**  | 
            ||
| 223 | * @Then /^I should be notified that ([^"]+) is required$/  | 
            ||
| 224 | */  | 
            ||
| 225 | public function iShouldBeNotifiedThatIsRequired($element)  | 
            ||
| 235 | |||
| 236 | /**  | 
            ||
| 237 | * @Given I am modifying a channel :channel  | 
            ||
| 238 | * @When I want to modify a channel :channel  | 
            ||
| 239 | * @When /^I want to modify (this channel)$/  | 
            ||
| 240 | */  | 
            ||
| 241 | public function iWantToModifyChannel(ChannelInterface $channel): void  | 
            ||
| 245 | |||
| 246 | /**  | 
            ||
| 247 | * @Then /^(this channel) name should be "([^"]+)"$/  | 
            ||
| 248 | * @Then /^(this channel) should still be named "([^"]+)"$/  | 
            ||
| 249 | */  | 
            ||
| 250 | public function thisChannelNameShouldBe(ChannelInterface $channel, $channelName)  | 
            ||
| 259 | |||
| 260 | /**  | 
            ||
| 261 | * @When I save my changes  | 
            ||
| 262 | * @When I try to save my changes  | 
            ||
| 263 | */  | 
            ||
| 264 | public function iSaveMyChanges()  | 
            ||
| 268 | |||
| 269 | /**  | 
            ||
| 270 | * @Then I should be notified that channel with this code already exists  | 
            ||
| 271 | */  | 
            ||
| 272 | public function iShouldBeNotifiedThatChannelWithThisCodeAlreadyExists()  | 
            ||
| 276 | |||
| 277 | /**  | 
            ||
| 278 | * @Then there should still be only one channel with :element :value  | 
            ||
| 279 | */  | 
            ||
| 280 | public function thereShouldStillBeOnlyOneChannelWithCode($element, $value)  | 
            ||
| 286 | |||
| 287 | /**  | 
            ||
| 288 | * @When I browse channels  | 
            ||
| 289 | * @When I want to browse channels  | 
            ||
| 290 | */  | 
            ||
| 291 | public function iWantToBrowseChannels(): void  | 
            ||
| 295 | |||
| 296 | /**  | 
            ||
| 297 | * @When I check (also) the :channelName channel  | 
            ||
| 298 | */  | 
            ||
| 299 | public function iCheckTheChannel(string $channelName): void  | 
            ||
| 303 | |||
| 304 | /**  | 
            ||
| 305 | * @When I delete them  | 
            ||
| 306 | */  | 
            ||
| 307 | public function iDeleteThem(): void  | 
            ||
| 311 | |||
| 312 | /**  | 
            ||
| 313 | * @Then I should see a single channel in the list  | 
            ||
| 314 | * @Then I should see :numberOfChannels channels in the list  | 
            ||
| 315 | */  | 
            ||
| 316 | public function iShouldSeeChannelsInTheList(int $numberOfChannels = 1): void  | 
            ||
| 320 | |||
| 321 | /**  | 
            ||
| 322 | * @Then the code field should be disabled  | 
            ||
| 323 | */  | 
            ||
| 324 | public function theCodeFieldShouldBeDisabled()  | 
            ||
| 328 | |||
| 329 | /**  | 
            ||
| 330 | * @Then /^(this channel) should be disabled$/  | 
            ||
| 331 | */  | 
            ||
| 332 | public function thisChannelShouldBeDisabled(ChannelInterface $channel)  | 
            ||
| 336 | |||
| 337 | /**  | 
            ||
| 338 | * @Then /^(this channel) should be enabled$/  | 
            ||
| 339 | * @Then channel with name :channel should still be enabled  | 
            ||
| 340 | */  | 
            ||
| 341 | public function thisChannelShouldBeEnabled(ChannelInterface $channel)  | 
            ||
| 345 | |||
| 346 | /**  | 
            ||
| 347 | * @When I delete channel :channel  | 
            ||
| 348 | */  | 
            ||
| 349 | public function iDeleteChannel(ChannelInterface $channel)  | 
            ||
| 354 | |||
| 355 | /**  | 
            ||
| 356 | * @Then the :channelName channel should no longer exist in the registry  | 
            ||
| 357 | */  | 
            ||
| 358 | public function thisChannelShouldNoLongerExistInTheRegistry($channelName)  | 
            ||
| 362 | |||
| 363 | /**  | 
            ||
| 364 | * @Then I should be notified that it cannot be deleted  | 
            ||
| 365 | */  | 
            ||
| 366 | public function iShouldBeNotifiedThatItCannotBeDeleted()  | 
            ||
| 373 | |||
| 374 | /**  | 
            ||
| 375 | * @When I make it available (only) in :locale  | 
            ||
| 376 | */  | 
            ||
| 377 | public function iMakeItAvailableIn(string $localeName): void  | 
            ||
| 384 | |||
| 385 | /**  | 
            ||
| 386 | * @Then the channel :channel should be available in :locale  | 
            ||
| 387 | */  | 
            ||
| 388 | public function theChannelShouldBeAvailableIn(ChannelInterface $channel, $locale)  | 
            ||
| 394 | |||
| 395 | /**  | 
            ||
| 396 | * @When I allow for paying in :currencyCode  | 
            ||
| 397 | */  | 
            ||
| 398 | public function iAllowToPayingForThisChannel($currencyCode)  | 
            ||
| 405 | |||
| 406 | /**  | 
            ||
| 407 | * @Then paying in :currencyCode should be possible for the :channel channel  | 
            ||
| 408 | */  | 
            ||
| 409 | public function payingInEuroShouldBePossibleForTheChannel($currencyCode, ChannelInterface $channel)  | 
            ||
| 415 | |||
| 416 | /**  | 
            ||
| 417 | * @When I select the :taxZone as default tax zone  | 
            ||
| 418 | */  | 
            ||
| 419 | public function iSelectDefaultTaxZone($taxZone)  | 
            ||
| 426 | |||
| 427 | /**  | 
            ||
| 428 | * @Given I remove its default tax zone  | 
            ||
| 429 | */  | 
            ||
| 430 | public function iRemoveItsDefaultTaxZone()  | 
            ||
| 434 | |||
| 435 | /**  | 
            ||
| 436 | * @When I select the :taxCalculationStrategy as tax calculation strategy  | 
            ||
| 437 | */  | 
            ||
| 438 | public function iSelectTaxCalculationStrategy($taxCalculationStrategy)  | 
            ||
| 445 | |||
| 446 | /**  | 
            ||
| 447 | * @Then the default tax zone for the :channel channel should be :taxZone  | 
            ||
| 448 | */  | 
            ||
| 449 | public function theDefaultTaxZoneForTheChannelShouldBe(ChannelInterface $channel, $taxZone)  | 
            ||
| 455 | |||
| 456 | /**  | 
            ||
| 457 | * @Given channel :channel should not have default tax zone  | 
            ||
| 458 | */  | 
            ||
| 459 | public function channelShouldNotHaveDefaultTaxZone(ChannelInterface $channel)  | 
            ||
| 465 | |||
| 466 | /**  | 
            ||
| 467 | * @Then the tax calculation strategy for the :channel channel should be :taxCalculationStrategy  | 
            ||
| 468 | */  | 
            ||
| 469 | public function theTaxCalculationStrategyForTheChannelShouldBe(ChannelInterface $channel, $taxCalculationStrategy)  | 
            ||
| 475 | |||
| 476 | /**  | 
            ||
| 477 | * @Then the base currency field should be disabled  | 
            ||
| 478 | */  | 
            ||
| 479 | public function theBaseCurrencyFieldShouldBeDisabled()  | 
            ||
| 483 | |||
| 484 | /**  | 
            ||
| 485 | * @Then I should be notified that the default locale has to be enabled  | 
            ||
| 486 | */  | 
            ||
| 487 | public function iShouldBeNotifiedThatTheDefaultLocaleHasToBeEnabled(): void  | 
            ||
| 494 | |||
| 495 | /**  | 
            ||
| 496 | * @param bool $state  | 
            ||
| 497 | */  | 
            ||
| 498 | private function assertChannelState(ChannelInterface $channel, $state)  | 
            ||
| 507 | }  | 
            ||
| 508 |