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 | /** @var SharedStorageInterface */ |
||
| 34 | private $sharedStorage; |
||
| 35 | |||
| 36 | /** @var IndexPageInterface */ |
||
| 37 | private $indexPage; |
||
| 38 | |||
| 39 | /** @var ShowPageInterface */ |
||
| 40 | private $showPage; |
||
| 41 | |||
| 42 | /** @var UpdatePageInterface */ |
||
| 43 | private $updatePage; |
||
| 44 | |||
| 45 | /** @var HistoryPageInterface */ |
||
| 46 | private $historyPage; |
||
| 47 | |||
| 48 | /** @var NotificationCheckerInterface */ |
||
| 49 | private $notificationChecker; |
||
| 50 | |||
| 51 | /** @var SharedSecurityServiceInterface */ |
||
| 52 | private $sharedSecurityService; |
||
| 53 | |||
| 54 | public function __construct( |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @Given I am browsing orders |
||
| 74 | * @When I browse orders |
||
| 75 | */ |
||
| 76 | public function iBrowseOrders() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @When I browse order's :order history |
||
| 83 | */ |
||
| 84 | public function iBrowseOrderHistory(OrderInterface $order) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @Given /^I am viewing the summary of (this order)$/ |
||
| 91 | * @When I view the summary of the order :order |
||
| 92 | */ |
||
| 93 | public function iSeeTheOrder(OrderInterface $order) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @When /^I mark (this order) as paid$/ |
||
| 100 | */ |
||
| 101 | public function iMarkThisOrderAsAPaid(OrderInterface $order) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @When /^I mark (this order)'s payment as refunded$/ |
||
| 108 | */ |
||
| 109 | public function iMarkThisOrderSPaymentAsRefunded(OrderInterface $order) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @When specify its tracking code as :trackingCode |
||
| 116 | */ |
||
| 117 | public function specifyItsTrackingCodeAs($trackingCode) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @When /^I ship (this order)$/ |
||
| 125 | */ |
||
| 126 | public function iShipThisOrder(OrderInterface $order) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @When I switch the way orders are sorted by :fieldName |
||
| 133 | */ |
||
| 134 | public function iSwitchSortingBy($fieldName) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @When I specify filter date from as :dateTime |
||
| 141 | */ |
||
| 142 | public function iSpecifyFilterDateFromAs($dateTime) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @When I specify filter date to as :dateTime |
||
| 149 | */ |
||
| 150 | public function iSpecifyFilterDateToAs($dateTime) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @When I choose :channelName as a channel filter |
||
| 157 | */ |
||
| 158 | public function iChooseChannelAsAChannelFilter($channelName) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @When I choose :currencyName as the filter currency |
||
| 165 | */ |
||
| 166 | public function iChooseCurrencyAsTheFilterCurrency($currencyName) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @When I specify filter total being greater than :total |
||
| 173 | */ |
||
| 174 | public function iSpecifyFilterTotalBeingGreaterThan($total) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @When I specify filter total being less than :total |
||
| 181 | */ |
||
| 182 | public function iSpecifyFilterTotalBeingLessThan($total) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @When I filter |
||
| 189 | */ |
||
| 190 | public function iFilter() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @Then I should see a single order from customer :customer |
||
| 197 | */ |
||
| 198 | public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @Then it should have been placed by the customer :customerEmail |
||
| 205 | */ |
||
| 206 | public function itShouldBePlacedByCustomer($customerEmail) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @Then it should be shipped to :customerName, :street, :postcode, :city, :countryName |
||
| 213 | * @Then /^(this order) should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/ |
||
| 214 | */ |
||
| 215 | public function itShouldBeShippedTo( |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @Then it should be billed to :customerName, :street, :postcode, :city, :countryName |
||
| 232 | * @Then the order should be billed to :customerName, :street, :postcode, :city, :countryName |
||
| 233 | * @Then /^(this order) bill should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/ |
||
| 234 | */ |
||
| 235 | public function itShouldBeBilledTo( |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @Then it should have no shipping address set |
||
| 252 | */ |
||
| 253 | public function itShouldHaveNoShippingAddressSet(): void |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @Then it should be shipped via the :shippingMethodName shipping method |
||
| 260 | */ |
||
| 261 | public function itShouldBeShippedViaShippingMethod($shippingMethodName) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @Then it should be paid with :paymentMethodName |
||
| 268 | */ |
||
| 269 | public function itShouldBePaidWith($paymentMethodName) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @Then /^it should have (\d+) items$/ |
||
| 276 | * @Then I should see :amount orders in the list |
||
| 277 | * @Then I should see a single order in the list |
||
| 278 | */ |
||
| 279 | public function itShouldHaveAmountOfItems($amount = 1) |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @Then the product named :productName should be in the items list |
||
| 286 | */ |
||
| 287 | public function theProductShouldBeInTheItemsList($productName) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @Then the order's items total should be :itemsTotal |
||
| 294 | */ |
||
| 295 | public function theOrdersItemsTotalShouldBe($itemsTotal) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @Then /^the order's total should(?:| still) be "([^"]+)"$/ |
||
| 302 | */ |
||
| 303 | public function theOrdersTotalShouldBe($total) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @Then there should be a shipping charge :shippingCharge |
||
| 310 | */ |
||
| 311 | public function theOrdersShippingChargesShouldBe($shippingCharge) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @Then the order's shipping total should be :shippingTotal |
||
| 318 | */ |
||
| 319 | public function theOrdersShippingTotalShouldBe($shippingTotal) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @Then the order's payment should (also) be :paymentAmount |
||
| 326 | */ |
||
| 327 | public function theOrdersPaymentShouldBe($paymentAmount) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @Then the order should have tax :tax |
||
| 334 | */ |
||
| 335 | public function theOrderShouldHaveTax($tax) |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @Then /^the order's tax total should(?:| still) be "([^"]+)"$/ |
||
| 342 | */ |
||
| 343 | public function theOrdersTaxTotalShouldBe($taxTotal) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @Then the order's promotion discount should be :promotionDiscount |
||
| 350 | */ |
||
| 351 | public function theOrdersPromotionDiscountShouldBe($promotionDiscount) |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @Then the order's shipping promotion should be :promotion |
||
| 358 | */ |
||
| 359 | public function theOrdersShippingPromotionDiscountShouldBe($promotionData) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @Then /^the order's promotion total should(?:| still) be "([^"]+)"$/ |
||
| 366 | */ |
||
| 367 | public function theOrdersPromotionTotalShouldBe($promotionTotal) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @When I check :itemName data |
||
| 374 | */ |
||
| 375 | public function iCheckData($itemName) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @Then /^(its) code should be "([^"]+)"$/ |
||
| 382 | */ |
||
| 383 | public function itemCodeShouldBe($itemName, $code) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @Then /^(its) unit price should be ([^"]+)$/ |
||
| 390 | */ |
||
| 391 | public function itemUnitPriceShouldBe($itemName, $unitPrice) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @Then /^(its) discounted unit price should be ([^"]+)$/ |
||
| 398 | */ |
||
| 399 | public function itemDiscountedUnitPriceShouldBe($itemName, $discountedUnitPrice) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @Then /^(its) quantity should be ([^"]+)$/ |
||
| 406 | */ |
||
| 407 | public function itemQuantityShouldBe($itemName, $quantity) |
||
| 411 | |||
| 412 | /** |
||
| 413 | * @Then /^(its) subtotal should be ([^"]+)$/ |
||
| 414 | */ |
||
| 415 | public function itemSubtotalShouldBe($itemName, $subtotal) |
||
| 419 | |||
| 420 | /** |
||
| 421 | * @Then /^(its) discount should be ([^"]+)$/ |
||
| 422 | */ |
||
| 423 | public function theItemShouldHaveDiscount($itemName, $discount) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @Then /^(its) tax should be ([^"]+)$/ |
||
| 430 | */ |
||
| 431 | public function itemTaxShouldBe($itemName, $tax) |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @Then /^(its) total should be ([^"]+)$/ |
||
| 438 | */ |
||
| 439 | public function itemTotalShouldBe($itemName, $total) |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @Then I should be notified that the order's payment has been successfully completed |
||
| 446 | */ |
||
| 447 | public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted() |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @Then I should be notified that the order's payment has been successfully refunded |
||
| 457 | */ |
||
| 458 | public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded() |
||
| 465 | |||
| 466 | /** |
||
| 467 | * @Then it should have payment state :paymentState |
||
| 468 | * @Then it should have payment with state :paymentState |
||
| 469 | */ |
||
| 470 | public function itShouldHavePaymentState($paymentState) |
||
| 474 | |||
| 475 | /** |
||
| 476 | * @Then it should have order's payment state :orderPaymentState |
||
| 477 | */ |
||
| 478 | public function itShouldHaveOrderPaymentState($orderPaymentState) |
||
| 482 | |||
| 483 | /** |
||
| 484 | * @Then it should have order's shipping state :orderShippingState |
||
| 485 | */ |
||
| 486 | public function itShouldHaveOrderShippingState($orderShippingState) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @Then it's payment state should be refunded |
||
| 493 | */ |
||
| 494 | public function orderPaymentStateShouldBeRefunded() |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @Then /^I should not be able to mark (this order) as paid again$/ |
||
| 501 | */ |
||
| 502 | public function iShouldNotBeAbleToFinalizeItsPayment(OrderInterface $order) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * @Then I should be notified that the order has been successfully shipped |
||
| 509 | */ |
||
| 510 | public function iShouldBeNotifiedThatTheOrderHasBeenSuccessfullyShipped() |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @Then /^I should not be able to ship (this order)$/ |
||
| 520 | */ |
||
| 521 | public function iShouldNotBeAbleToShipThisOrder(OrderInterface $order) |
||
| 525 | |||
| 526 | /** |
||
| 527 | * @When I cancel this order |
||
| 528 | */ |
||
| 529 | public function iCancelThisOrder() |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @Then I should be notified that it has been successfully updated |
||
| 536 | */ |
||
| 537 | public function iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled() |
||
| 544 | |||
| 545 | /** |
||
| 546 | * @Then I should not be able to cancel this order |
||
| 547 | */ |
||
| 548 | public function iShouldNotBeAbleToCancelThisOrder() |
||
| 552 | |||
| 553 | /** |
||
| 554 | * @Then this order should have state :state |
||
| 555 | * @Then its state should be :state |
||
| 556 | */ |
||
| 557 | public function itsStateShouldBe($state) |
||
| 561 | |||
| 562 | /** |
||
| 563 | * @Then it should( still) have a :state state |
||
| 564 | */ |
||
| 565 | public function itShouldHaveState($state) |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @Then /^(the administrator) should know about (this additional note) for (this order made by "[^"]+")$/ |
||
| 572 | */ |
||
| 573 | public function theCustomerServiceShouldKnowAboutThisAdditionalNotes( |
||
| 587 | |||
| 588 | /** |
||
| 589 | * @Then I should see an order with :orderNumber number |
||
| 590 | */ |
||
| 591 | public function iShouldSeeOrderWithNumber($orderNumber) |
||
| 595 | |||
| 596 | /** |
||
| 597 | * @Then I should not see an order with :orderNumber number |
||
| 598 | */ |
||
| 599 | public function iShouldNotSeeOrderWithNumber($orderNumber) |
||
| 603 | |||
| 604 | /** |
||
| 605 | * @Then I should not see any orders with currency :currencyCode |
||
| 606 | */ |
||
| 607 | public function iShouldNotSeeAnyOrderWithCurrency($currencyCode) |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @Then the first order should have number :number |
||
| 614 | */ |
||
| 615 | public function theFirstOrderShouldHaveNumber($number) |
||
| 619 | |||
| 620 | /** |
||
| 621 | * @Then it should have shipment in state :shipmentState |
||
| 622 | */ |
||
| 623 | public function itShouldHaveShipmentState($shipmentState) |
||
| 627 | |||
| 628 | /** |
||
| 629 | * @Then order :orderNumber should have shipment state :shippingState |
||
| 630 | */ |
||
| 631 | public function thisOrderShipmentStateShouldBe($shippingState) |
||
| 635 | |||
| 636 | /** |
||
| 637 | * @Then the order :order should have order payment state :orderPaymentState |
||
| 638 | * @Then /^(this order) should have order payment state "([^"]+)"$/ |
||
| 639 | */ |
||
| 640 | public function theOrderShouldHavePaymentState(OrderInterface $order, $orderPaymentState) |
||
| 644 | |||
| 645 | /** |
||
| 646 | * @Then the order :order should have order shipping state :orderShippingState |
||
| 647 | * @Then /^(this order) should have order shipping state "([^"]+)"$/ |
||
| 648 | */ |
||
| 649 | public function theOrderShouldHaveShippingState(OrderInterface $order, $orderShippingState) |
||
| 653 | |||
| 654 | /** |
||
| 655 | * @Then /^there should be(?:| only) (\d+) payments?$/ |
||
| 656 | */ |
||
| 657 | public function theOrderShouldHaveNumberOfPayments($number) |
||
| 661 | |||
| 662 | /** |
||
| 663 | * @Then I should see the order :orderNumber with total :total |
||
| 664 | */ |
||
| 665 | public function iShouldSeeTheOrderWithTotal($orderNumber, $total) |
||
| 669 | |||
| 670 | /** |
||
| 671 | * @When /^I want to modify a customer's (?:billing|shipping) address of (this order)$/ |
||
| 672 | */ |
||
| 673 | public function iWantToModifyACustomerSShippingAddress(OrderInterface $order) |
||
| 677 | |||
| 678 | /** |
||
| 679 | * @When I save my changes |
||
| 680 | * @When I try to save my changes |
||
| 681 | */ |
||
| 682 | public function iSaveMyChanges() |
||
| 686 | |||
| 687 | /** |
||
| 688 | * @When /^I specify their (?:|new )shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/ |
||
| 689 | */ |
||
| 690 | public function iSpecifyTheirShippingAddressAsFor(AddressInterface $address) |
||
| 694 | |||
| 695 | /** |
||
| 696 | * @When /^I specify their (?:|new )billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/ |
||
| 697 | */ |
||
| 698 | public function iSpecifyTheirBillingAddressAsFor(AddressInterface $address) |
||
| 702 | |||
| 703 | /** |
||
| 704 | * @Then /^I should be notified that the "([^"]+)", the "([^"]+)", the "([^"]+)" and the "([^"]+)" in (shipping|billing) details are required$/ |
||
| 705 | */ |
||
| 706 | public function iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired($firstElement, $secondElement, $thirdElement, $fourthElement, $type) |
||
| 713 | |||
| 714 | /** |
||
| 715 | * @Then I should see :provinceName as province in the shipping address |
||
| 716 | */ |
||
| 717 | public function iShouldSeeAsProvinceInTheShippingAddress($provinceName) |
||
| 721 | |||
| 722 | /** |
||
| 723 | * @Then I should see :provinceName ad province in the billing address |
||
| 724 | */ |
||
| 725 | public function iShouldSeeAdProvinceInTheBillingAddress($provinceName) |
||
| 729 | |||
| 730 | /** |
||
| 731 | * @Then /^(the administrator) should know about IP address of (this order made by "[^"]+")$/ |
||
| 732 | */ |
||
| 733 | public function theAdministratorShouldKnowAboutIPAddressOfThisOrderMadeBy( |
||
| 746 | |||
| 747 | /** |
||
| 748 | * @When /^I (clear old billing address) information$/ |
||
| 749 | */ |
||
| 750 | public function iSpecifyTheBillingAddressAs(AddressInterface $address) |
||
| 754 | |||
| 755 | /** |
||
| 756 | * @When /^I (clear old shipping address) information$/ |
||
| 757 | */ |
||
| 758 | public function iSpecifyTheShippingAddressAs(AddressInterface $address) |
||
| 762 | |||
| 763 | /** |
||
| 764 | * @When /^I do not specify new information$/ |
||
| 765 | */ |
||
| 766 | public function iDoNotSpecifyNewInformation() |
||
| 770 | |||
| 771 | /** |
||
| 772 | * @Then /^(the administrator) should see that (order placed by "[^"]+") has "([^"]+)" currency$/ |
||
| 773 | */ |
||
| 774 | public function theAdministratorShouldSeeThatThisOrderHasBeenPlacedIn(AdminUserInterface $user, OrderInterface $order, $currency) |
||
| 782 | |||
| 783 | /** |
||
| 784 | * @Then /^(the administrator) should see the order with total "([^"]+)" in order list$/ |
||
| 785 | */ |
||
| 786 | public function theAdministratorShouldSeeTheOrderWithTotalInOrderList(AdminUserInterface $user, $total) |
||
| 794 | |||
| 795 | /** |
||
| 796 | * @Then there should be :count changes in the registry |
||
| 797 | */ |
||
| 798 | public function thereShouldBeCountChangesInTheRegistry($count) |
||
| 802 | |||
| 803 | /** |
||
| 804 | * @Then I should not be able to refund this payment |
||
| 805 | */ |
||
| 806 | public function iShouldNotBeAbleToRefundThisPayment() |
||
| 810 | |||
| 811 | /** |
||
| 812 | * @Then I should not see information about payments |
||
| 813 | */ |
||
| 814 | public function iShouldNotSeeInformationAboutPayments() |
||
| 818 | |||
| 819 | /** |
||
| 820 | * @Then I should not see information about shipments |
||
| 821 | */ |
||
| 822 | public function iShouldNotSeeInformationAboutShipments() |
||
| 826 | |||
| 827 | /** |
||
| 828 | * @param string $type |
||
| 829 | * @param string $element |
||
| 830 | * @param string $expectedMessage |
||
| 831 | * |
||
| 832 | * @throws \InvalidArgumentException |
||
| 833 | */ |
||
| 834 | private function assertElementValidationMessage($type, $element, $expectedMessage) |
||
| 839 | } |
||
| 840 |