Completed
Push — master ( 3ee5ff...5084e8 )
by Joachim
12:38
created

Transaction   B

Complexity

Total Complexity 41

Size/Duplication

Total Lines 466
Duplicated Lines 5.79 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 41
lcom 1
cbo 6
dl 27
loc 466
rs 8.2769
c 0
b 0
f 0

31 Methods

Rating   Name   Duplication   Size   Complexity  
A getTransactionId() 0 4 1
A getPaymentId() 0 4 1
A getCardStatus() 0 4 1
A getCreditCardToken() 0 4 1
A getCreditCardMaskedPan() 0 4 1
A getThreeDSecureResult() 0 4 1
A getLiableForChargeback() 0 4 1
A getBlacklistToken() 0 4 1
A getShopOrderId() 0 4 1
A getShop() 0 4 1
A getTerminal() 0 4 1
A getTransactionStatus() 0 4 1
A getReasonCode() 0 4 1
A getMerchantCurrency() 0 4 1
A getMerchantCurrencyAlpha() 0 4 1
A getCardHolderCurrency() 0 4 1
A getCardHolderCurrencyAlpha() 0 4 1
A getReservedAmount() 0 4 1
A getCapturedAmount() 0 4 1
A getRefundedAmount() 0 4 1
A getRecurringDefaultAmount() 0 4 1
A getCreatedDate() 0 4 1
A getUpdatedDate() 0 4 1
A getPaymentNature() 0 4 1
A getPaymentNatureService() 0 4 1
A getFraudRiskScore() 0 4 1
A getFraudExplanation() 0 4 1
A getPaymentInfos() 0 4 1
A getCustomerInfo() 0 4 1
A getReconciliationIdentifiers() 0 4 1
C init() 27 73 11

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

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
2
namespace Loevgaard\AltaPay\Response\Partial;
3
4
use Loevgaard\AltaPay\Exception\ResponseException;
5
use Loevgaard\AltaPay\Response\Partial\Transaction\CustomerInfo;
6
use Loevgaard\AltaPay\Response\Partial\Transaction\PaymentInfo;
7
use Loevgaard\AltaPay\Response\Partial\Transaction\PaymentNatureService;
8
use Loevgaard\AltaPay\Response\Partial\Transaction\ReconciliationIdentifier;
9
10
class Transaction extends PartialResponse
11
{
12
    /**
13
     * @var int
14
     */
15
    private $transactionId;
16
17
    /**
18
     * @var string
19
     */
20
    private $paymentId;
21
22
    /**
23
     * @var string
24
     */
25
    private $cardStatus;
26
27
    /**
28
     * @var string
29
     */
30
    private $creditCardToken;
31
32
    /**
33
     * @var string
34
     */
35
    private $creditCardMaskedPan;
36
37
    /**
38
     * @var string
39
     */
40
    private $threeDSecureResult;
41
42
    /**
43
     * @var string
44
     */
45
    private $liableForChargeback;
46
47
    /**
48
     * @var string
49
     */
50
    private $blacklistToken;
51
52
    /**
53
     * @var string
54
     */
55
    private $shopOrderId;
56
57
    /**
58
     * @var string
59
     */
60
    private $shop;
61
62
    /**
63
     * @var string
64
     */
65
    private $terminal;
66
67
    /**
68
     * @var string
69
     */
70
    private $transactionStatus;
71
72
    /**
73
     * @var string
74
     */
75
    private $reasonCode;
76
77
    /**
78
     * @var int
79
     */
80
    private $merchantCurrency;
81
82
    /**
83
     * @var string
84
     */
85
    private $merchantCurrencyAlpha;
86
87
    /**
88
     * @var int
89
     */
90
    private $cardHolderCurrency;
91
92
    /**
93
     * @var string
94
     */
95
    private $cardHolderCurrencyAlpha;
96
97
    /**
98
     * @var float
99
     */
100
    private $reservedAmount;
101
102
    /**
103
     * @var float
104
     */
105
    private $capturedAmount;
106
107
    /**
108
     * @var float
109
     */
110
    private $refundedAmount;
111
112
    /**
113
     * @var float
114
     */
115
    private $recurringDefaultAmount;
116
117
    /**
118
     * @var \DateTimeImmutable
119
     */
120
    private $createdDate;
121
122
    /**
123
     * @var \DateTimeImmutable
124
     */
125
    private $updatedDate;
126
127
    /**
128
     * @var string
129
     */
130
    private $paymentNature;
131
132
    /**
133
     * @var PaymentNatureService
134
     */
135
    private $paymentNatureService;
136
137
    /**
138
     * @var float
139
     */
140
    private $fraudRiskScore;
141
142
    /**
143
     * @var string
144
     */
145
    private $fraudExplanation;
146
147
    /**
148
     * @var PaymentInfo[]
149
     */
150
    private $paymentInfos;
151
152
    /**
153
     * @var CustomerInfo
154
     */
155
    private $customerInfo;
156
157
    /**
158
     * @var ReconciliationIdentifier[]
159
     */
160
    private $reconciliationIdentifiers;
161
162
    /**
163
     * @return int
164
     */
165
    public function getTransactionId() : int
166
    {
167
        return $this->transactionId;
168
    }
169
170
    /**
171
     * @return string
172
     */
173
    public function getPaymentId() : string
174
    {
175
        return $this->paymentId;
176
    }
177
178
    /**
179
     * @return string
180
     */
181
    public function getCardStatus() : string
182
    {
183
        return $this->cardStatus;
184
    }
185
186
    /**
187
     * @return string
188
     */
189
    public function getCreditCardToken() : string
190
    {
191
        return $this->creditCardToken;
192
    }
193
194
    /**
195
     * @return string
196
     */
197
    public function getCreditCardMaskedPan() : string
198
    {
199
        return $this->creditCardMaskedPan;
200
    }
201
202
    /**
203
     * @return string
204
     */
205
    public function getThreeDSecureResult() : string
206
    {
207
        return $this->threeDSecureResult;
208
    }
209
210
    /**
211
     * @return string
212
     */
213
    public function getLiableForChargeback() : string
214
    {
215
        return $this->liableForChargeback;
216
    }
217
218
    /**
219
     * @return string
220
     */
221
    public function getBlacklistToken() : string
222
    {
223
        return $this->blacklistToken;
224
    }
225
226
    /**
227
     * @return string
228
     */
229
    public function getShopOrderId() : string
230
    {
231
        return $this->shopOrderId;
232
    }
233
234
    /**
235
     * @return string
236
     */
237
    public function getShop() : string
238
    {
239
        return $this->shop;
240
    }
241
242
    /**
243
     * @return string
244
     */
245
    public function getTerminal() : string
246
    {
247
        return $this->terminal;
248
    }
249
250
    /**
251
     * @return string
252
     */
253
    public function getTransactionStatus() : string
254
    {
255
        return $this->transactionStatus;
256
    }
257
258
    /**
259
     * @return string
260
     */
261
    public function getReasonCode() : string
262
    {
263
        return $this->reasonCode;
264
    }
265
266
    /**
267
     * @return int
268
     */
269
    public function getMerchantCurrency() : int
270
    {
271
        return $this->merchantCurrency;
272
    }
273
274
    /**
275
     * @return string
276
     */
277
    public function getMerchantCurrencyAlpha() : string
278
    {
279
        return $this->merchantCurrencyAlpha;
280
    }
281
282
    /**
283
     * @return int
284
     */
285
    public function getCardHolderCurrency() : int
286
    {
287
        return $this->cardHolderCurrency;
288
    }
289
290
    /**
291
     * @return string
292
     */
293
    public function getCardHolderCurrencyAlpha() : string
294
    {
295
        return $this->cardHolderCurrencyAlpha;
296
    }
297
298
    /**
299
     * @return float
300
     */
301
    public function getReservedAmount() : float
302
    {
303
        return $this->reservedAmount;
304
    }
305
306
    /**
307
     * @return float
308
     */
309
    public function getCapturedAmount() : float
310
    {
311
        return $this->capturedAmount;
312
    }
313
314
    /**
315
     * @return float
316
     */
317
    public function getRefundedAmount() : float
318
    {
319
        return $this->refundedAmount;
320
    }
321
322
    /**
323
     * @return float
324
     */
325
    public function getRecurringDefaultAmount() : float
326
    {
327
        return $this->recurringDefaultAmount;
328
    }
329
330
    /**
331
     * @return \DateTimeImmutable
332
     */
333
    public function getCreatedDate() : \DateTimeImmutable
334
    {
335
        return $this->createdDate;
336
    }
337
338
    /**
339
     * @return \DateTimeImmutable
340
     */
341
    public function getUpdatedDate() : \DateTimeImmutable
342
    {
343
        return $this->updatedDate;
344
    }
345
346
    /**
347
     * @return string
348
     */
349
    public function getPaymentNature() : string
350
    {
351
        return $this->paymentNature;
352
    }
353
354
    /**
355
     * @return PaymentNatureService
356
     */
357
    public function getPaymentNatureService()
358
    {
359
        return $this->paymentNatureService;
360
    }
361
362
    /**
363
     * @return float
364
     */
365
    public function getFraudRiskScore() : float
366
    {
367
        return $this->fraudRiskScore;
368
    }
369
370
    /**
371
     * @return string
372
     */
373
    public function getFraudExplanation() : string
374
    {
375
        return $this->fraudExplanation;
376
    }
377
378
    /**
379
     * @return PaymentInfo[]
380
     */
381
    public function getPaymentInfos() : array
382
    {
383
        return $this->paymentInfos;
384
    }
385
386
    /**
387
     * @return CustomerInfo
388
     */
389
    public function getCustomerInfo() : CustomerInfo
390
    {
391
        return $this->customerInfo;
392
    }
393
394
    /**
395
     * @return ReconciliationIdentifier[]
396
     */
397
    public function getReconciliationIdentifiers() : array
398
    {
399
        return $this->reconciliationIdentifiers;
400
    }
401
402
    protected function init()
403
    {
404
        $this->transactionId = (int)$this->xmlDoc->TransactionId;
405
        $this->paymentId = (string)$this->xmlDoc->PaymentId;
406
        $this->cardStatus = (string)$this->xmlDoc->CardStatus;
407
        $this->creditCardToken = (string)$this->xmlDoc->CreditCardToken;
408
        $this->creditCardMaskedPan = (string)$this->xmlDoc->CreditCardMaskedPan;
409
        $this->threeDSecureResult = (string)$this->xmlDoc->ThreeDSecureResult;
410
        $this->liableForChargeback = (string)$this->xmlDoc->LiableForChargeback;
411
        $this->blacklistToken = (string)$this->xmlDoc->BlacklistToken;
412
        $this->shopOrderId = (string)$this->xmlDoc->ShopOrderId;
413
        $this->shop = (string)$this->xmlDoc->Shop;
414
        $this->terminal = (string)$this->xmlDoc->Terminal;
415
        $this->transactionStatus = (string)$this->xmlDoc->TransactionStatus;
416
        $this->reasonCode = (string)$this->xmlDoc->ReasonCode;
417
        $this->merchantCurrency = (int)$this->xmlDoc->MerchantCurrency;
418
        $this->merchantCurrencyAlpha = (string)$this->xmlDoc->MerchantCurrencyAlpha;
419
        $this->cardHolderCurrency = (int)$this->xmlDoc->CardHolderCurrency;
420
        $this->cardHolderCurrencyAlpha = (string)$this->xmlDoc->CardHolderCurrencyAlpha;
421
        $this->reservedAmount = (float)$this->xmlDoc->ReservedAmount;
422
        $this->capturedAmount = (float)$this->xmlDoc->CapturedAmount;
423
        $this->refundedAmount = (float)$this->xmlDoc->RefundedAmount;
424
        $this->recurringDefaultAmount = (float)$this->xmlDoc->RecurringDefaultAmount;
425
        $this->paymentNature = (string)$this->xmlDoc->PaymentNature;
426
        $this->fraudRiskScore = (float)$this->xmlDoc->FraudRiskScore;
427
        $this->fraudExplanation = (string)$this->xmlDoc->FraudExplanation;
428
429
        $this->createdDate = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', (string)$this->xmlDoc->CreatedDate);
430 View Code Duplication
        if ($this->createdDate === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
431
            $exception = new ResponseException('The created date format is wrong');
432
            $exception->setResponse($this->getOriginalResponse());
433
            throw $exception;
434
        }
435
436
        $this->updatedDate = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', (string)$this->xmlDoc->UpdatedDate);
437 View Code Duplication
        if ($this->updatedDate === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
438
            $exception = new ResponseException('The updated date format is wrong');
439
            $exception->setResponse($this->getOriginalResponse());
440
            throw $exception;
441
        }
442
443
        // populating payment nature service object
444
        $this->paymentNatureService = new PaymentNatureService(
445
            $this->getOriginalResponse(),
446
            $this->xmlDoc->PaymentNatureService
447
        );
448
449
        // populating payment info objects
450
        $this->paymentInfos = [];
451 View Code Duplication
        if (isset($this->xmlDoc->PaymentInfos) &&
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
452
            isset($this->xmlDoc->PaymentInfos->PaymentInfo) &&
453
            !empty($this->xmlDoc->PaymentInfos->PaymentInfo)) {
454
            foreach ($this->xmlDoc->PaymentInfos->PaymentInfo as $paymentInfo) {
455
                $this->paymentInfos[] = new PaymentInfo($this->getOriginalResponse(), $paymentInfo);
456
            }
457
        }
458
459
        // populating customer info object
460
        $this->customerInfo = new Transaction\CustomerInfo($this->getOriginalResponse(), $this->xmlDoc->CustomerInfo);
461
462
        // populating reconciliation identifiers
463
        $this->reconciliationIdentifiers = [];
464 View Code Duplication
        if (isset($this->xmlDoc->ReconciliationIdentifiers) &&
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
465
            isset($this->xmlDoc->ReconciliationIdentifiers->ReconciliationIdentifier) &&
466
            !empty($this->xmlDoc->ReconciliationIdentifiers->ReconciliationIdentifier)) {
467
            foreach ($this->xmlDoc->ReconciliationIdentifiers->ReconciliationIdentifier as $reconciliationIdentifier) {
468
                $this->reconciliationIdentifiers[] = new ReconciliationIdentifier(
469
                    $this->getOriginalResponse(),
470
                    $reconciliationIdentifier
471
                );
472
            }
473
        }
474
    }
475
}
476