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 |
||
29 | final class ManagingChannelsContext implements Context |
||
30 | { |
||
31 | /** @var IndexPageInterface */ |
||
32 | private $indexPage; |
||
33 | |||
34 | /** @var CreatePageInterface */ |
||
35 | private $createPage; |
||
36 | |||
37 | /** @var UpdatePageInterface */ |
||
38 | private $updatePage; |
||
39 | |||
40 | /** @var CurrentPageResolverInterface */ |
||
41 | private $currentPageResolver; |
||
42 | |||
43 | /** @var NotificationCheckerInterface */ |
||
44 | private $notificationChecker; |
||
45 | |||
46 | public function __construct( |
||
59 | |||
60 | /** |
||
61 | * @Given I want to create a new channel |
||
62 | */ |
||
63 | public function iWantToCreateANewChannel() |
||
67 | |||
68 | /** |
||
69 | * @When I specify its code as :code |
||
70 | * @When I do not specify its code |
||
71 | */ |
||
72 | public function iSpecifyItsCodeAs($code = null) |
||
76 | |||
77 | /** |
||
78 | * @When I name it :name |
||
79 | * @When I rename it to :name |
||
80 | * @When I do not name it |
||
81 | * @When I remove its name |
||
82 | */ |
||
83 | public function iNameIt($name = null) |
||
87 | |||
88 | /** |
||
89 | * @When I choose :currency as the base currency |
||
90 | * @When I do not choose base currency |
||
91 | */ |
||
92 | public function iChooseAsABaseCurrency(?CurrencyInterface $currency = null) |
||
96 | |||
97 | /** |
||
98 | * @When I choose :locale as a default locale |
||
99 | * @When I do not choose default locale |
||
100 | */ |
||
101 | public function iChooseAsADefaultLocale($locale = null) |
||
105 | |||
106 | /** |
||
107 | * @When I allow to skip shipping step if only one shipping method is available |
||
108 | */ |
||
109 | public function iAllowToSkipShippingStepIfOnlyOneShippingMethodIsAvailable() |
||
113 | |||
114 | /** |
||
115 | * @When I allow to skip payment step if only one payment method is available |
||
116 | */ |
||
117 | public function iAllowToSkipPaymentStepIfOnlyOnePaymentMethodIsAvailable() |
||
121 | |||
122 | /** |
||
123 | * @When I add it |
||
124 | * @When I try to add it |
||
125 | */ |
||
126 | public function iAddIt() |
||
130 | |||
131 | /** |
||
132 | * @Then I should see the channel :channelName in the list |
||
133 | * @Then the channel :channelName should appear in the registry |
||
134 | * @Then the channel :channelName should be in the registry |
||
135 | */ |
||
136 | public function theChannelShouldAppearInTheRegistry(string $channelName): void |
||
142 | |||
143 | /** |
||
144 | * @Then /^(this channel) should still be in the registry$/ |
||
145 | */ |
||
146 | public function thisChannelShouldAppearInTheRegistry(ChannelInterface $channel) |
||
150 | |||
151 | /** |
||
152 | * @When I describe it as :description |
||
153 | */ |
||
154 | public function iDescribeItAs($description) |
||
158 | |||
159 | /** |
||
160 | * @When I set its hostname as :hostname |
||
161 | */ |
||
162 | public function iSetItsHostnameAs($hostname) |
||
166 | |||
167 | /** |
||
168 | * @When I set its contact email as :contactEmail |
||
169 | */ |
||
170 | public function iSetItsContactEmailAs($contactEmail) |
||
174 | |||
175 | /** |
||
176 | * @When I define its color as :color |
||
177 | */ |
||
178 | public function iDefineItsColorAs($color) |
||
182 | |||
183 | /** |
||
184 | * @When I enable it |
||
185 | */ |
||
186 | public function iEnableIt() |
||
190 | |||
191 | /** |
||
192 | * @When I disable it |
||
193 | */ |
||
194 | public function iDisableIt() |
||
201 | |||
202 | /** |
||
203 | * @Then I should be notified that at least one channel has to be defined |
||
204 | */ |
||
205 | public function iShouldBeNotifiedThatAtLeastOneChannelHasToBeDefinedIsRequired() |
||
212 | |||
213 | /** |
||
214 | * @Then channel with :element :value should not be added |
||
215 | */ |
||
216 | public function channelWithShouldNotBeAdded($element, $value) |
||
222 | |||
223 | /** |
||
224 | * @Then /^I should be notified that ([^"]+) is required$/ |
||
225 | */ |
||
226 | public function iShouldBeNotifiedThatIsRequired($element) |
||
236 | |||
237 | /** |
||
238 | * @Given I am modifying a channel :channel |
||
239 | * @When I want to modify a channel :channel |
||
240 | * @When /^I want to modify (this channel)$/ |
||
241 | */ |
||
242 | public function iWantToModifyChannel(ChannelInterface $channel): void |
||
246 | |||
247 | /** |
||
248 | * @Then /^(this channel) name should be "([^"]+)"$/ |
||
249 | * @Then /^(this channel) should still be named "([^"]+)"$/ |
||
250 | */ |
||
251 | public function thisChannelNameShouldBe(ChannelInterface $channel, $channelName) |
||
260 | |||
261 | /** |
||
262 | * @When I save my changes |
||
263 | * @When I try to save my changes |
||
264 | */ |
||
265 | public function iSaveMyChanges() |
||
269 | |||
270 | /** |
||
271 | * @When /^I define its type as (mobile|website|pos)$/ |
||
272 | */ |
||
273 | public function iDefineItsTypeAs(string $type): void |
||
277 | |||
278 | /** |
||
279 | * @Then I should be notified that channel with this code already exists |
||
280 | */ |
||
281 | public function iShouldBeNotifiedThatChannelWithThisCodeAlreadyExists() |
||
285 | |||
286 | /** |
||
287 | * @Then there should still be only one channel with :element :value |
||
288 | */ |
||
289 | public function thereShouldStillBeOnlyOneChannelWithCode($element, $value) |
||
295 | |||
296 | /** |
||
297 | * @When I browse channels |
||
298 | * @When I want to browse channels |
||
299 | */ |
||
300 | public function iWantToBrowseChannels(): void |
||
304 | |||
305 | /** |
||
306 | * @When I check (also) the :channelName channel |
||
307 | */ |
||
308 | public function iCheckTheChannel(string $channelName): void |
||
312 | |||
313 | /** |
||
314 | * @When I delete them |
||
315 | */ |
||
316 | public function iDeleteThem(): void |
||
320 | |||
321 | /** |
||
322 | * @Then I should see a single channel in the list |
||
323 | * @Then I should see :numberOfChannels channels in the list |
||
324 | */ |
||
325 | public function iShouldSeeChannelsInTheList(int $numberOfChannels = 1): void |
||
329 | |||
330 | /** |
||
331 | * @Then the code field should be disabled |
||
332 | */ |
||
333 | public function theCodeFieldShouldBeDisabled() |
||
337 | |||
338 | /** |
||
339 | * @Then /^(this channel) should be disabled$/ |
||
340 | */ |
||
341 | public function thisChannelShouldBeDisabled(ChannelInterface $channel) |
||
345 | |||
346 | /** |
||
347 | * @Then /^(this channel) should be enabled$/ |
||
348 | * @Then channel with name :channel should still be enabled |
||
349 | */ |
||
350 | public function thisChannelShouldBeEnabled(ChannelInterface $channel) |
||
354 | |||
355 | /** |
||
356 | * @When I delete channel :channel |
||
357 | */ |
||
358 | public function iDeleteChannel(ChannelInterface $channel) |
||
363 | |||
364 | /** |
||
365 | * @Then the :channelName channel should no longer exist in the registry |
||
366 | */ |
||
367 | public function thisChannelShouldNoLongerExistInTheRegistry($channelName) |
||
371 | |||
372 | /** |
||
373 | * @Then I should be notified that it cannot be deleted |
||
374 | */ |
||
375 | public function iShouldBeNotifiedThatItCannotBeDeleted() |
||
382 | |||
383 | /** |
||
384 | * @When I make it available (only) in :locale |
||
385 | */ |
||
386 | public function iMakeItAvailableIn(string $localeName): void |
||
393 | |||
394 | /** |
||
395 | * @Then the channel :channel should be available in :locale |
||
396 | */ |
||
397 | public function theChannelShouldBeAvailableIn(ChannelInterface $channel, $locale) |
||
403 | |||
404 | /** |
||
405 | * @When I allow for paying in :currencyCode |
||
406 | */ |
||
407 | public function iAllowToPayingForThisChannel($currencyCode) |
||
414 | |||
415 | /** |
||
416 | * @Then paying in :currencyCode should be possible for the :channel channel |
||
417 | */ |
||
418 | public function payingInEuroShouldBePossibleForTheChannel($currencyCode, ChannelInterface $channel) |
||
424 | |||
425 | /** |
||
426 | * @When I select the :taxZone as default tax zone |
||
427 | */ |
||
428 | public function iSelectDefaultTaxZone($taxZone) |
||
435 | |||
436 | /** |
||
437 | * @Given I remove its default tax zone |
||
438 | */ |
||
439 | public function iRemoveItsDefaultTaxZone() |
||
443 | |||
444 | /** |
||
445 | * @When I select the :taxCalculationStrategy as tax calculation strategy |
||
446 | */ |
||
447 | public function iSelectTaxCalculationStrategy($taxCalculationStrategy) |
||
454 | |||
455 | /** |
||
456 | * @Then the default tax zone for the :channel channel should be :taxZone |
||
457 | */ |
||
458 | public function theDefaultTaxZoneForTheChannelShouldBe(ChannelInterface $channel, $taxZone) |
||
464 | |||
465 | /** |
||
466 | * @When /^I change its type to (mobile|website|pos)$/ |
||
467 | */ |
||
468 | public function iChangeItsTypeTo(string $type): void |
||
472 | |||
473 | /** |
||
474 | * @Given channel :channel should not have default tax zone |
||
475 | */ |
||
476 | public function channelShouldNotHaveDefaultTaxZone(ChannelInterface $channel) |
||
482 | |||
483 | /** |
||
484 | * @Then the tax calculation strategy for the :channel channel should be :taxCalculationStrategy |
||
485 | */ |
||
486 | public function theTaxCalculationStrategyForTheChannelShouldBe(ChannelInterface $channel, $taxCalculationStrategy) |
||
492 | |||
493 | /** |
||
494 | * @Then the base currency field should be disabled |
||
495 | */ |
||
496 | public function theBaseCurrencyFieldShouldBeDisabled() |
||
500 | |||
501 | /** |
||
502 | * @Then I should be notified that the default locale has to be enabled |
||
503 | */ |
||
504 | public function iShouldBeNotifiedThatTheDefaultLocaleHasToBeEnabled(): void |
||
511 | |||
512 | /** |
||
513 | * @Then /^this channel type should be (mobile|website|pos)$/ |
||
514 | */ |
||
515 | public function thisChannelTypeShouldBe(string $type): void |
||
519 | |||
520 | /** |
||
521 | * @param bool $state |
||
522 | */ |
||
523 | private function assertChannelState(ChannelInterface $channel, $state) |
||
532 | } |
||
533 |