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 | /** |
||
31 | * @var IndexPageInterface |
||
32 | */ |
||
33 | private $indexPage; |
||
34 | |||
35 | /** |
||
36 | * @var CreatePageInterface |
||
37 | */ |
||
38 | private $createPage; |
||
39 | |||
40 | /** |
||
41 | * @var UpdatePageInterface |
||
42 | */ |
||
43 | private $updatePage; |
||
44 | |||
45 | /** |
||
46 | * @var CurrentPageResolverInterface |
||
47 | */ |
||
48 | private $currentPageResolver; |
||
49 | |||
50 | /** |
||
51 | * @var NotificationCheckerInterface |
||
52 | */ |
||
53 | private $notificationChecker; |
||
54 | |||
55 | /** |
||
56 | * @param IndexPageInterface $indexPage |
||
57 | * @param CreatePageInterface $createPage |
||
58 | * @param UpdatePageInterface $updatePage |
||
59 | * @param CurrentPageResolverInterface $currentPageResolver |
||
60 | * @param NotificationCheckerInterface $notificationChecker |
||
61 | */ |
||
62 | public function __construct( |
||
75 | |||
76 | /** |
||
77 | * @Given I want to create a new channel |
||
78 | */ |
||
79 | public function iWantToCreateANewChannel() |
||
83 | |||
84 | /** |
||
85 | * @When I specify its code as :code |
||
86 | * @When I do not specify its code |
||
87 | */ |
||
88 | public function iSpecifyItsCodeAs($code = null) |
||
92 | |||
93 | /** |
||
94 | * @When I name it :name |
||
95 | * @When I rename it to :name |
||
96 | * @When I do not name it |
||
97 | * @When I remove its name |
||
98 | */ |
||
99 | public function iNameIt($name = null) |
||
103 | |||
104 | /** |
||
105 | * @When I choose :currency as a default currency |
||
106 | * @When I do not choose default currency |
||
107 | */ |
||
108 | public function iChooseAsADefaultCurrency($currency = null) |
||
112 | |||
113 | /** |
||
114 | * @When I choose :locale as a default locale |
||
115 | * @When I do not choose default locale |
||
116 | */ |
||
117 | public function iChooseAsADefaultLocale($locale = null) |
||
121 | |||
122 | /** |
||
123 | * @When I add it |
||
124 | * @When I try to add it |
||
125 | */ |
||
126 | public function iAddIt() |
||
130 | |||
131 | /** |
||
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($channelName) |
||
144 | |||
145 | /** |
||
146 | * @Then /^(this channel) should still be in the registry$/ |
||
147 | */ |
||
148 | public function thisChannelShouldAppearInTheRegistry(ChannelInterface $channel) |
||
152 | |||
153 | /** |
||
154 | * @When I describe it as :description |
||
155 | */ |
||
156 | public function iDescribeItAs($description) |
||
160 | |||
161 | /** |
||
162 | * @When I set its hostname as :hostname |
||
163 | */ |
||
164 | public function iSetItsHostnameAs($hostname) |
||
168 | |||
169 | /** |
||
170 | * @When I define its color as :color |
||
171 | */ |
||
172 | public function iDefineItsColorAs($color) |
||
176 | |||
177 | /** |
||
178 | * @When I enable it |
||
179 | */ |
||
180 | public function iEnableIt() |
||
184 | |||
185 | /** |
||
186 | * @When I disable it |
||
187 | */ |
||
188 | public function iDisableIt() |
||
194 | |||
195 | /** |
||
196 | * @Then I should be notified that at least one channel has to be defined |
||
197 | */ |
||
198 | public function iShouldBeNotifiedThatAtLeastOneChannelHasToBeDefinedIsRequired() |
||
205 | |||
206 | /** |
||
207 | * @Then channel with :element :value should not be added |
||
208 | */ |
||
209 | public function channelWithShouldNotBeAdded($element, $value) |
||
218 | |||
219 | /** |
||
220 | * @Then /^I should be notified that ([^"]+) is required$/ |
||
221 | */ |
||
222 | public function iShouldBeNotifiedThatIsRequired($element) |
||
232 | |||
233 | /** |
||
234 | * @Given I want to modify a channel :channel |
||
235 | * @Given /^I want to modify (this channel)$/ |
||
236 | */ |
||
237 | public function iWantToModifyChannel(ChannelInterface $channel) |
||
241 | |||
242 | /** |
||
243 | * @Then /^(this channel) name should be "([^"]+)"$/ |
||
244 | * @Then /^(this channel) should still be named "([^"]+)"$/ |
||
245 | */ |
||
246 | 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 | * @Then I should be notified that channel with this code already exists |
||
272 | */ |
||
273 | public function iShouldBeNotifiedThatChannelWithThisCodeAlreadyExists() |
||
277 | |||
278 | /** |
||
279 | * @Then there should still be only one channel with :element :value |
||
280 | */ |
||
281 | public function thereShouldStillBeOnlyOneChannelWithCode($element, $value) |
||
290 | |||
291 | /** |
||
292 | * @When /^I want to browse channels$/ |
||
293 | */ |
||
294 | public function iWantToBrowseChannels() |
||
298 | |||
299 | /** |
||
300 | * @Then I should see :numberOfChannels channels in the list |
||
301 | */ |
||
302 | public function iShouldSeeChannelsInTheList($numberOfChannels) |
||
312 | |||
313 | /** |
||
314 | * @Then the code field should be disabled |
||
315 | */ |
||
316 | public function theCodeFieldShouldBeDisabled() |
||
323 | |||
324 | /** |
||
325 | * @Then /^(this channel) should be disabled$/ |
||
326 | */ |
||
327 | public function thisChannelShouldBeDisabled(ChannelInterface $channel) |
||
331 | |||
332 | /** |
||
333 | * @Then /^(this channel) should be enabled$/ |
||
334 | * @Then channel with name :channel should still be enabled |
||
335 | */ |
||
336 | public function thisChannelShouldBeEnabled(ChannelInterface $channel) |
||
340 | |||
341 | /** |
||
342 | * @When I delete channel :channel |
||
343 | */ |
||
344 | public function iDeleteChannel(ChannelInterface $channel) |
||
349 | |||
350 | /** |
||
351 | * @Then the :channelName channel should no longer exist in the registry |
||
352 | */ |
||
353 | public function thisChannelShouldNoLongerExistInTheRegistry($channelName) |
||
360 | |||
361 | /** |
||
362 | * @Then I should be notified that it cannot be deleted |
||
363 | */ |
||
364 | public function iShouldBeNotifiedThatItCannotBeDeleted() |
||
371 | |||
372 | /** |
||
373 | * @When I make it available in :locale |
||
374 | */ |
||
375 | public function iMakeItAvailableIn($locale) |
||
381 | |||
382 | /** |
||
383 | * @Then the channel :channel should be available in :locale |
||
384 | */ |
||
385 | public function theChannelShouldBeAvailableIn(ChannelInterface $channel, $locale) |
||
394 | |||
395 | /** |
||
396 | * @When I allow for paying in :currencyCode |
||
397 | */ |
||
398 | public function iAllowToPayingForThisChannel($currencyCode) |
||
404 | |||
405 | /** |
||
406 | * @Then paying in :currencyCode should be possible for the :channel channel |
||
407 | */ |
||
408 | public function payingInEuroShouldBePossibleForTheChannel($currencyCode, ChannelInterface $channel) |
||
417 | |||
418 | /** |
||
419 | * @When I select the :taxZone as default tax zone |
||
420 | */ |
||
421 | public function iSelectDefaultTaxZone($taxZone) |
||
427 | |||
428 | /** |
||
429 | * @Given I remove its default tax zone |
||
430 | */ |
||
431 | public function iRemoveItsDefaultTaxZone() |
||
435 | |||
436 | /** |
||
437 | * @When I select the :taxCalculationStrategy as tax calculation strategy |
||
438 | */ |
||
439 | 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) |
||
458 | |||
459 | /** |
||
460 | * @Given channel :channel should not have default tax zone |
||
461 | */ |
||
462 | public function channelShouldNotHaveDefaultTaxZone(ChannelInterface $channel) |
||
471 | |||
472 | /** |
||
473 | * @Then the tax calculation strategy for the :channel channel should be :taxCalculationStrategy |
||
474 | */ |
||
475 | public function theTaxCalculationStrategyForTheChannelShouldBe(ChannelInterface $channel, $taxCalculationStrategy) |
||
484 | |||
485 | /** |
||
486 | * @param ChannelInterface $channel |
||
487 | * @param bool $state |
||
488 | */ |
||
489 | private function assertChannelState(ChannelInterface $channel, $state) |
||
502 | } |
||
503 |
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.