Complex classes like AccountContext 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 AccountContext, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | final class AccountContext implements Context |
||
31 | { |
||
32 | /** |
||
33 | * @var DashboardPageInterface |
||
34 | */ |
||
35 | private $dashboardPage; |
||
36 | |||
37 | /** |
||
38 | * @var ProfileUpdatePageInterface |
||
39 | */ |
||
40 | private $profileUpdatePage; |
||
41 | |||
42 | /** |
||
43 | * @var ChangePasswordPageInterface |
||
44 | */ |
||
45 | private $changePasswordPage; |
||
46 | |||
47 | /** |
||
48 | * @var IndexPageInterface |
||
49 | */ |
||
50 | private $orderIndexPage; |
||
51 | |||
52 | /** |
||
53 | * @var ShowPageInterface |
||
54 | */ |
||
55 | private $orderShowPage; |
||
56 | |||
57 | /** |
||
58 | * @var LoginPageInterface |
||
59 | */ |
||
60 | private $loginPage; |
||
61 | |||
62 | /** |
||
63 | * @var NotificationCheckerInterface |
||
64 | */ |
||
65 | private $notificationChecker; |
||
66 | |||
67 | /** |
||
68 | * @param DashboardPageInterface $dashboardPage |
||
69 | * @param ProfileUpdatePageInterface $profileUpdatePage |
||
70 | * @param ChangePasswordPageInterface $changePasswordPage |
||
71 | * @param IndexPageInterface $orderIndexPage |
||
72 | * @param ShowPageInterface $orderShowPage |
||
73 | * @param LoginPageInterface $loginPage |
||
74 | * @param NotificationCheckerInterface $notificationChecker |
||
75 | */ |
||
76 | public function __construct( |
||
93 | |||
94 | /** |
||
95 | * @When I want to modify my profile |
||
96 | */ |
||
97 | public function iWantToModifyMyProfile() |
||
101 | |||
102 | /** |
||
103 | * @When I specify the first name as :firstName |
||
104 | * @When I remove the first name |
||
105 | */ |
||
106 | public function iSpecifyTheFirstName($firstName = null) |
||
110 | |||
111 | /** |
||
112 | * @When I specify the last name as :lastName |
||
113 | * @When I remove the last name |
||
114 | */ |
||
115 | public function iSpecifyTheLastName($lastName = null) |
||
119 | |||
120 | /** |
||
121 | * @When I specify the customer email as :email |
||
122 | * @When I remove the customer email |
||
123 | */ |
||
124 | public function iSpecifyCustomerTheEmail($email = null) |
||
128 | |||
129 | /** |
||
130 | * @When I save my changes |
||
131 | * @When I try to save my changes |
||
132 | */ |
||
133 | public function iSaveMyChanges() |
||
137 | |||
138 | /** |
||
139 | * @Then I should be notified that it has been successfully edited |
||
140 | */ |
||
141 | public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited() |
||
145 | |||
146 | /** |
||
147 | * @Then my name should be :name |
||
148 | * @Then my name should still be :name |
||
149 | */ |
||
150 | public function myNameShouldBe($name) |
||
156 | |||
157 | /** |
||
158 | * @Then my email should be :email |
||
159 | * @Then my email should still be :email |
||
160 | */ |
||
161 | public function myEmailShouldBe($email) |
||
167 | |||
168 | /** |
||
169 | * @Then /^I should be notified that the (email|password|city|street|first name|last name) is required$/ |
||
170 | */ |
||
171 | public function iShouldBeNotifiedThatElementIsRequired($element) |
||
178 | |||
179 | /** |
||
180 | * @Then /^I should be notified that the (email) is invalid$/ |
||
181 | */ |
||
182 | public function iShouldBeNotifiedThatElementIsInvalid($element) |
||
189 | |||
190 | /** |
||
191 | * @Then I should be notified that the email is already used |
||
192 | */ |
||
193 | public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed() |
||
197 | |||
198 | /** |
||
199 | * @Given /^I want to change my password$/ |
||
200 | */ |
||
201 | public function iWantToChangeMyPassword() |
||
205 | |||
206 | /** |
||
207 | * @Given I change password from :oldPassword to :newPassword |
||
208 | */ |
||
209 | public function iChangePasswordTo($oldPassword, $newPassword) |
||
215 | |||
216 | /** |
||
217 | * @Then I should be notified that my password has been successfully changed |
||
218 | */ |
||
219 | public function iShouldBeNotifiedThatMyPasswordHasBeenSuccessfullyChanged() |
||
223 | |||
224 | /** |
||
225 | * @Given I specify the current password as :password |
||
226 | */ |
||
227 | public function iSpecifyTheCurrentPasswordAs($password) |
||
231 | |||
232 | /** |
||
233 | * @Given I specify the new password as :password |
||
234 | */ |
||
235 | public function iSpecifyTheNewPasswordAs($password) |
||
239 | |||
240 | /** |
||
241 | * @Given I confirm this password as :password |
||
242 | */ |
||
243 | public function iSpecifyTheConfirmationPasswordAs($password) |
||
247 | |||
248 | /** |
||
249 | * @Then I should be notified that provided password is different than the current one |
||
250 | */ |
||
251 | public function iShouldBeNotifiedThatProvidedPasswordIsDifferentThanTheCurrentOne() |
||
258 | |||
259 | /** |
||
260 | * @Then I should be notified that the entered passwords do not match |
||
261 | */ |
||
262 | public function iShouldBeNotifiedThatTheEnteredPasswordsDoNotMatch() |
||
269 | |||
270 | /** |
||
271 | * @Then I should be notified that the password should be at least 4 characters long |
||
272 | */ |
||
273 | public function iShouldBeNotifiedThatThePasswordShouldBeAtLeastCharactersLong() |
||
280 | |||
281 | /** |
||
282 | * @When I browse my orders |
||
283 | */ |
||
284 | public function iBrowseMyOrders() |
||
288 | |||
289 | /** |
||
290 | * @Then I should see a single order in the list |
||
291 | */ |
||
292 | public function iShouldSeeASingleOrderInTheList() |
||
296 | |||
297 | /** |
||
298 | * @Then this order should have :order number |
||
299 | */ |
||
300 | public function thisOrderShouldHaveNumber(OrderInterface $order) |
||
304 | |||
305 | /** |
||
306 | * @When I view the summary of the order :order |
||
307 | */ |
||
308 | public function iViewTheSummaryOfTheOrder(OrderInterface $order) |
||
312 | |||
313 | /** |
||
314 | * @When I am viewing the summary of my last order |
||
315 | */ |
||
316 | public function iViewingTheSummaryOfMyLastOrder() |
||
321 | |||
322 | /** |
||
323 | * @Then it should has number :orderNumber |
||
324 | */ |
||
325 | public function itShouldHasNumber($orderNumber) |
||
329 | |||
330 | /** |
||
331 | * @Then I should see :customerName, :street, :postcode, :city, :countryName as shipping address |
||
332 | */ |
||
333 | public function iShouldSeeAsShippingAddress($customerName, $street, $postcode, $city, $countryName) |
||
337 | |||
338 | /** |
||
339 | * @Then I should see :customerName, :street, :postcode, :city, :countryName as billing address |
||
340 | */ |
||
341 | public function itShouldBeShippedTo($customerName, $street, $postcode, $city, $countryName) |
||
345 | |||
346 | /** |
||
347 | * @Then I should see :total as order's total |
||
348 | */ |
||
349 | public function iShouldSeeAsOrderSTotal($total) |
||
353 | |||
354 | /** |
||
355 | * @Then I should see :itemsTotal as order's subtotal |
||
356 | */ |
||
357 | public function iShouldSeeAsOrderSSubtotal($subtotal) |
||
361 | |||
362 | /** |
||
363 | * @Then I should see that I have to pay :paymentAmount for this order |
||
364 | * @Then I should see :paymentTotal as payment total |
||
365 | */ |
||
366 | public function iShouldSeeIHaveToPayForThisOrder($paymentAmount) |
||
370 | |||
371 | /** |
||
372 | * @Then I should see :numberOfItems items in the list |
||
373 | */ |
||
374 | public function iShouldSeeItemsInTheList($numberOfItems) |
||
378 | |||
379 | /** |
||
380 | * @Then the product named :productName should be in the items list |
||
381 | */ |
||
382 | public function theProductShouldBeInTheItemsList($productName) |
||
386 | |||
387 | /** |
||
388 | * @Then I should see :itemPrice as item price |
||
389 | */ |
||
390 | public function iShouldSeeAsItemPrice($itemPrice) |
||
394 | |||
395 | /** |
||
396 | * @When I subscribe to the newsletter |
||
397 | */ |
||
398 | public function iSubscribeToTheNewsletter() |
||
402 | |||
403 | /** |
||
404 | * @Then I should be subscribed to the newsletter |
||
405 | */ |
||
406 | public function iShouldBeSubscribedToTheNewsletter() |
||
410 | |||
411 | /** |
||
412 | * @Then I should see :provinceName as province in the shipping address |
||
413 | */ |
||
414 | public function iShouldSeeAsProvinceInTheShippingAddress($provinceName) |
||
418 | |||
419 | /** |
||
420 | * @Then I should see :provinceName as province in the billing address |
||
421 | */ |
||
422 | public function iShouldSeeAsProvinceInTheBillingAddress($provinceName) |
||
426 | |||
427 | /** |
||
428 | * @Then /^I should be able to change payment method for (this order)$/ |
||
429 | */ |
||
430 | public function iShouldBeAbleToChangePaymentMethodForThisOrder(OrderInterface $order) |
||
434 | |||
435 | /** |
||
436 | * @Then I should be redirected to my account dashboard |
||
437 | */ |
||
438 | public function iShouldBeRedirectedToMyAccountDashboard() |
||
442 | |||
443 | /** |
||
444 | * @When I want to log in |
||
445 | */ |
||
446 | public function iWantToLogIn() |
||
450 | } |
||
451 |