Complex classes like ManagingCustomersContext 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 ManagingCustomersContext, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | final class ManagingCustomersContext implements Context |
||
| 27 | { |
||
| 28 | /** @var CustomerIndexPageInterface */ |
||
| 29 | private $indexPage; |
||
| 30 | |||
| 31 | /** @var CreatePageInterface */ |
||
| 32 | private $createPage; |
||
| 33 | |||
| 34 | /** @var UpdatePageInterface */ |
||
| 35 | private $updatePage; |
||
| 36 | |||
| 37 | /** @var ShowPageInterface */ |
||
| 38 | private $showPage; |
||
| 39 | |||
| 40 | /** @var IndexPageInterface */ |
||
| 41 | private $ordersIndexPage; |
||
| 42 | |||
| 43 | /** @var CurrentPageResolverInterface */ |
||
| 44 | private $currentPageResolver; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param CustomerIndexPageInterface $indexPage |
||
|
|
|||
| 48 | */ |
||
| 49 | public function __construct( |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @Given I want to create a new customer |
||
| 67 | * @Given I want to create a new customer account |
||
| 68 | */ |
||
| 69 | public function iWantToCreateANewCustomer() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @When /^I specify (?:their|his) first name as "([^"]*)"$/ |
||
| 76 | */ |
||
| 77 | public function iSpecifyItsFirstNameAs($name) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @When /^I specify (?:their|his) last name as "([^"]*)"$/ |
||
| 84 | */ |
||
| 85 | public function iSpecifyItsLastNameAs($name) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @When I specify their email as :name |
||
| 92 | * @When I do not specify their email |
||
| 93 | */ |
||
| 94 | public function iSpecifyItsEmailAs($email = null) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @When I change their email to :email |
||
| 101 | * @When I remove its email |
||
| 102 | */ |
||
| 103 | public function iChangeTheirEmailTo($email = null): void |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @When I add them |
||
| 110 | * @When I try to add them |
||
| 111 | */ |
||
| 112 | public function iAddIt() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @Then the customer :customer should appear in the store |
||
| 119 | * @Then the customer :customer should still have this email |
||
| 120 | */ |
||
| 121 | public function theCustomerShould(CustomerInterface $customer) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @When I select :gender as its gender |
||
| 130 | */ |
||
| 131 | public function iSelectGender($gender) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @When I select :group as their group |
||
| 138 | */ |
||
| 139 | public function iSelectGroup($group) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @When I specify its birthday as :birthday |
||
| 146 | */ |
||
| 147 | public function iSpecifyItsBirthdayAs($birthday) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @When /^I want to edit (this customer)$/ |
||
| 154 | */ |
||
| 155 | public function iWantToEditThisCustomer(CustomerInterface $customer) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @When I save my changes |
||
| 162 | * @When I try to save my changes |
||
| 163 | */ |
||
| 164 | public function iSaveMyChanges() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @Then /^(this customer) with name "([^"]*)" should appear in the store$/ |
||
| 171 | */ |
||
| 172 | public function theCustomerWithNameShouldAppearInTheRegistry(CustomerInterface $customer, $name) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @When I want to see all customers in store |
||
| 181 | */ |
||
| 182 | public function iWantToSeeAllCustomersInStore() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @Then /^I should see (\d+) customers in the list$/ |
||
| 189 | */ |
||
| 190 | public function iShouldSeeCustomersInTheList($amountOfCustomers) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @Then I should see the customer :email in the list |
||
| 197 | */ |
||
| 198 | public function iShouldSeeTheCustomerInTheList($email) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @Then /^I should be notified that ([^"]+) is required$/ |
||
| 205 | */ |
||
| 206 | public function iShouldBeNotifiedThatFirstNameIsRequired($elementName) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @Then /^I should be notified that ([^"]+) should be ([^"]+)$/ |
||
| 216 | */ |
||
| 217 | public function iShouldBeNotifiedThatTheElementShouldBe($elementName, $validationMessage) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @Then the customer with email :email should not appear in the store |
||
| 227 | */ |
||
| 228 | public function theCustomerShouldNotAppearInTheStore($email) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @When I remove its first name |
||
| 237 | */ |
||
| 238 | public function iRemoveItsFirstName() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @Then /^(this customer) should have an empty first name$/ |
||
| 245 | * @Then the customer :customer should still have an empty first name |
||
| 246 | */ |
||
| 247 | public function theCustomerShouldStillHaveAnEmptyFirstName(CustomerInterface $customer) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @When I remove its last name |
||
| 256 | */ |
||
| 257 | public function iRemoveItsLastName() |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @Then /^(this customer) should have an empty last name$/ |
||
| 264 | * @Then the customer :customer should still have an empty last name |
||
| 265 | */ |
||
| 266 | public function theCustomerShouldStillHaveAnEmptyLastName(CustomerInterface $customer) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @Then I should be notified that email is not valid |
||
| 275 | */ |
||
| 276 | public function iShouldBeNotifiedThatEmailIsNotValid() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @Then I should be notified that email must be unique |
||
| 283 | */ |
||
| 284 | public function iShouldBeNotifiedThatEmailMustBeUnique() |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @Then there should still be only one customer with email :email |
||
| 291 | */ |
||
| 292 | public function thereShouldStillBeOnlyOneCustomerWithEmail($email) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @Given I want to enable :customer |
||
| 301 | * @Given I want to disable :customer |
||
| 302 | */ |
||
| 303 | public function iWantToChangeStatusOf(CustomerInterface $customer) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @When I enable their account |
||
| 310 | */ |
||
| 311 | public function iEnableIt() |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @When I disable their account |
||
| 318 | */ |
||
| 319 | public function iDisableIt() |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @Then /^(this customer) should be enabled$/ |
||
| 326 | */ |
||
| 327 | public function thisCustomerShouldBeEnabled(CustomerInterface $customer) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @Then /^(this customer) should be disabled$/ |
||
| 336 | */ |
||
| 337 | public function thisCustomerShouldBeDisabled(CustomerInterface $customer) |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @When I specify their password as :password |
||
| 346 | */ |
||
| 347 | public function iSpecifyItsPasswordAs($password) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @When I choose create account option |
||
| 354 | */ |
||
| 355 | public function iChooseCreateAccountOption() |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @When I browse orders of a customer :customer |
||
| 362 | */ |
||
| 363 | public function iBrowseOrdersOfACustomer(CustomerInterface $customer): void |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @When I sort them by :sortBy |
||
| 370 | */ |
||
| 371 | public function iSortThemByChannel(string $sortBy): void |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @Then the customer :customer should have an account created |
||
| 378 | * @Then /^(this customer) should have an account created$/ |
||
| 379 | */ |
||
| 380 | public function theyShouldHaveAnAccountCreated(CustomerInterface $customer): void |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @When I view details of the customer :customer |
||
| 390 | * @When /^I view (their) details$/ |
||
| 391 | */ |
||
| 392 | public function iViewDetailsOfTheCustomer(CustomerInterface $customer) |
||
| 396 | |||
| 397 | /** |
||
| 398 | * @Then his name should be :name |
||
| 399 | */ |
||
| 400 | public function hisNameShouldBe($name) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @Then he should be registered since :registrationDate |
||
| 407 | */ |
||
| 408 | public function hisRegistrationDateShouldBe($registrationDate) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @Then his email should be :email |
||
| 415 | */ |
||
| 416 | public function hisEmailShouldBe($email) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @Then his phone number should be :phoneNumber |
||
| 423 | */ |
||
| 424 | public function hisPhoneNumberShouldBe($phoneNumber) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @Then his default address should be :defaultAddress |
||
| 431 | */ |
||
| 432 | public function hisShippingAddressShouldBe($defaultAddress) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * @Then I should see information about no existing account for this customer |
||
| 439 | */ |
||
| 440 | public function iShouldSeeInformationAboutNoExistingAccountForThisCustomer() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @Then I should see that this customer is subscribed to the newsletter |
||
| 447 | */ |
||
| 448 | public function iShouldSeeThatThisCustomerIsSubscribedToTheNewsletter() |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @Then I should not see information about email verification |
||
| 455 | */ |
||
| 456 | public function iShouldSeeInformationAboutEmailVerification() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @When I make them subscribed to the newsletter |
||
| 463 | */ |
||
| 464 | public function iMakeThemSubscribedToTheNewsletter() |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @When I change the password of user :customer to :newPassword |
||
| 471 | */ |
||
| 472 | public function iChangeThePasswordOfUserTo(CustomerInterface $customer, $newPassword) |
||
| 478 | |||
| 479 | /** |
||
| 480 | * @Then this customer should be subscribed to the newsletter |
||
| 481 | */ |
||
| 482 | public function thisCustomerShouldBeSubscribedToTheNewsletter() |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @Then the province in the default address should be :provinceName |
||
| 489 | */ |
||
| 490 | public function theProvinceInTheDefaultAddressShouldBe($provinceName) |
||
| 494 | |||
| 495 | /** |
||
| 496 | * @Then this customer should have :groupName as their group |
||
| 497 | */ |
||
| 498 | public function thisCustomerShouldHaveAsTheirGroup($groupName) |
||
| 505 | |||
| 506 | /** |
||
| 507 | * @Then I should see that this customer has verified the email |
||
| 508 | */ |
||
| 509 | public function iShouldSeeThatThisCustomerHasVerifiedTheEmail() |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @Then I should see a single order in the list |
||
| 516 | */ |
||
| 517 | public function iShouldSeeASingleOrderInTheList() |
||
| 521 | |||
| 522 | /** |
||
| 523 | * @Then I should see the order with number :orderNumber in the list |
||
| 524 | */ |
||
| 525 | public function iShouldSeeASingleOrderFromCustomer($orderNumber) |
||
| 529 | |||
| 530 | /** |
||
| 531 | * @Then I should not see the order with number :orderNumber in the list |
||
| 532 | */ |
||
| 533 | public function iShouldNotSeeASingleOrderFromCustomer($orderNumber) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @When I do not specify any information |
||
| 540 | */ |
||
| 541 | public function iDoNotSpecifyAnyInformation() |
||
| 545 | |||
| 546 | /** |
||
| 547 | * @Then I should not be able to specify their password |
||
| 548 | */ |
||
| 549 | public function iShouldNotBeAbleToSpecifyItPassword() |
||
| 553 | |||
| 554 | /** |
||
| 555 | * @Then I should still be on the customer creation page |
||
| 556 | */ |
||
| 557 | public function iShouldBeOnTheCustomerCreationPage() |
||
| 561 | |||
| 562 | /** |
||
| 563 | * @Then I should be able to select create account option |
||
| 564 | */ |
||
| 565 | public function iShouldBeAbleToSelectCreateAccountOption() |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @Then I should be able to specify their password |
||
| 572 | */ |
||
| 573 | public function iShouldBeAbleToSpecifyItPassword() |
||
| 577 | |||
| 578 | /** |
||
| 579 | * @Then I should not be able to select create account option |
||
| 580 | */ |
||
| 581 | public function iShouldNotBeAbleToSelectCreateAccountOption() |
||
| 585 | |||
| 586 | /** |
||
| 587 | * @When I do not choose create account option |
||
| 588 | */ |
||
| 589 | public function iDoNotChooseCreateAccountOption() |
||
| 593 | |||
| 594 | /** |
||
| 595 | * @Then I should not see create account option |
||
| 596 | */ |
||
| 597 | public function iShouldNotSeeCreateAccountOption() |
||
| 601 | |||
| 602 | /** |
||
| 603 | * @Then /^I should be notified that the password must be at least (\d+) characters long$/ |
||
| 604 | */ |
||
| 605 | public function iShouldBeNotifiedThatThePasswordMustBeAtLeastCharactersLong($amountOfCharacters) |
||
| 612 | |||
| 613 | /** |
||
| 614 | * @Then I should see the customer has not placed any orders yet |
||
| 615 | */ |
||
| 616 | public function iShouldSeeTheCustomerHasNotYetPlacedAnyOrders() |
||
| 620 | |||
| 621 | /** |
||
| 622 | * @Then /^I should see that they have placed (\d+) orders? in the "([^"]+)" channel$/ |
||
| 623 | */ |
||
| 624 | public function iShouldSeeThatTheyHavePlacedOrdersInTheChannel($ordersCount, $channelName) |
||
| 628 | |||
| 629 | /** |
||
| 630 | * @Then /^I should see that the overall total value of all their orders in the "([^"]+)" channel is "([^"]+)"$/ |
||
| 631 | */ |
||
| 632 | public function iShouldSeeThatTheOverallTotalValueOfAllTheirOrdersInTheChannelIs($channelName, $ordersValue) |
||
| 636 | |||
| 637 | /** |
||
| 638 | * @Then /^I should see that the average total value of their order in the "([^"]+)" channel is "([^"]+)"$/ |
||
| 639 | */ |
||
| 640 | public function iShouldSeeThatTheAverageTotalValueOfTheirOrderInTheChannelIs($channelName, $ordersValue) |
||
| 644 | } |
||
| 645 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.