Complex classes like Transaction 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 Transaction, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class Transaction implements HydratableInterface |
||
8 | { |
||
9 | use PaymentNatureServiceTrait; |
||
10 | use PaymentInfosTrait; |
||
11 | use CustomerInfoTrait; |
||
12 | use ReconciliationIdentifiersTrait; |
||
13 | use CreditCardExpiryTrait; |
||
14 | |||
15 | /** |
||
16 | * @var int |
||
17 | */ |
||
18 | private $transactionId; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $paymentId; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $authType; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $cardStatus; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $creditCardToken; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $creditCardMaskedPan; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | private $threeDSecureResult; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | private $liableForChargeback; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | private $CVVCheckResult; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | private $blacklistToken; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | */ |
||
68 | private $shopOrderId; |
||
69 | |||
70 | /** |
||
71 | * @var string |
||
72 | */ |
||
73 | private $shop; |
||
74 | |||
75 | /** |
||
76 | * @var string |
||
77 | */ |
||
78 | private $terminal; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | */ |
||
83 | private $transactionStatus; |
||
84 | |||
85 | /** |
||
86 | * @var string |
||
87 | */ |
||
88 | private $reasonCode; |
||
89 | |||
90 | /** |
||
91 | * @var int |
||
92 | */ |
||
93 | private $merchantCurrency; |
||
94 | |||
95 | /** |
||
96 | * @var string |
||
97 | */ |
||
98 | private $merchantCurrencyAlpha; |
||
99 | |||
100 | /** |
||
101 | * @var int |
||
102 | */ |
||
103 | private $cardHolderCurrency; |
||
104 | |||
105 | /** |
||
106 | * @var string |
||
107 | */ |
||
108 | private $cardHolderCurrencyAlpha; |
||
109 | |||
110 | /** |
||
111 | * @var float |
||
112 | */ |
||
113 | private $reservedAmount; |
||
114 | |||
115 | /** |
||
116 | * @var float |
||
117 | */ |
||
118 | private $capturedAmount; |
||
119 | |||
120 | /** |
||
121 | * @var float |
||
122 | */ |
||
123 | private $refundedAmount; |
||
124 | |||
125 | /** |
||
126 | * @var float |
||
127 | */ |
||
128 | private $creditedAmount; |
||
129 | |||
130 | /** |
||
131 | * @var float |
||
132 | */ |
||
133 | private $recurringDefaultAmount; |
||
134 | |||
135 | /** |
||
136 | * @var float |
||
137 | */ |
||
138 | private $surchargeAmount; |
||
139 | |||
140 | /** |
||
141 | * @var \DateTimeImmutable |
||
142 | */ |
||
143 | private $createdDate; |
||
144 | |||
145 | /** |
||
146 | * @var \DateTimeImmutable |
||
147 | */ |
||
148 | private $updatedDate; |
||
149 | |||
150 | /** |
||
151 | * @var string |
||
152 | */ |
||
153 | private $paymentNature; |
||
154 | |||
155 | /** |
||
156 | * @var string |
||
157 | */ |
||
158 | private $paymentSchemeName; |
||
159 | |||
160 | /** |
||
161 | * @var string |
||
162 | */ |
||
163 | private $addressVerification; |
||
164 | |||
165 | /** |
||
166 | * @var string |
||
167 | */ |
||
168 | private $addressVerificationDescription; |
||
169 | |||
170 | /** |
||
171 | * @var float |
||
172 | */ |
||
173 | private $fraudRiskScore; |
||
174 | |||
175 | /** |
||
176 | * @var string |
||
177 | */ |
||
178 | private $fraudExplanation; |
||
179 | |||
180 | 27 | public function hydrateXml(\SimpleXMLElement $xml) |
|
237 | |||
238 | /** |
||
239 | * @return int |
||
240 | */ |
||
241 | 3 | public function getTransactionId() : ?int |
|
245 | |||
246 | /** |
||
247 | * @return string |
||
248 | */ |
||
249 | 3 | public function getPaymentId() : ?string |
|
253 | |||
254 | /** |
||
255 | * @return string |
||
256 | */ |
||
257 | 6 | public function getAuthType(): ?string |
|
261 | |||
262 | /** |
||
263 | * @return string |
||
264 | */ |
||
265 | 3 | public function getCardStatus() : ?string |
|
269 | |||
270 | /** |
||
271 | * @return string |
||
272 | */ |
||
273 | 3 | public function getCreditCardToken() : ?string |
|
277 | |||
278 | /** |
||
279 | * @return string |
||
280 | */ |
||
281 | 3 | public function getCreditCardMaskedPan() : ?string |
|
285 | |||
286 | /** |
||
287 | * @return string |
||
288 | */ |
||
289 | 3 | public function getThreeDSecureResult() : ?string |
|
293 | |||
294 | /** |
||
295 | * @return string |
||
296 | */ |
||
297 | 3 | public function getLiableForChargeback() : ?string |
|
301 | |||
302 | /** |
||
303 | * @return string |
||
304 | */ |
||
305 | 6 | public function getCVVCheckResult(): ?string |
|
309 | |||
310 | /** |
||
311 | * @return string |
||
312 | */ |
||
313 | 3 | public function getBlacklistToken() : ?string |
|
317 | |||
318 | /** |
||
319 | * @return string |
||
320 | */ |
||
321 | 3 | public function getShopOrderId() : ?string |
|
325 | |||
326 | /** |
||
327 | * @return string |
||
328 | */ |
||
329 | 3 | public function getShop() : ?string |
|
333 | |||
334 | /** |
||
335 | * @return string |
||
336 | */ |
||
337 | 3 | public function getTerminal() : ?string |
|
341 | |||
342 | /** |
||
343 | * @return string |
||
344 | */ |
||
345 | 3 | public function getTransactionStatus() : ?string |
|
349 | |||
350 | /** |
||
351 | * @return string |
||
352 | */ |
||
353 | 3 | public function getReasonCode() : ?string |
|
357 | |||
358 | /** |
||
359 | * @return int |
||
360 | */ |
||
361 | 3 | public function getMerchantCurrency() : ?int |
|
365 | |||
366 | /** |
||
367 | * @return string |
||
368 | */ |
||
369 | 3 | public function getMerchantCurrencyAlpha() : ?string |
|
373 | |||
374 | /** |
||
375 | * @return int |
||
376 | */ |
||
377 | 3 | public function getCardHolderCurrency() : ?int |
|
381 | |||
382 | /** |
||
383 | * @return string |
||
384 | */ |
||
385 | 3 | public function getCardHolderCurrencyAlpha() : ?string |
|
389 | |||
390 | /** |
||
391 | * @return float |
||
392 | */ |
||
393 | 3 | public function getReservedAmount() : ?float |
|
397 | |||
398 | /** |
||
399 | * @return float |
||
400 | */ |
||
401 | 3 | public function getCapturedAmount() : ?float |
|
405 | |||
406 | /** |
||
407 | * @return float |
||
408 | */ |
||
409 | 3 | public function getRefundedAmount() : ?float |
|
413 | |||
414 | /** |
||
415 | * @return float |
||
416 | */ |
||
417 | 6 | public function getCreditedAmount(): ?float |
|
421 | |||
422 | /** |
||
423 | * @return float |
||
424 | */ |
||
425 | 3 | public function getRecurringDefaultAmount() : ?float |
|
429 | |||
430 | /** |
||
431 | * @return float |
||
432 | */ |
||
433 | 6 | public function getSurchargeAmount(): ?float |
|
437 | |||
438 | /** |
||
439 | * @return \DateTimeImmutable |
||
440 | */ |
||
441 | 3 | public function getCreatedDate() : ?\DateTimeImmutable |
|
445 | |||
446 | /** |
||
447 | * @return \DateTimeImmutable |
||
448 | */ |
||
449 | 3 | public function getUpdatedDate() : ?\DateTimeImmutable |
|
453 | |||
454 | /** |
||
455 | * @return string |
||
456 | */ |
||
457 | 3 | public function getPaymentNature() : ?string |
|
461 | |||
462 | /** |
||
463 | * @return float |
||
464 | */ |
||
465 | 3 | public function getFraudRiskScore() : ?float |
|
469 | |||
470 | /** |
||
471 | * @return string |
||
472 | */ |
||
473 | 3 | public function getFraudExplanation() : ?string |
|
477 | } |
||
478 |