Complex classes like ManagingZonesContext 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 ManagingZonesContext, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
28 | final class ManagingZonesContext implements Context |
||
29 | { |
||
30 | /** @var ApiClientInterface */ |
||
31 | private $client; |
||
32 | |||
33 | /** @var ResponseCheckerInterface */ |
||
34 | private $responseChecker; |
||
35 | |||
36 | /** @var SharedStorageInterface */ |
||
37 | private $sharedStorage; |
||
38 | |||
39 | /** @var IriConverterInterface */ |
||
40 | private $iriConverter; |
||
41 | |||
42 | public function __construct( |
||
53 | |||
54 | /** |
||
55 | * @When I want to create a new zone consisting of :memberType |
||
56 | */ |
||
57 | public function iWantToCreateANewZoneConsistingOfCountry(string $memberType): void |
||
62 | |||
63 | /** |
||
64 | * @When I name it :name |
||
65 | * @When I rename it to :name |
||
66 | */ |
||
67 | public function iNameIt(string $name): void |
||
71 | |||
72 | /** |
||
73 | * @When I specify its code as :code |
||
74 | */ |
||
75 | public function iSpecifyItsCodeAs(string $code): void |
||
79 | |||
80 | /** |
||
81 | * @When I do not specify its :type |
||
82 | * @When I do not add a country member |
||
83 | */ |
||
84 | public function iDoNotSpecifyItsField(): void |
||
88 | |||
89 | /** |
||
90 | * @When I add a country :country |
||
91 | */ |
||
92 | public function iAddACountry(CountryInterface $country): void |
||
98 | |||
99 | /** |
||
100 | * @When I add a province :province |
||
101 | */ |
||
102 | public function iAddAProvince(ProvinceInterface $province): void |
||
108 | |||
109 | /** |
||
110 | * @When I add a zone :zone |
||
111 | */ |
||
112 | public function iAddAZone(ZoneInterface $zone): void |
||
118 | |||
119 | /** |
||
120 | * @When I select its scope as :scope |
||
121 | */ |
||
122 | public function iSelectItsScopeAs(string $scope): void |
||
126 | |||
127 | /** |
||
128 | * @When I add it |
||
129 | * @When I try to add it |
||
130 | */ |
||
131 | public function iAddIt(): void |
||
135 | |||
136 | /** |
||
137 | * @When I want to see all zones in store |
||
138 | * @When I browse zones |
||
139 | */ |
||
140 | public function iWantToSeeAllZonesInStore(): void |
||
144 | |||
145 | /** |
||
146 | * @When I delete zone named :zone |
||
147 | */ |
||
148 | public function iDeleteZoneNamed(ZoneInterface $zone): void |
||
152 | |||
153 | /** |
||
154 | * @When I check the :zone zone |
||
155 | * @When I check also the :zone zone |
||
156 | */ |
||
157 | public function iCheckTheZone(ZoneInterface $zone): void |
||
166 | |||
167 | /** |
||
168 | * @When I delete them |
||
169 | */ |
||
170 | public function iDeleteThem(): void |
||
176 | |||
177 | /** |
||
178 | * @When I want to modify the zone named :zone |
||
179 | */ |
||
180 | public function iWantToModifyTheZoneNamed(ZoneInterface $zone): void |
||
184 | |||
185 | /** |
||
186 | * @When I remove the :country country member |
||
187 | */ |
||
188 | public function iRemoveTheCountryMember(CountryInterface $country): void |
||
192 | |||
193 | /** |
||
194 | * @When I remove the :province province member |
||
195 | */ |
||
196 | public function iRemoveTheProvinceMember(ProvinceInterface $province): void |
||
200 | |||
201 | /** |
||
202 | * @When I remove the :zone zone member |
||
203 | */ |
||
204 | public function iRemoveTheZoneMember(ZoneInterface $zone): void |
||
208 | |||
209 | /** |
||
210 | * @When I save my changes |
||
211 | */ |
||
212 | public function iSaveMyChanges(): void |
||
216 | |||
217 | /** |
||
218 | * @Then the zone named :zone with the :country country member should appear in the registry |
||
219 | */ |
||
220 | public function theZoneNamedWithTheCountryMemberShouldAppearInTheRegistry( |
||
230 | |||
231 | /** |
||
232 | * @Then I should not be able to edit its code |
||
233 | */ |
||
234 | public function iShouldNotBeAbleToEditItsCode(): void |
||
243 | |||
244 | /** |
||
245 | * @Then I can not add a zone :zone |
||
246 | */ |
||
247 | public function iCanNotAddAZone(ZoneInterface $zone): void |
||
258 | |||
259 | /** |
||
260 | * @Then the zone named :zone with the :province province member should appear in the registry |
||
261 | */ |
||
262 | public function theZoneNamedWithTheProvinceMemberShouldAppearInTheRegistry( |
||
272 | |||
273 | /** |
||
274 | * @Then the zone named :zone with the :otherZone zone member should appear in the registry |
||
275 | */ |
||
276 | public function theZoneNamedWithTheZoneMemberShouldAppearInTheRegistry( |
||
286 | |||
287 | /** |
||
288 | * @Then its scope should be :scope |
||
289 | */ |
||
290 | public function itsScopeShouldBe(string $scope): void |
||
297 | |||
298 | /** |
||
299 | * @Then I should see :count zones in the list |
||
300 | * @Then I should see a single zone in the list |
||
301 | */ |
||
302 | public function iShouldSeeZonesInTheList(int $count = 1): void |
||
306 | |||
307 | /** |
||
308 | * @Then I should see the zone named :name in the list |
||
309 | * @Then I should still see the zone named :name in the list |
||
310 | */ |
||
311 | public function iShouldSeeTheZoneNamedInTheList(string $name): void |
||
318 | |||
319 | /** |
||
320 | * @Then there should still be only one zone with code :code |
||
321 | */ |
||
322 | public function thereShouldStillBeOnlyOneZoneWithCode(string $code): void |
||
330 | |||
331 | /** |
||
332 | * @Then the zone named :name should no longer exist in the registry |
||
333 | */ |
||
334 | public function theZoneNamedShouldNoLongerExistInTheRegistry(string $name): void |
||
341 | |||
342 | /** |
||
343 | * @Then /^zone with (code|name) "([^"]*)" should not be added$/ |
||
344 | */ |
||
345 | public function zoneShouldNotBeAdded(string $field, string $value): void |
||
352 | |||
353 | /** |
||
354 | * @Then /^(this zone) should have only (the "([^"]*)" (?:country|province|zone) member)$/ |
||
355 | */ |
||
356 | public function thisZoneShouldHaveOnlyTheProvinceMember(ZoneInterface $zone, ZoneMemberInterface $zoneMember): void |
||
369 | |||
370 | /** |
||
371 | * @Then /^(this zone) name should be "([^"]*)"$/ |
||
372 | */ |
||
373 | public function thisZoneNameShouldBe(ZoneInterface $zone, string $name): void |
||
380 | |||
381 | /** |
||
382 | * @Then I should be notified that it has been successfully created |
||
383 | */ |
||
384 | public function iShouldBeNotifiedThatItHasBeenSuccessfullyCreated(): void |
||
391 | |||
392 | /** |
||
393 | * @Then I should be notified that it has been successfully edited |
||
394 | */ |
||
395 | public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void |
||
402 | |||
403 | /** |
||
404 | * @Then I should be notified that it has been successfully deleted |
||
405 | * @Then I should be notified that they have been successfully deleted |
||
406 | */ |
||
407 | public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted(): void |
||
414 | |||
415 | /** |
||
416 | * @Then I should be notified that this zone cannot be deleted |
||
417 | */ |
||
418 | public function iShouldBeNotifiedThatThisZoneCannotBeDeleted(): void |
||
425 | |||
426 | /** |
||
427 | * @Then I should be notified that zone with this code already exists |
||
428 | */ |
||
429 | public function iShouldBeNotifiedThatZoneWithThisCodeAlreadyExists(): void |
||
436 | |||
437 | /** |
||
438 | * @Then /^I should be notified that (code|name) is required$/ |
||
439 | */ |
||
440 | public function iShouldBeNotifiedThatIsRequired(string $element): void |
||
447 | |||
448 | /** |
||
449 | * @Then I should be notified that at least one zone member is required |
||
450 | */ |
||
451 | public function iShouldBeNotifiedThatAtLeastOneZoneMemberIsRequired(): void |
||
458 | |||
459 | /** |
||
460 | * @param CountryInterface|ZoneInterface|ProvinceInterface $objectToRemove |
||
461 | */ |
||
462 | private function removeZoneMember($objectToRemove): void |
||
468 | } |
||
469 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.