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 | * @When /^I define its type as (mobile|website|pos)$/ |
||
271 | */ |
||
272 | public function iDefineItsTypeAs(string $type): void |
||
276 | |||
277 | /** |
||
278 | * @Then I should be notified that channel with this code already exists |
||
279 | */ |
||
280 | public function iShouldBeNotifiedThatChannelWithThisCodeAlreadyExists() |
||
284 | |||
285 | /** |
||
286 | * @Then there should still be only one channel with :element :value |
||
287 | */ |
||
288 | public function thereShouldStillBeOnlyOneChannelWithCode($element, $value) |
||
294 | |||
295 | /** |
||
296 | * @When I browse channels |
||
297 | * @When I want to browse channels |
||
298 | */ |
||
299 | public function iWantToBrowseChannels(): void |
||
303 | |||
304 | /** |
||
305 | * @When I check (also) the :channelName channel |
||
306 | */ |
||
307 | public function iCheckTheChannel(string $channelName): void |
||
311 | |||
312 | /** |
||
313 | * @When I delete them |
||
314 | */ |
||
315 | public function iDeleteThem(): void |
||
319 | |||
320 | /** |
||
321 | * @Then I should see a single channel in the list |
||
322 | * @Then I should see :numberOfChannels channels in the list |
||
323 | */ |
||
324 | public function iShouldSeeChannelsInTheList(int $numberOfChannels = 1): void |
||
328 | |||
329 | /** |
||
330 | * @Then the code field should be disabled |
||
331 | */ |
||
332 | public function theCodeFieldShouldBeDisabled() |
||
336 | |||
337 | /** |
||
338 | * @Then /^(this channel) should be disabled$/ |
||
339 | */ |
||
340 | public function thisChannelShouldBeDisabled(ChannelInterface $channel) |
||
344 | |||
345 | /** |
||
346 | * @Then /^(this channel) should be enabled$/ |
||
347 | * @Then channel with name :channel should still be enabled |
||
348 | */ |
||
349 | public function thisChannelShouldBeEnabled(ChannelInterface $channel) |
||
353 | |||
354 | /** |
||
355 | * @When I delete channel :channel |
||
356 | */ |
||
357 | public function iDeleteChannel(ChannelInterface $channel) |
||
362 | |||
363 | /** |
||
364 | * @Then the :channelName channel should no longer exist in the registry |
||
365 | */ |
||
366 | public function thisChannelShouldNoLongerExistInTheRegistry($channelName) |
||
370 | |||
371 | /** |
||
372 | * @Then I should be notified that it cannot be deleted |
||
373 | */ |
||
374 | public function iShouldBeNotifiedThatItCannotBeDeleted() |
||
381 | |||
382 | /** |
||
383 | * @When I make it available (only) in :locale |
||
384 | */ |
||
385 | public function iMakeItAvailableIn(string $localeName): void |
||
392 | |||
393 | /** |
||
394 | * @Then the channel :channel should be available in :locale |
||
395 | */ |
||
396 | public function theChannelShouldBeAvailableIn(ChannelInterface $channel, $locale) |
||
402 | |||
403 | /** |
||
404 | * @When I allow for paying in :currencyCode |
||
405 | */ |
||
406 | public function iAllowToPayingForThisChannel($currencyCode) |
||
413 | |||
414 | /** |
||
415 | * @Then paying in :currencyCode should be possible for the :channel channel |
||
416 | */ |
||
417 | public function payingInEuroShouldBePossibleForTheChannel($currencyCode, ChannelInterface $channel) |
||
423 | |||
424 | /** |
||
425 | * @When I select the :taxZone as default tax zone |
||
426 | */ |
||
427 | public function iSelectDefaultTaxZone($taxZone) |
||
434 | |||
435 | /** |
||
436 | * @Given I remove its default tax zone |
||
437 | */ |
||
438 | public function iRemoveItsDefaultTaxZone() |
||
442 | |||
443 | /** |
||
444 | * @When I select the :taxCalculationStrategy as tax calculation strategy |
||
445 | */ |
||
446 | public function iSelectTaxCalculationStrategy($taxCalculationStrategy) |
||
453 | |||
454 | /** |
||
455 | * @Then the default tax zone for the :channel channel should be :taxZone |
||
456 | */ |
||
457 | public function theDefaultTaxZoneForTheChannelShouldBe(ChannelInterface $channel, $taxZone) |
||
463 | |||
464 | /** |
||
465 | * @When /^I change its type to (mobile|website|pos)$/ |
||
466 | */ |
||
467 | public function iChangeItsTypeTo(string $type): void |
||
471 | |||
472 | /** |
||
473 | * @Given channel :channel should not have default tax zone |
||
474 | */ |
||
475 | public function channelShouldNotHaveDefaultTaxZone(ChannelInterface $channel) |
||
481 | |||
482 | /** |
||
483 | * @Then the tax calculation strategy for the :channel channel should be :taxCalculationStrategy |
||
484 | */ |
||
485 | public function theTaxCalculationStrategyForTheChannelShouldBe(ChannelInterface $channel, $taxCalculationStrategy) |
||
491 | |||
492 | /** |
||
493 | * @Then the base currency field should be disabled |
||
494 | */ |
||
495 | public function theBaseCurrencyFieldShouldBeDisabled() |
||
499 | |||
500 | /** |
||
501 | * @Then I should be notified that the default locale has to be enabled |
||
502 | */ |
||
503 | public function iShouldBeNotifiedThatTheDefaultLocaleHasToBeEnabled(): void |
||
510 | |||
511 | /** |
||
512 | * @Then /^this channel type should be (mobile|website|pos)$/ |
||
513 | */ |
||
514 | public function thisChannelTypeShouldBe(string $type): void |
||
518 | |||
519 | /** |
||
520 | * @param bool $state |
||
521 | */ |
||
522 | private function assertChannelState(ChannelInterface $channel, $state) |
||
531 | } |
||
532 |