Complex classes like ManagingOrdersContext 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 ManagingOrdersContext, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | final class ManagingOrdersContext implements Context |
||
32 | { |
||
33 | /** |
||
34 | * @var SharedStorageInterface |
||
35 | */ |
||
36 | private $sharedStorage; |
||
37 | |||
38 | /** |
||
39 | * @var IndexPageInterface |
||
40 | */ |
||
41 | private $indexPage; |
||
42 | |||
43 | /** |
||
44 | * @var ShowPageInterface |
||
45 | */ |
||
46 | private $showPage; |
||
47 | |||
48 | /** |
||
49 | * @var UpdatePageInterface |
||
50 | */ |
||
51 | private $updatePage; |
||
52 | |||
53 | /** |
||
54 | * @var HistoryPageInterface |
||
55 | */ |
||
56 | private $historyPage; |
||
57 | |||
58 | /** |
||
59 | * @var NotificationCheckerInterface |
||
60 | */ |
||
61 | private $notificationChecker; |
||
62 | |||
63 | /** |
||
64 | * @var SharedSecurityServiceInterface |
||
65 | */ |
||
66 | private $sharedSecurityService; |
||
67 | |||
68 | /** |
||
69 | * @param SharedStorageInterface $sharedStorage |
||
70 | * @param IndexPageInterface $indexPage |
||
71 | * @param ShowPageInterface $showPage |
||
72 | * @param UpdatePageInterface $updatePage |
||
73 | * @param HistoryPageInterface $historyPage |
||
74 | * @param NotificationCheckerInterface $notificationChecker |
||
75 | * @param SharedSecurityServiceInterface $sharedSecurityService |
||
76 | */ |
||
77 | public function __construct( |
||
94 | |||
95 | /** |
||
96 | * @Given I am browsing orders |
||
97 | * @When I browse orders |
||
98 | */ |
||
99 | public function iBrowseOrders() |
||
103 | |||
104 | /** |
||
105 | * @When I browse order's :order history |
||
106 | */ |
||
107 | public function iBrowseOrderHistory(OrderInterface $order) |
||
111 | |||
112 | /** |
||
113 | * @Given /^I am viewing the summary of (this order)$/ |
||
114 | * @When I view the summary of the order :order |
||
115 | */ |
||
116 | public function iSeeTheOrder(OrderInterface $order) |
||
120 | |||
121 | /** |
||
122 | * @When /^I mark (this order) as paid$/ |
||
123 | */ |
||
124 | public function iMarkThisOrderAsAPaid(OrderInterface $order) |
||
128 | |||
129 | /** |
||
130 | * @When /^I mark (this order)'s payment as refunded$/ |
||
131 | */ |
||
132 | public function iMarkThisOrderSPaymentAsRefunded(OrderInterface $order) |
||
136 | |||
137 | /** |
||
138 | * @When specify its tracking code as :trackingCode |
||
139 | */ |
||
140 | public function specifyItsTrackingCodeAs($trackingCode) |
||
145 | |||
146 | /** |
||
147 | * @When /^I ship (this order)$/ |
||
148 | */ |
||
149 | public function iShipThisOrder(OrderInterface $order) |
||
153 | |||
154 | /** |
||
155 | * @When I switch the way orders are sorted by :fieldName |
||
156 | */ |
||
157 | public function iSwitchSortingBy($fieldName) |
||
161 | |||
162 | /** |
||
163 | * @When I specify filter date from as :dateTime |
||
164 | */ |
||
165 | public function iSpecifyFilterDateFromAs($dateTime) |
||
169 | |||
170 | /** |
||
171 | * @When I specify filter date to as :dateTime |
||
172 | */ |
||
173 | public function iSpecifyFilterDateToAs($dateTime) |
||
177 | |||
178 | /** |
||
179 | * @When I choose :channelName as a channel filter |
||
180 | */ |
||
181 | public function iChooseChannelAsAChannelFilter($channelName) |
||
185 | |||
186 | /** |
||
187 | * @When I choose :currencyName as the filter currency |
||
188 | */ |
||
189 | public function iChooseCurrencyAsTheFilterCurrency($currencyName) |
||
193 | |||
194 | /** |
||
195 | * @When I specify filter total being greater than :total |
||
196 | */ |
||
197 | public function iSpecifyFilterTotalBeingGreaterThan($total) |
||
201 | |||
202 | /** |
||
203 | * @When I specify filter total being less than :total |
||
204 | */ |
||
205 | public function iSpecifyFilterTotalBeingLessThan($total) |
||
209 | |||
210 | /** |
||
211 | * @When I filter |
||
212 | */ |
||
213 | public function iFilter() |
||
217 | |||
218 | /** |
||
219 | * @Then I should see a single order from customer :customer |
||
220 | */ |
||
221 | public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer) |
||
225 | |||
226 | /** |
||
227 | * @Then it should have been placed by the customer :customerEmail |
||
228 | */ |
||
229 | public function itShouldBePlacedByCustomer($customerEmail) |
||
233 | |||
234 | /** |
||
235 | * @Then it should be shipped to :customerName, :street, :postcode, :city, :countryName |
||
236 | * @Then /^(this order) should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/ |
||
237 | */ |
||
238 | public function itShouldBeShippedTo( |
||
252 | |||
253 | /** |
||
254 | * @Then it should be billed to :customerName, :street, :postcode, :city, :countryName |
||
255 | * @Then the order should be billed to :customerName, :street, :postcode, :city, :countryName |
||
256 | * @Then /^(this order) bill should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/ |
||
257 | */ |
||
258 | public function itShouldBeBilledTo( |
||
272 | |||
273 | /** |
||
274 | * @Then it should be shipped via the :shippingMethodName shipping method |
||
275 | */ |
||
276 | public function itShouldBeShippedViaShippingMethod($shippingMethodName) |
||
280 | |||
281 | /** |
||
282 | * @Then it should be paid with :paymentMethodName |
||
283 | */ |
||
284 | public function itShouldBePaidWith($paymentMethodName) |
||
288 | |||
289 | /** |
||
290 | * @Then /^it should have (\d+) items$/ |
||
291 | * @Then I should see :amount orders in the list |
||
292 | * @Then I should see a single order in the list |
||
293 | */ |
||
294 | public function itShouldHaveAmountOfItems($amount = 1) |
||
298 | |||
299 | /** |
||
300 | * @Then the product named :productName should be in the items list |
||
301 | */ |
||
302 | public function theProductShouldBeInTheItemsList($productName) |
||
306 | |||
307 | /** |
||
308 | * @Then the order's items total should be :itemsTotal |
||
309 | */ |
||
310 | public function theOrdersItemsTotalShouldBe($itemsTotal) |
||
314 | |||
315 | /** |
||
316 | * @Then /^the order's total should(?:| still) be "([^"]+)"$/ |
||
317 | */ |
||
318 | public function theOrdersTotalShouldBe($total) |
||
322 | |||
323 | /** |
||
324 | * @Then there should be a shipping charge :shippingCharge |
||
325 | */ |
||
326 | public function theOrdersShippingChargesShouldBe($shippingCharge) |
||
330 | |||
331 | /** |
||
332 | * @Then the order's shipping total should be :shippingTotal |
||
333 | */ |
||
334 | public function theOrdersShippingTotalShouldBe($shippingTotal) |
||
338 | |||
339 | /** |
||
340 | * @Then the order's payment should (also) be :paymentAmount |
||
341 | */ |
||
342 | public function theOrdersPaymentShouldBe($paymentAmount) |
||
346 | |||
347 | /** |
||
348 | * @Then the order should have tax :tax |
||
349 | */ |
||
350 | public function theOrderShouldHaveTax($tax) |
||
354 | |||
355 | /** |
||
356 | * @Then /^the order's tax total should(?:| still) be "([^"]+)"$/ |
||
357 | */ |
||
358 | public function theOrdersTaxTotalShouldBe($taxTotal) |
||
362 | |||
363 | /** |
||
364 | * @Then the order's promotion discount should be :promotionDiscount |
||
365 | */ |
||
366 | public function theOrdersPromotionDiscountShouldBe($promotionDiscount) |
||
370 | |||
371 | /** |
||
372 | * @Then the order's shipping promotion should be :promotion |
||
373 | */ |
||
374 | public function theOrdersShippingPromotionDiscountShouldBe($promotionData) |
||
378 | |||
379 | /** |
||
380 | * @Then /^the order's promotion total should(?:| still) be "([^"]+)"$/ |
||
381 | */ |
||
382 | public function theOrdersPromotionTotalShouldBe($promotionTotal) |
||
386 | |||
387 | /** |
||
388 | * @When I check :itemName data |
||
389 | */ |
||
390 | public function iCheckData($itemName) |
||
394 | |||
395 | /** |
||
396 | * @Then /^(its) code should be "([^"]+)"$/ |
||
397 | */ |
||
398 | public function itemCodeShouldBe($itemName, $code) |
||
402 | |||
403 | /** |
||
404 | * @Then /^(its) unit price should be ([^"]+)$/ |
||
405 | */ |
||
406 | public function itemUnitPriceShouldBe($itemName, $unitPrice) |
||
410 | |||
411 | /** |
||
412 | * @Then /^(its) discounted unit price should be ([^"]+)$/ |
||
413 | */ |
||
414 | public function itemDiscountedUnitPriceShouldBe($itemName, $discountedUnitPrice) |
||
418 | |||
419 | /** |
||
420 | * @Then /^(its) quantity should be ([^"]+)$/ |
||
421 | */ |
||
422 | public function itemQuantityShouldBe($itemName, $quantity) |
||
426 | |||
427 | /** |
||
428 | * @Then /^(its) subtotal should be ([^"]+)$/ |
||
429 | */ |
||
430 | public function itemSubtotalShouldBe($itemName, $subtotal) |
||
434 | |||
435 | /** |
||
436 | * @Then /^(its) discount should be ([^"]+)$/ |
||
437 | */ |
||
438 | public function theItemShouldHaveDiscount($itemName, $discount) |
||
442 | |||
443 | /** |
||
444 | * @Then /^(its) tax should be ([^"]+)$/ |
||
445 | */ |
||
446 | public function itemTaxShouldBe($itemName, $tax) |
||
450 | |||
451 | /** |
||
452 | * @Then /^(its) total should be ([^"]+)$/ |
||
453 | */ |
||
454 | public function itemTotalShouldBe($itemName, $total) |
||
458 | |||
459 | /** |
||
460 | * @Then I should be notified that the order's payment has been successfully completed |
||
461 | */ |
||
462 | public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted() |
||
469 | |||
470 | /** |
||
471 | * @Then I should be notified that the order's payment has been successfully refunded |
||
472 | */ |
||
473 | public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded() |
||
480 | |||
481 | /** |
||
482 | * @Then it should have payment state :paymentState |
||
483 | * @Then it should have payment with state :paymentState |
||
484 | */ |
||
485 | public function itShouldHavePaymentState($paymentState) |
||
489 | |||
490 | /** |
||
491 | * @Then it should have order's payment state :orderPaymentState |
||
492 | */ |
||
493 | public function itShouldHaveOrderPaymentState($orderPaymentState) |
||
497 | |||
498 | /** |
||
499 | * @Then it should have order's shipping state :orderShippingState |
||
500 | */ |
||
501 | public function itShouldHaveOrderShippingState($orderShippingState) |
||
505 | |||
506 | /** |
||
507 | * @Then it's payment state should be refunded |
||
508 | */ |
||
509 | public function orderPaymentStateShouldBeRefunded() |
||
513 | |||
514 | /** |
||
515 | * @Then /^I should not be able to mark (this order) as paid again$/ |
||
516 | */ |
||
517 | public function iShouldNotBeAbleToFinalizeItsPayment(OrderInterface $order) |
||
521 | |||
522 | /** |
||
523 | * @Then I should be notified that the order has been successfully shipped |
||
524 | */ |
||
525 | public function iShouldBeNotifiedThatTheOrderHasBeenSuccessfullyShipped() |
||
532 | |||
533 | /** |
||
534 | * @Then /^I should not be able to ship (this order)$/ |
||
535 | */ |
||
536 | public function iShouldNotBeAbleToShipThisOrder(OrderInterface $order) |
||
540 | |||
541 | /** |
||
542 | * @When I cancel this order |
||
543 | */ |
||
544 | public function iCancelThisOrder() |
||
548 | |||
549 | /** |
||
550 | * @Then I should be notified that it has been successfully updated |
||
551 | */ |
||
552 | public function iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled() |
||
559 | |||
560 | /** |
||
561 | * @Then I should not be able to cancel this order |
||
562 | */ |
||
563 | public function iShouldNotBeAbleToCancelThisOrder() |
||
567 | |||
568 | /** |
||
569 | * @Then this order should have state :state |
||
570 | * @Then its state should be :state |
||
571 | */ |
||
572 | public function itsStateShouldBe($state) |
||
576 | |||
577 | /** |
||
578 | * @Then it should( still) have a :state state |
||
579 | */ |
||
580 | public function itShouldHaveState($state) |
||
584 | |||
585 | /** |
||
586 | * @Then /^(the administrator) should know about (this additional note) for (this order made by "[^"]+")$/ |
||
587 | */ |
||
588 | public function theCustomerServiceShouldKnowAboutThisAdditionalNotes( |
||
602 | |||
603 | /** |
||
604 | * @Then I should see an order with :orderNumber number |
||
605 | */ |
||
606 | public function iShouldSeeOrderWithNumber($orderNumber) |
||
610 | |||
611 | /** |
||
612 | * @Then I should not see an order with :orderNumber number |
||
613 | */ |
||
614 | public function iShouldNotSeeOrderWithNumber($orderNumber) |
||
618 | |||
619 | /** |
||
620 | * @Then I should not see any orders with currency :currencyCode |
||
621 | */ |
||
622 | public function iShouldNotSeeAnyOrderWithCurrency($currencyCode) |
||
626 | |||
627 | /** |
||
628 | * @Then the first order should have number :number |
||
629 | */ |
||
630 | public function theFirstOrderShouldHaveNumber($number) |
||
634 | |||
635 | /** |
||
636 | * @Then it should have shipment in state :shipmentState |
||
637 | */ |
||
638 | public function itShouldHaveShipmentState($shipmentState) |
||
642 | |||
643 | /** |
||
644 | * @Then order :orderNumber should have shipment state :shippingState |
||
645 | */ |
||
646 | public function thisOrderShipmentStateShouldBe($shippingState) |
||
650 | |||
651 | /** |
||
652 | * @Then the order :order should have order payment state :orderPaymentState |
||
653 | * @Then /^(this order) should have order payment state "([^"]+)"$/ |
||
654 | */ |
||
655 | public function theOrderShouldHavePaymentState(OrderInterface $order, $orderPaymentState) |
||
659 | |||
660 | /** |
||
661 | * @Then the order :order should have order shipping state :orderShippingState |
||
662 | * @Then /^(this order) should have order shipping state "([^"]+)"$/ |
||
663 | */ |
||
664 | public function theOrderShouldHaveShippingState(OrderInterface $order, $orderShippingState) |
||
668 | |||
669 | /** |
||
670 | * @Then /^there should be(?:| only) (\d+) payments?$/ |
||
671 | */ |
||
672 | public function theOrderShouldHaveNumberOfPayments($number) |
||
676 | |||
677 | /** |
||
678 | * @Then I should see the order :orderNumber with total :total |
||
679 | */ |
||
680 | public function iShouldSeeTheOrderWithTotal($orderNumber, $total) |
||
684 | |||
685 | /** |
||
686 | * @When /^I want to modify a customer's (?:billing|shipping) address of (this order)$/ |
||
687 | */ |
||
688 | public function iWantToModifyACustomerSShippingAddress(OrderInterface $order) |
||
692 | |||
693 | /** |
||
694 | * @When I save my changes |
||
695 | * @When I try to save my changes |
||
696 | */ |
||
697 | public function iSaveMyChanges() |
||
701 | |||
702 | /** |
||
703 | * @When /^I specify their (?:|new )shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/ |
||
704 | */ |
||
705 | public function iSpecifyTheirShippingAddressAsFor(AddressInterface $address) |
||
709 | |||
710 | /** |
||
711 | * @When /^I specify their (?:|new )billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/ |
||
712 | */ |
||
713 | public function iSpecifyTheirBillingAddressAsFor(AddressInterface $address) |
||
717 | |||
718 | /** |
||
719 | * @Then /^I should be notified that the "([^"]+)", the "([^"]+)", the "([^"]+)" and the "([^"]+)" in (shipping|billing) details are required$/ |
||
720 | */ |
||
721 | public function iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired($firstElement, $secondElement, $thirdElement, $fourthElement, $type) |
||
728 | |||
729 | /** |
||
730 | * @Then I should see :provinceName as province in the shipping address |
||
731 | */ |
||
732 | public function iShouldSeeAsProvinceInTheShippingAddress($provinceName) |
||
736 | |||
737 | /** |
||
738 | * @Then I should see :provinceName ad province in the billing address |
||
739 | */ |
||
740 | public function iShouldSeeAdProvinceInTheBillingAddress($provinceName) |
||
744 | |||
745 | /** |
||
746 | * @Then /^(the administrator) should know about IP address of (this order made by "[^"]+")$/ |
||
747 | */ |
||
748 | public function theAdministratorShouldKnowAboutIPAddressOfThisOrderMadeBy( |
||
761 | |||
762 | /** |
||
763 | * @When /^I (clear old billing address) information$/ |
||
764 | */ |
||
765 | public function iSpecifyTheBillingAddressAs(AddressInterface $address) |
||
769 | |||
770 | /** |
||
771 | * @When /^I (clear old shipping address) information$/ |
||
772 | */ |
||
773 | public function iSpecifyTheShippingAddressAs(AddressInterface $address) |
||
777 | |||
778 | /** |
||
779 | * @When /^I do not specify new information$/ |
||
780 | */ |
||
781 | public function iDoNotSpecifyNewInformation() |
||
785 | |||
786 | /** |
||
787 | * @Then /^(the administrator) should see that (order placed by "[^"]+") has "([^"]+)" currency$/ |
||
788 | */ |
||
789 | public function theAdministratorShouldSeeThatThisOrderHasBeenPlacedIn(AdminUserInterface $user, OrderInterface $order, $currency) |
||
797 | |||
798 | /** |
||
799 | * @Then /^(the administrator) should see the order with total "([^"]+)" in order list$/ |
||
800 | */ |
||
801 | public function theAdministratorShouldSeeTheOrderWithTotalInOrderList(AdminUserInterface $user, $total) |
||
809 | |||
810 | /** |
||
811 | * @Then there should be :count changes in the registry |
||
812 | */ |
||
813 | public function thereShouldBeCountChangesInTheRegistry($count) |
||
817 | |||
818 | /** |
||
819 | * @Then I should not be able to refund this payment |
||
820 | */ |
||
821 | public function iShouldNotBeAbleToRefundThisPayment() |
||
825 | |||
826 | /** |
||
827 | * @Then I should not see information about payments |
||
828 | */ |
||
829 | public function iShouldNotSeeInformationAboutPayments() |
||
833 | |||
834 | /** |
||
835 | * @Then I should not see information about shipments |
||
836 | */ |
||
837 | public function iShouldNotSeeInformationAboutShipments() |
||
841 | |||
842 | /** |
||
843 | * @param string $type |
||
844 | * @param string $element |
||
845 | * @param string $expectedMessage |
||
846 | * |
||
847 | * @throws \InvalidArgumentException |
||
848 | */ |
||
849 | private function assertElementValidationMessage($type, $element, $expectedMessage) |
||
854 | } |
||
855 |