Total Complexity | 42 |
Total Lines | 620 |
Duplicated Lines | 0 % |
Changes | 16 | ||
Bugs | 1 | Features | 0 |
Complex classes like CrefoPayConfig 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.
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 CrefoPayConfig, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class CrefoPayConfig extends AbstractBundleConfig |
||
17 | { |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected const NOTIFICATION_TRANSACTION_STATUS_ACKNOWLEDGE_PENDING = 'ACKNOWLEDGEPENDING'; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected const NOTIFICATION_TRANSACTION_STATUS_FRAUD_PENDING = 'FRAUDPENDING'; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected const NOTIFICATION_TRANSACTION_STATUS_FRAUD_CANCELLED = 'FRAUDCANCELLED'; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected const NOTIFICATION_TRANSACTION_STATUS_CIA_PENDING = 'CIAPENDING'; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected const NOTIFICATION_TRANSACTION_STATUS_MERCHANT_PENDING = 'MERCHANTPENDING'; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected const NOTIFICATION_TRANSACTION_STATUS_CANCELLED = 'CANCELLED'; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | protected const NOTIFICATION_TRANSACTION_STATUS_EXPIRED = 'EXPIRED'; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | protected const NOTIFICATION_TRANSACTION_STATUS_IN_PROGRESS = 'INPROGRESS'; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | protected const NOTIFICATION_TRANSACTION_STATUS_DONE = 'DONE'; |
||
62 | |||
63 | /** |
||
64 | * @var string |
||
65 | */ |
||
66 | protected const NOTIFICATION_ORDER_STATUS_PAY_PENDING = 'PAYPENDING'; |
||
67 | |||
68 | /** |
||
69 | * @var string |
||
70 | */ |
||
71 | protected const NOTIFICATION_ORDER_STATUS_PAID = 'PAID'; |
||
72 | |||
73 | /** |
||
74 | * @var string |
||
75 | */ |
||
76 | protected const NOTIFICATION_ORDER_STATUS_CLEARED = 'CLEARED'; |
||
77 | |||
78 | /** |
||
79 | * @var string |
||
80 | */ |
||
81 | protected const NOTIFICATION_ORDER_STATUS_PAYMENT_FAILED = 'PAYMENTFAILED'; |
||
82 | |||
83 | /** |
||
84 | * @var string |
||
85 | */ |
||
86 | protected const NOTIFICATION_ORDER_STATUS_CHARGE_BACK = 'CHARGEBACK'; |
||
87 | |||
88 | /** |
||
89 | * @var string |
||
90 | */ |
||
91 | protected const NOTIFICATION_ORDER_STATUS_IN_DUNNING = 'INDUNNING'; |
||
92 | |||
93 | /** |
||
94 | * @var string |
||
95 | */ |
||
96 | protected const NOTIFICATION_ORDER_STATUS_IN_COLLECTION = 'IN_COLLECTION'; |
||
97 | |||
98 | /** |
||
99 | * @var string |
||
100 | */ |
||
101 | protected const OMS_STATUS_NEW = 'new'; |
||
102 | |||
103 | /** |
||
104 | * @var string |
||
105 | */ |
||
106 | protected const OMS_STATUS_RESERVED = 'reserved'; |
||
107 | |||
108 | /** |
||
109 | * @var string |
||
110 | */ |
||
111 | protected const OMS_STATUS_AUTHORIZED = 'authorized'; |
||
112 | |||
113 | /** |
||
114 | * @var string |
||
115 | */ |
||
116 | protected const OMS_STATUS_WAITING_FOR_CAPTURE = 'waiting for capture'; |
||
117 | |||
118 | /** |
||
119 | * @var string |
||
120 | */ |
||
121 | protected const OMS_STATUS_WAITING_FOR_CASH = 'waiting for cash'; |
||
122 | |||
123 | /** |
||
124 | * @var string |
||
125 | */ |
||
126 | protected const OMS_STATUS_CAPTURE_PENDING = 'capture pending'; |
||
127 | |||
128 | /** |
||
129 | * @var string |
||
130 | */ |
||
131 | protected const OMS_STATUS_CAPTURED = 'captured'; |
||
132 | |||
133 | /** |
||
134 | * @var string |
||
135 | */ |
||
136 | protected const OMS_STATUS_CANCELLATION_PENDING = 'cancellation pending'; |
||
137 | |||
138 | /** |
||
139 | * @var string |
||
140 | */ |
||
141 | protected const OMS_STATUS_CANCELED = 'canceled'; |
||
142 | |||
143 | /** |
||
144 | * @var string |
||
145 | */ |
||
146 | protected const OMS_STATUS_REFUNDED = 'refunded'; |
||
147 | |||
148 | /** |
||
149 | * @var string |
||
150 | */ |
||
151 | protected const OMS_STATUS_MONEY_REDUCED = 'money reduced'; |
||
152 | |||
153 | /** |
||
154 | * @var string |
||
155 | */ |
||
156 | protected const OMS_STATUS_EXPIRED = 'expired'; |
||
157 | |||
158 | /** |
||
159 | * @var string |
||
160 | */ |
||
161 | protected const OMS_STATUS_DONE = 'done'; |
||
162 | |||
163 | /** |
||
164 | * @var string |
||
165 | */ |
||
166 | protected const OMS_EVENT_CANCEL = 'cancel'; |
||
167 | |||
168 | /** |
||
169 | * @var string |
||
170 | */ |
||
171 | protected const OMS_EVENT_NO_CANCELLATION = 'no cancellation'; |
||
172 | |||
173 | /** |
||
174 | * @var string |
||
175 | */ |
||
176 | protected const OMS_EVENT_FINISH = 'finish'; |
||
177 | |||
178 | /** |
||
179 | * @var int |
||
180 | */ |
||
181 | protected const CREFO_PAY_API_CAPTURE_ID_LENGTH = 30; |
||
182 | |||
183 | /** |
||
184 | * @var string |
||
185 | */ |
||
186 | protected const CREFO_PAY_AUTOMATIC_OMS_TRIGGER = 'CREFO_PAY_AUTOMATIC_OMS_TRIGGER'; |
||
187 | |||
188 | /** |
||
189 | * @var array<string, string> |
||
190 | */ |
||
191 | protected const CREFO_PAY_SALUTATION_MAP = [ |
||
192 | 'Mr' => 'M', |
||
193 | 'Ms' => 'F', |
||
194 | 'Mrs' => 'F', |
||
195 | 'Dr' => 'M', |
||
196 | ]; |
||
197 | |||
198 | /** |
||
199 | * @api |
||
200 | * |
||
201 | * @return int |
||
202 | */ |
||
203 | public function getMerchantId(): int |
||
204 | { |
||
205 | return $this->get(CrefoPayConstants::MERCHANT_ID); |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * @api |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | public function getStoreId(): string |
||
214 | { |
||
215 | return $this->get(CrefoPayConstants::STORE_ID); |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @api |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | public function getRefundDescription(): string |
||
224 | { |
||
225 | return $this->get(CrefoPayConstants::REFUND_DESCRIPTION); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @api |
||
230 | * |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getProviderName(): string |
||
234 | { |
||
235 | return $this->getSharedConfig()->getProviderName(); |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * @api |
||
240 | * |
||
241 | * @return int |
||
242 | */ |
||
243 | public function getUserRiskClass(): int |
||
244 | { |
||
245 | return $this->getSharedConfig()->getUserRiskClass(); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @api |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | public function getProductTypeDefault(): string |
||
254 | { |
||
255 | return $this->getSharedConfig()->getProductTypeDefault(); |
||
256 | } |
||
257 | |||
258 | /** |
||
259 | * @api |
||
260 | * |
||
261 | * @return string |
||
262 | */ |
||
263 | public function getProductTypeShippingCosts(): string |
||
264 | { |
||
265 | return $this->getSharedConfig()->getProductTypeShippingCosts(); |
||
266 | } |
||
267 | |||
268 | /** |
||
269 | * @api |
||
270 | * |
||
271 | * @return int |
||
272 | */ |
||
273 | public function getProductRiskClass(): int |
||
274 | { |
||
275 | return $this->getSharedConfig()->getProductRiskClass(); |
||
276 | } |
||
277 | |||
278 | /** |
||
279 | * @api |
||
280 | * |
||
281 | * @return array<string> |
||
282 | */ |
||
283 | public function getInternalToExternalPaymentMethodNamesMapping(): array |
||
284 | { |
||
285 | return [ |
||
286 | $this->getSharedConfig()->getCrefoPayPaymentMethodBill() => $this->getSharedConfig()->getExternalPaymentMethodBill(), |
||
287 | $this->getSharedConfig()->getCrefoPayPaymentMethodCashOnDelivery() => $this->getSharedConfig()->getExternalPaymentMethodCashOnDelivery(), |
||
288 | $this->getSharedConfig()->getCrefoPayPaymentMethodDirectDebit() => $this->getSharedConfig()->getExternalPaymentMethodDirectDebit(), |
||
289 | $this->getSharedConfig()->getCrefoPayPaymentMethodPayPal() => $this->getSharedConfig()->getExternalPaymentMethodPayPal(), |
||
290 | $this->getSharedConfig()->getCrefoPayPaymentMethodPrepaid() => $this->getSharedConfig()->getExternalPaymentMethodPrepaid(), |
||
291 | $this->getSharedConfig()->getCrefoPayPaymentMethodSofort() => $this->getSharedConfig()->getExternalPaymentMethodSofort(), |
||
292 | $this->getSharedConfig()->getCrefoPayPaymentMethodCreditCard() => $this->getSharedConfig()->getExternalPaymentMethodCreditCard(), |
||
293 | $this->getSharedConfig()->getCrefoPayPaymentMethodCreditCard3D() => $this->getSharedConfig()->getExternalPaymentMethodCreditCard3D(), |
||
294 | ]; |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * @api |
||
299 | * |
||
300 | * @return string |
||
301 | */ |
||
302 | public function getNotificationTransactionStatusAcknowledgePending(): string |
||
303 | { |
||
304 | return static::NOTIFICATION_TRANSACTION_STATUS_ACKNOWLEDGE_PENDING; |
||
305 | } |
||
306 | |||
307 | /** |
||
308 | * @api |
||
309 | * |
||
310 | * @return string |
||
311 | */ |
||
312 | public function getNotificationTransactionStatusMerchantPending(): string |
||
313 | { |
||
314 | return static::NOTIFICATION_TRANSACTION_STATUS_MERCHANT_PENDING; |
||
315 | } |
||
316 | |||
317 | /** |
||
318 | * @api |
||
319 | * |
||
320 | * @return string |
||
321 | */ |
||
322 | public function getNotificationTransactionStatusCiaPending(): string |
||
323 | { |
||
324 | return static::NOTIFICATION_TRANSACTION_STATUS_CIA_PENDING; |
||
325 | } |
||
326 | |||
327 | /** |
||
328 | * @api |
||
329 | * |
||
330 | * @return string |
||
331 | */ |
||
332 | public function getNotificationTransactionStatusCancelled(): string |
||
333 | { |
||
334 | return static::NOTIFICATION_TRANSACTION_STATUS_CANCELLED; |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * @api |
||
339 | * |
||
340 | * @return string |
||
341 | */ |
||
342 | public function getNotificationTransactionStatusExpired(): string |
||
343 | { |
||
344 | return static::NOTIFICATION_TRANSACTION_STATUS_EXPIRED; |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * @api |
||
349 | * |
||
350 | * @return string |
||
351 | */ |
||
352 | public function getNotificationTransactionStatusDone(): string |
||
353 | { |
||
354 | return static::NOTIFICATION_TRANSACTION_STATUS_DONE; |
||
355 | } |
||
356 | |||
357 | /** |
||
358 | * @api |
||
359 | * |
||
360 | * @return string |
||
361 | */ |
||
362 | public function getNotificationOrderStatusPayPending(): string |
||
363 | { |
||
364 | return static::NOTIFICATION_ORDER_STATUS_PAY_PENDING; |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * @api |
||
369 | * |
||
370 | * @return string |
||
371 | */ |
||
372 | public function getNotificationOrderStatusPaid(): string |
||
373 | { |
||
374 | return static::NOTIFICATION_ORDER_STATUS_PAID; |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * @api |
||
379 | * |
||
380 | * @return string |
||
381 | */ |
||
382 | public function getNotificationOrderStatusChargeBack(): string |
||
383 | { |
||
384 | return static::NOTIFICATION_ORDER_STATUS_CHARGE_BACK; |
||
385 | } |
||
386 | |||
387 | /** |
||
388 | * @api |
||
389 | * |
||
390 | * @return string |
||
391 | */ |
||
392 | public function getOmsStatusNew(): string |
||
393 | { |
||
394 | return static::OMS_STATUS_NEW; |
||
395 | } |
||
396 | |||
397 | /** |
||
398 | * @api |
||
399 | * |
||
400 | * @return string |
||
401 | */ |
||
402 | public function getOmsStatusReserved(): string |
||
403 | { |
||
404 | return static::OMS_STATUS_RESERVED; |
||
405 | } |
||
406 | |||
407 | /** |
||
408 | * @api |
||
409 | * |
||
410 | * @return string |
||
411 | */ |
||
412 | public function getOmsStatusAuthorized(): string |
||
413 | { |
||
414 | return static::OMS_STATUS_AUTHORIZED; |
||
415 | } |
||
416 | |||
417 | /** |
||
418 | * @api |
||
419 | * |
||
420 | * @return string |
||
421 | */ |
||
422 | public function getOmsStatusWaitingForCapture(): string |
||
423 | { |
||
424 | return static::OMS_STATUS_WAITING_FOR_CAPTURE; |
||
425 | } |
||
426 | |||
427 | /** |
||
428 | * @api |
||
429 | * |
||
430 | * @return string |
||
431 | */ |
||
432 | public function getOmsStatusWaitingForCash(): string |
||
433 | { |
||
434 | return static::OMS_STATUS_WAITING_FOR_CASH; |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * @api |
||
439 | * |
||
440 | * @return string |
||
441 | */ |
||
442 | public function getOmsStatusCapturePending(): string |
||
443 | { |
||
444 | return static::OMS_STATUS_CAPTURE_PENDING; |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * @api |
||
449 | * |
||
450 | * @return string |
||
451 | */ |
||
452 | public function getOmsStatusCaptured(): string |
||
453 | { |
||
454 | return static::OMS_STATUS_CAPTURED; |
||
455 | } |
||
456 | |||
457 | /** |
||
458 | * @api |
||
459 | * |
||
460 | * @return string |
||
461 | */ |
||
462 | public function getOmsStatusCancellationPending(): string |
||
463 | { |
||
464 | return static::OMS_STATUS_CANCELLATION_PENDING; |
||
465 | } |
||
466 | |||
467 | /** |
||
468 | * @api |
||
469 | * |
||
470 | * @return string |
||
471 | */ |
||
472 | public function getOmsStatusCanceled(): string |
||
473 | { |
||
474 | return static::OMS_STATUS_CANCELED; |
||
475 | } |
||
476 | |||
477 | /** |
||
478 | * @api |
||
479 | * |
||
480 | * @return string |
||
481 | */ |
||
482 | public function getOmsStatusRefunded(): string |
||
485 | } |
||
486 | |||
487 | /** |
||
488 | * @api |
||
489 | * |
||
490 | * @return string |
||
491 | */ |
||
492 | public function getOmsStatusMoneyReduced(): string |
||
493 | { |
||
494 | return static::OMS_STATUS_MONEY_REDUCED; |
||
495 | } |
||
496 | |||
497 | /** |
||
498 | * @api |
||
499 | * |
||
500 | * @return string |
||
501 | */ |
||
502 | public function getOmsStatusExpired(): string |
||
503 | { |
||
504 | return static::OMS_STATUS_EXPIRED; |
||
505 | } |
||
506 | |||
507 | /** |
||
508 | * @api |
||
509 | * |
||
510 | * @return string |
||
511 | */ |
||
512 | public function getOmsStatusDone(): string |
||
513 | { |
||
514 | return static::OMS_STATUS_DONE; |
||
515 | } |
||
516 | |||
517 | /** |
||
518 | * @api |
||
519 | * |
||
520 | * @return string |
||
521 | */ |
||
522 | public function getOmsEventCancel(): string |
||
523 | { |
||
524 | return static::OMS_EVENT_CANCEL; |
||
525 | } |
||
526 | |||
527 | /** |
||
528 | * @api |
||
529 | * |
||
530 | * @return string |
||
531 | */ |
||
532 | public function getOmsEventNoCancellation(): string |
||
533 | { |
||
534 | return static::OMS_EVENT_NO_CANCELLATION; |
||
535 | } |
||
536 | |||
537 | /** |
||
538 | * @api |
||
539 | * |
||
540 | * @return string |
||
541 | */ |
||
542 | public function getOmsEventFinish(): string |
||
543 | { |
||
544 | return static::OMS_EVENT_FINISH; |
||
545 | } |
||
546 | |||
547 | /** |
||
548 | * @api |
||
549 | * |
||
550 | * @return array<string> |
||
551 | */ |
||
552 | public function getNotificationTransactionToOmsStatusMapping(): array |
||
561 | ]; |
||
562 | } |
||
563 | |||
564 | /** |
||
565 | * @api |
||
566 | * |
||
567 | * @return array<string> |
||
568 | */ |
||
569 | public function getNotificationOrderToOmsStatusMapping(): array |
||
570 | { |
||
571 | return [ |
||
572 | $this->getNotificationOrderStatusPayPending() => $this->getOmsStatusCapturePending(), |
||
573 | $this->getNotificationOrderStatusPaid() => $this->getOmsStatusCaptured(), |
||
574 | $this->getNotificationOrderStatusChargeBack() => $this->getOmsStatusRefunded(), |
||
575 | ]; |
||
576 | } |
||
577 | |||
578 | /** |
||
579 | * @api |
||
580 | * |
||
581 | * @return int |
||
582 | */ |
||
583 | public function getCrefoPayApiCaptureIdLength(): int |
||
584 | { |
||
585 | return static::CREFO_PAY_API_CAPTURE_ID_LENGTH; |
||
586 | } |
||
587 | |||
588 | /** |
||
589 | * @api |
||
590 | * |
||
591 | * @return string |
||
592 | */ |
||
593 | public function getCrefoPayAutomaticOmsTrigger(): string |
||
594 | { |
||
595 | return static::CREFO_PAY_AUTOMATIC_OMS_TRIGGER; |
||
596 | } |
||
597 | |||
598 | /** |
||
599 | * @api |
||
600 | * |
||
601 | * @return bool |
||
602 | */ |
||
603 | public function getIsBusinessToBusiness(): bool |
||
606 | } |
||
607 | |||
608 | /** |
||
609 | * @api |
||
610 | * |
||
611 | * @return bool |
||
612 | */ |
||
613 | public function getCaptureExpensesSeparately(): bool |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * @api |
||
620 | * |
||
621 | * @return bool |
||
622 | */ |
||
623 | public function getRefundExpensesWithLastItem(): bool |
||
624 | { |
||
625 | return $this->get(CrefoPayConstants::REFUND_EXPENSES_WITH_LAST_ITEM); |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * @api |
||
630 | * |
||
631 | * @return array<string, string> |
||
632 | */ |
||
633 | public function getCrefoPaySalutationMap(): array |
||
636 | } |
||
637 | } |
||
638 |