Complex classes like PaymentRequest 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 PaymentRequest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class PaymentRequest extends Payload implements PaymentRequestInterface |
||
13 | { |
||
14 | const ACCOUNT_OFFER_REQUIRED = 'required'; |
||
15 | const ACCOUNT_OFFER_DISABLED = 'disabled'; |
||
16 | |||
17 | const PAYMENT_SOURCE_ECOMMERCE = 'eCommerce'; |
||
18 | const PAYMENT_SOURCE_MOBI = 'mobi'; |
||
19 | const PAYMENT_SOURCE_MOTO = 'moto'; |
||
20 | const PAYMENT_SOURCE_MAIL_ORDER = 'mail_order'; |
||
21 | const PAYMENT_SOURCE_TELEPHONE_ORDER = 'telephone_order'; |
||
22 | |||
23 | const SHIPPING_METHOD_LOW_COST = 'LowCost'; |
||
24 | const SHIPPING_METHOD_DESIGNATED_BY_CUSTOMER = 'DesignatedByCustomer'; |
||
25 | const SHIPPING_METHOD_INTERNATIONAL = 'International'; |
||
26 | const SHIPPING_METHOD_MILITARY = 'Military'; |
||
27 | const SHIPPING_METHOD_NEXT_DAY = 'NextDay'; |
||
28 | const SHIPPING_METHOD_OTHER = 'Other'; |
||
29 | const SHIPPING_METHOD_STORE_PICKUP = 'StorePickup'; |
||
30 | const SHIPPING_METHOD_TWO_DAY_SERVICE = 'TwoDayService'; |
||
31 | const SHIPPING_METHOD_THREE_DAY_SERVICE = 'ThreeDayService'; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $terminal; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $shopOrderId; |
||
42 | |||
43 | /** |
||
44 | * @var float |
||
45 | */ |
||
46 | private $amount; |
||
47 | |||
48 | /** |
||
49 | * Currency in ISO-4217 format |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $currency; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | private $language; |
||
59 | |||
60 | /** |
||
61 | * @var array |
||
62 | */ |
||
63 | private $transactionInfo; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | */ |
||
68 | private $type; |
||
69 | |||
70 | /** |
||
71 | * @var string |
||
72 | */ |
||
73 | private $ccToken; |
||
74 | |||
75 | /** |
||
76 | * @var string |
||
77 | */ |
||
78 | private $saleReconciliationIdentifier; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | */ |
||
83 | private $saleInvoiceNumber; |
||
84 | |||
85 | /** |
||
86 | * @var float |
||
87 | */ |
||
88 | private $salesTax; |
||
89 | |||
90 | /** |
||
91 | * @var array |
||
92 | */ |
||
93 | private $cookieParts; |
||
94 | |||
95 | /** |
||
96 | * @var string |
||
97 | */ |
||
98 | private $paymentSource; |
||
99 | |||
100 | /** |
||
101 | * @var string |
||
102 | */ |
||
103 | private $fraudService; |
||
104 | |||
105 | /** |
||
106 | * @var string |
||
107 | */ |
||
108 | private $shippingMethod; |
||
109 | |||
110 | /** |
||
111 | * @var string |
||
112 | */ |
||
113 | private $customerCreatedDate; |
||
114 | |||
115 | /** |
||
116 | * @var string |
||
117 | */ |
||
118 | private $organisationNumber; |
||
119 | |||
120 | /** |
||
121 | * @var string |
||
122 | */ |
||
123 | private $accountOffer; |
||
124 | |||
125 | /** |
||
126 | * @var OrderLineInterface[] |
||
127 | */ |
||
128 | private $orderLines; |
||
129 | |||
130 | /** |
||
131 | * @var CustomerInfoInterface |
||
132 | */ |
||
133 | private $customerInfo; |
||
134 | |||
135 | /** |
||
136 | * @var ConfigInterface |
||
137 | */ |
||
138 | private $config; |
||
139 | |||
140 | 6 | public function __construct(string $terminal, string $shopOrderId, float $amount, string $currency) |
|
149 | |||
150 | /** |
||
151 | * @return array |
||
152 | 6 | */ |
|
153 | public function getPayload() : array |
||
202 | |||
203 | /** |
||
204 | 3 | * Takes an array of cookie parts and returns an urlencoded string ready to send |
|
205 | * |
||
206 | 3 | * @param array $cookieParts |
|
207 | 3 | * @return string |
|
208 | */ |
||
209 | public static function parseCookieParts(array $cookieParts) { |
||
218 | |||
219 | /** |
||
220 | * @param OrderLineInterface $orderLine |
||
221 | * @return PaymentRequest |
||
222 | 6 | */ |
|
223 | public function addOrderLine(OrderLineInterface $orderLine) : self |
||
228 | |||
229 | /** |
||
230 | * @param string $key |
||
231 | 6 | * @return string |
|
232 | */ |
||
233 | 6 | public function getCookiePart(string $key) : string |
|
237 | |||
238 | /** |
||
239 | * @param string $key |
||
240 | 6 | * @param string $value |
|
241 | * @return PaymentRequest |
||
242 | 6 | */ |
|
243 | 6 | public function setCookiePart(string $key, string $value) : self |
|
248 | |||
249 | 6 | /** |
|
250 | * @return string |
||
251 | 6 | */ |
|
252 | public function getTerminal() : string |
||
256 | |||
257 | /** |
||
258 | 6 | * @param string $terminal |
|
259 | * @return PaymentRequest |
||
260 | 6 | */ |
|
261 | 6 | public function setTerminal(string $terminal) : self |
|
266 | |||
267 | 6 | /** |
|
268 | * @return string |
||
269 | 6 | */ |
|
270 | public function getShopOrderId() : string |
||
274 | |||
275 | /** |
||
276 | 6 | * @param string $shopOrderId |
|
277 | * @return PaymentRequest |
||
278 | 6 | */ |
|
279 | 6 | public function setShopOrderId(string $shopOrderId) : self |
|
284 | |||
285 | 6 | /** |
|
286 | * @return float |
||
287 | 6 | */ |
|
288 | public function getAmount() : float |
||
292 | |||
293 | /** |
||
294 | 3 | * @param float $amount |
|
295 | * @return PaymentRequest |
||
296 | 3 | */ |
|
297 | 3 | public function setAmount(float $amount) : self |
|
302 | |||
303 | 6 | /** |
|
304 | * @return string |
||
305 | 6 | */ |
|
306 | public function getCurrency() : string |
||
310 | |||
311 | /** |
||
312 | 3 | * @param string $currency |
|
313 | * @return PaymentRequest |
||
314 | 3 | */ |
|
315 | 3 | public function setCurrency(string $currency) : self |
|
320 | |||
321 | 6 | /** |
|
322 | * @return string |
||
323 | 6 | */ |
|
324 | public function getLanguage() : ?string |
||
328 | |||
329 | /** |
||
330 | 3 | * @param string $language |
|
331 | * @return PaymentRequest |
||
332 | 3 | */ |
|
333 | 3 | public function setLanguage(string $language) : self |
|
338 | |||
339 | 6 | /** |
|
340 | * @return array |
||
341 | 6 | */ |
|
342 | public function getTransactionInfo() : ?array |
||
346 | |||
347 | /** |
||
348 | 3 | * @param array $transactionInfo |
|
349 | * @return PaymentRequest |
||
350 | 3 | */ |
|
351 | 3 | public function setTransactionInfo(array $transactionInfo) : self |
|
356 | |||
357 | 6 | /** |
|
358 | * @return string |
||
359 | 6 | */ |
|
360 | public function getType() : ?string |
||
364 | |||
365 | /** |
||
366 | 3 | * @param string $type |
|
367 | * @return PaymentRequest |
||
368 | 3 | */ |
|
369 | 3 | public function setType(string $type) : self |
|
374 | |||
375 | 6 | /** |
|
376 | * @return string |
||
377 | 6 | */ |
|
378 | public function getCcToken() : ?string |
||
382 | |||
383 | /** |
||
384 | 3 | * @param string $ccToken |
|
385 | * @return PaymentRequest |
||
386 | 3 | */ |
|
387 | 3 | public function setCcToken(string $ccToken) : self |
|
392 | |||
393 | 6 | /** |
|
394 | * @return string |
||
395 | 6 | */ |
|
396 | public function getSaleReconciliationIdentifier() : ?string |
||
400 | |||
401 | /** |
||
402 | 3 | * @param string $saleReconciliationIdentifier |
|
403 | * @return PaymentRequest |
||
404 | 3 | */ |
|
405 | 3 | public function setSaleReconciliationIdentifier(string $saleReconciliationIdentifier) : self |
|
410 | |||
411 | 6 | /** |
|
412 | * @return string |
||
413 | 6 | */ |
|
414 | public function getSaleInvoiceNumber() : ?string |
||
418 | |||
419 | /** |
||
420 | 3 | * @param string $saleInvoiceNumber |
|
421 | * @return PaymentRequest |
||
422 | 3 | */ |
|
423 | 3 | public function setSaleInvoiceNumber(string $saleInvoiceNumber) : self |
|
428 | |||
429 | 6 | /** |
|
430 | * @return float |
||
431 | 6 | */ |
|
432 | public function getSalesTax() : ?float |
||
436 | |||
437 | /** |
||
438 | 3 | * @param float $salesTax |
|
439 | * @return PaymentRequest |
||
440 | 3 | */ |
|
441 | 3 | public function setSalesTax(float $salesTax) : self |
|
446 | |||
447 | 6 | /** |
|
448 | * @return array |
||
449 | 6 | */ |
|
450 | public function getCookieParts(): array |
||
454 | |||
455 | /** |
||
456 | 3 | * @param array $cookieParts |
|
457 | * @return PaymentRequest |
||
458 | 3 | */ |
|
459 | 3 | public function setCookieParts(array $cookieParts) : self |
|
464 | |||
465 | 6 | /** |
|
466 | * @return string |
||
467 | 6 | */ |
|
468 | public function getPaymentSource() : ?string |
||
472 | |||
473 | /** |
||
474 | 3 | * @param string $paymentSource |
|
475 | * @return PaymentRequest |
||
476 | 3 | */ |
|
477 | 3 | public function setPaymentSource(string $paymentSource) : self |
|
482 | |||
483 | 6 | /** |
|
484 | * @return string |
||
485 | 6 | */ |
|
486 | public function getFraudService() : ?string |
||
490 | |||
491 | /** |
||
492 | 3 | * @param string $fraudService |
|
493 | * @return PaymentRequest |
||
494 | 3 | */ |
|
495 | 3 | public function setFraudService(string $fraudService) : self |
|
500 | |||
501 | 6 | /** |
|
502 | * @return string |
||
503 | 6 | */ |
|
504 | public function getShippingMethod() : ?string |
||
508 | |||
509 | /** |
||
510 | 3 | * @param string $shippingMethod |
|
511 | * @return PaymentRequest |
||
512 | 3 | */ |
|
513 | 3 | public function setShippingMethod(string $shippingMethod) : self |
|
518 | |||
519 | 6 | /** |
|
520 | * @return string |
||
521 | 6 | */ |
|
522 | public function getCustomerCreatedDate() : ?string |
||
526 | |||
527 | /** |
||
528 | 3 | * @param string $customerCreatedDate |
|
529 | * @return PaymentRequest |
||
530 | 3 | */ |
|
531 | 3 | public function setCustomerCreatedDate(string $customerCreatedDate) : self |
|
536 | |||
537 | 6 | /** |
|
538 | * @return string |
||
539 | 6 | */ |
|
540 | public function getOrganisationNumber() : ?string |
||
544 | |||
545 | /** |
||
546 | * @param string $organisationNumber |
||
547 | * @return PaymentRequest |
||
548 | */ |
||
549 | public function setOrganisationNumber(string $organisationNumber) : self |
||
554 | |||
555 | 6 | /** |
|
556 | * @return string |
||
557 | 6 | */ |
|
558 | 3 | public function getAccountOffer() : ?string |
|
562 | |||
563 | /** |
||
564 | * @param string $accountOffer |
||
565 | * @return PaymentRequest |
||
566 | */ |
||
567 | 3 | public function setAccountOffer(string $accountOffer) : self |
|
572 | |||
573 | /** |
||
574 | * @return OrderLineInterface[] |
||
575 | */ |
||
576 | 6 | public function getOrderLines() : ?array |
|
580 | 2 | ||
581 | 6 | /** |
|
582 | * @param OrderLineInterface[] $orderLines |
||
583 | * @return PaymentRequest |
||
584 | */ |
||
585 | public function setOrderLines(array $orderLines) : self |
||
590 | 3 | ||
591 | 3 | /** |
|
592 | * @return CustomerInfoInterface |
||
593 | */ |
||
594 | public function getCustomerInfo() : CustomerInfoInterface |
||
601 | |||
602 | /** |
||
603 | * @param CustomerInfoInterface $customerInfo |
||
604 | * @return PaymentRequest |
||
605 | */ |
||
606 | public function setCustomerInfo(CustomerInfoInterface $customerInfo) : self |
||
611 | |||
612 | /** |
||
613 | * @return ConfigInterface |
||
614 | */ |
||
615 | public function getConfig() : ConfigInterface |
||
622 | |||
623 | /** |
||
624 | * @param ConfigInterface $config |
||
625 | * @return PaymentRequest |
||
626 | */ |
||
627 | public function setConfig(ConfigInterface $config) : self |
||
632 | } |
||
633 |