Complex classes like ManagingPaymentMethodsContext 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 ManagingPaymentMethodsContext, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | final class ManagingPaymentMethodsContext implements Context |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * @var CreatePageInterface |
||
| 32 | */ |
||
| 33 | private $createPage; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var IndexPageInterface |
||
| 37 | */ |
||
| 38 | private $indexPage; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var UpdatePageInterface |
||
| 42 | */ |
||
| 43 | private $updatePage; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var CurrentPageResolverInterface |
||
| 47 | */ |
||
| 48 | private $currentPageResolver; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var NotificationCheckerInterface |
||
| 52 | */ |
||
| 53 | private $notificationChecker; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var array |
||
| 57 | */ |
||
| 58 | private $gatewayFactories; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param CreatePageInterface $createPage |
||
| 62 | * @param IndexPageInterface $indexPage |
||
| 63 | * @param UpdatePageInterface $updatePage |
||
| 64 | * @param CurrentPageResolverInterface $currentPageResolver |
||
| 65 | * @param NotificationCheckerInterface $notificationChecker |
||
| 66 | * @param array $gatewayFactories |
||
| 67 | */ |
||
| 68 | public function __construct( |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @Given I want to modify the :paymentMethod payment method |
||
| 86 | */ |
||
| 87 | public function iWantToModifyAPaymentMethod(PaymentMethodInterface $paymentMethod) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @When I name it :name in :language |
||
| 94 | * @When I rename it to :name in :language |
||
| 95 | * @When I remove its name from :language translation |
||
| 96 | */ |
||
| 97 | public function iNameItIn($name = null, $language) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @When I do not name it |
||
| 106 | */ |
||
| 107 | public function iDoNotNameIt() |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @When I enable it |
||
| 114 | */ |
||
| 115 | public function iEnableIt() |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @When I disable it |
||
| 122 | */ |
||
| 123 | public function iDisableIt() |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @When I save my changes |
||
| 130 | * @When I try to save my changes |
||
| 131 | */ |
||
| 132 | public function iSaveMyChanges() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @When I delete the :paymentMethod payment method |
||
| 139 | * @When I try to delete the :paymentMethod payment method |
||
| 140 | */ |
||
| 141 | public function iDeletePaymentMethod(PaymentMethodInterface $paymentMethod) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @Then I should be notified that it is in use |
||
| 149 | */ |
||
| 150 | public function iShouldBeNotifiedThatItIsInUse() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @When I choose :gatewayName gateway |
||
| 157 | */ |
||
| 158 | public function iChooseGateway($gatewayName) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @Then this payment method :element should be :value |
||
| 167 | */ |
||
| 168 | public function thisPaymentMethodElementShouldBe($element, $value) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @When I want to create a new offline payment method |
||
| 175 | * @When I want to create a new payment method with :factory gateway factory |
||
| 176 | */ |
||
| 177 | public function iWantToCreateANewPaymentMethod($factory = 'Offline') |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @When I specify its code as :code |
||
| 184 | * @When I do not specify its code |
||
| 185 | */ |
||
| 186 | public function iSpecifyItsCodeAs($code = null) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @When I describe it as :description in :language |
||
| 193 | */ |
||
| 194 | public function iDescribeItAsIn($description, $language) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @When make it available in channel :channel |
||
| 201 | */ |
||
| 202 | public function iMakeItAvailableInChannel($channel) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @Given I set its instruction as :instructions in :language |
||
| 209 | */ |
||
| 210 | public function iSetItsInstructionAsIn($instructions, $language) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @When I add it |
||
| 217 | * @When I try to add it |
||
| 218 | */ |
||
| 219 | public function iAddIt() |
||
| 223 | |||
| 224 | /** |
||
| 225 | * @Then the payment method :paymentMethodName should appear in the registry |
||
| 226 | * @Then the payment method :paymentMethodName should be in the registry |
||
| 227 | */ |
||
| 228 | public function thePaymentMethodShouldAppearInTheRegistry($paymentMethodName) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @Given /^(this payment method) should still be in the registry$/ |
||
| 237 | */ |
||
| 238 | public function thisPaymentMethodShouldStillBeInTheRegistry(PaymentMethodInterface $paymentMethod) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @Given I am browsing payment methods |
||
| 245 | * @When I browse payment methods |
||
| 246 | */ |
||
| 247 | public function iBrowsePaymentMethods() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @Then the first payment method on the list should have :field :value |
||
| 254 | */ |
||
| 255 | public function theFirstPaymentMethodOnTheListShouldHave($field, $value) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @Then the last payment method on the list should have :field :value |
||
| 262 | */ |
||
| 263 | public function theLastPaymentMethodOnTheListShouldHave($field, $value) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @When I switch the way payment methods are sorted by :field |
||
| 272 | * @When I start sorting payment methods by :field |
||
| 273 | * @Given the payment methods are already sorted by :field |
||
| 274 | */ |
||
| 275 | public function iSortPaymentMethodsBy($field) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @Then I should see :amount payment methods in the list |
||
| 282 | */ |
||
| 283 | public function iShouldSeePaymentMethodsInTheList($amount) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @Then I should be notified that :element is required |
||
| 290 | */ |
||
| 291 | public function iShouldBeNotifiedThatIsRequired($element) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @Then I should be notified that I have to specify paypal :element |
||
| 298 | */ |
||
| 299 | public function iShouldBeNotifiedThatIHaveToSpecifyPaypal($element) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @Then I should be notified that gateway name should contain only letters and underscores |
||
| 309 | */ |
||
| 310 | public function iShouldBeNotifiedThatGatewayNameShouldContainOnlyLettersAndUnderscores() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @Then the payment method with :element :value should not be added |
||
| 320 | */ |
||
| 321 | public function thePaymentMethodWithElementValueShouldNotBeAdded($element, $value) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @Then /^(this payment method) should still be named "([^"]+)"$/ |
||
| 330 | */ |
||
| 331 | public function thisShippingMethodNameShouldBe(PaymentMethodInterface $paymentMethod, $paymentMethodName) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @param string $element |
||
| 343 | * @param string $expectedMessage |
||
| 344 | */ |
||
| 345 | private function assertFieldValidationMessage($element, $expectedMessage) |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @Then the code field should be disabled |
||
| 355 | */ |
||
| 356 | public function theCodeFieldShouldBeDisabled() |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @Then the factory name field should be disabled |
||
| 363 | */ |
||
| 364 | public function theFactoryNameFieldShouldBeDisabled() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @Then this payment method should be enabled |
||
| 371 | */ |
||
| 372 | public function thisPaymentMethodShouldBeEnabled() |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @Then this payment method should be disabled |
||
| 379 | */ |
||
| 380 | public function thisPaymentMethodShouldBeDisabled() |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @Given the payment method :paymentMethod should have instructions :instructions in :language |
||
| 387 | */ |
||
| 388 | public function thePaymentMethodShouldHaveInstructionsIn( |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @Then the payment method :paymentMethod should be available in channel :channelName |
||
| 400 | */ |
||
| 401 | public function thePaymentMethodShouldBeAvailableInChannel( |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @Then /^(this payment method) should no longer exist in the registry$/ |
||
| 412 | */ |
||
| 413 | public function thisPaymentMethodShouldNoLongerExistInTheRegistry(PaymentMethodInterface $paymentMethod) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @Then I should be notified that payment method with this code already exists |
||
| 423 | */ |
||
| 424 | public function iShouldBeNotifiedThatPaymentMethodWithThisCodeAlreadyExists() |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @Then there should still be only one payment method with :element :code |
||
| 431 | */ |
||
| 432 | public function thereShouldStillBeOnlyOnePaymentMethodWith($element, $code) |
||
| 438 | |||
| 439 | /** |
||
| 440 | * @When I configure it with test paypal credentials |
||
| 441 | */ |
||
| 442 | public function iConfigureItWithTestPaypalCredentials() |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @When I configure it for username :username with :signature signature |
||
| 454 | */ |
||
| 455 | public function iConfigureItForUsernameWithSignature($username, $signature) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @When I do not specify configuration password |
||
| 466 | */ |
||
| 467 | public function iDoNotSpecifyConfigurationPassword() |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @When I configure it with test stripe gateway data |
||
| 474 | */ |
||
| 475 | public function iConfigureItWithTestStripeGatewayData() |
||
| 480 | } |
||
| 481 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.