Completed
Push — master ( c98fe8...bf7ad8 )
by Joachim
05:52
created

Transaction::hydrateXml()   F

Complexity

Conditions 12
Paths 896

Size

Total Lines 57
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 50
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 50
cts 50
cp 1
rs 3.5087
c 0
b 0
f 0
cc 12
eloc 49
nc 896
nop 1
crap 12

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Loevgaard\AltaPay\Entity;
3
4
use Loevgaard\AltaPay\Exception\XmlException;
5
use Loevgaard\AltaPay\Hydrator\HydratableInterface;
6
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)
181
    {
182 27
        $this->transactionId = (int)$xml->TransactionId;
183 27
        $this->paymentId = (string)$xml->PaymentId;
184 27
        $this->authType = isset($xml->AuthType) ? (string)$xml->AuthType : null;
185 27
        $this->cardStatus = (string)$xml->CardStatus;
186 27
        $this->creditCardToken = (string)$xml->CreditCardToken;
187 27
        $this->creditCardMaskedPan = (string)$xml->CreditCardMaskedPan;
188 27
        $this->threeDSecureResult = (string)$xml->ThreeDSecureResult;
189 27
        $this->liableForChargeback = (string)$xml->LiableForChargeback;
190 27
        $this->CVVCheckResult = isset($xml->CVVCheckResult) ? (string)$xml->CVVCheckResult : null;
191 27
        $this->blacklistToken = (string)$xml->BlacklistToken;
192 27
        $this->shopOrderId = (string)$xml->ShopOrderId;
193 27
        $this->shop = (string)$xml->Shop;
194 27
        $this->terminal = (string)$xml->Terminal;
195 27
        $this->transactionStatus = (string)$xml->TransactionStatus;
196 27
        $this->reasonCode = (string)$xml->ReasonCode;
197 27
        $this->merchantCurrency = (int)$xml->MerchantCurrency;
198 27
        $this->merchantCurrencyAlpha = (string)$xml->MerchantCurrencyAlpha;
199 27
        $this->cardHolderCurrency = (int)$xml->CardHolderCurrency;
200 27
        $this->cardHolderCurrencyAlpha = (string)$xml->CardHolderCurrencyAlpha;
201 27
        $this->reservedAmount = (float)$xml->ReservedAmount;
202 27
        $this->capturedAmount = (float)$xml->CapturedAmount;
203 27
        $this->refundedAmount = (float)$xml->RefundedAmount;
204 27
        $this->creditedAmount = isset($xml->CreditedAmount) ? (float)$xml->CreditedAmount : null;
205 27
        $this->recurringDefaultAmount = (float)$xml->RecurringDefaultAmount;
206 27
        $this->surchargeAmount = isset($xml->SurchargeAmount) ? (float)$xml->SurchargeAmount : null;
207 27
        $this->paymentNature = (string)$xml->PaymentNature;
208 27
        $this->paymentSchemeName = isset($xml->PaymentSchemeName) ? (string)$xml->PaymentSchemeName : null;
209 27
        $this->addressVerification = isset($xml->AddressVerification) ? (string)$xml->AddressVerification : null;
210 27
        $this->addressVerificationDescription = isset($xml->AddressVerificationDescription) ? (string)$xml->AddressVerificationDescription : null;
211 27
        $this->fraudRiskScore = (float)$xml->FraudRiskScore;
212 27
        $this->fraudExplanation = (string)$xml->FraudExplanation;
213 27
        $this->hydratePaymentNatureService($xml);
214 27
        $this->hydratePaymentInfos($xml);
215 27
        $this->hydrateCustomerInfo($xml);
216 27
        $this->hydrateReconciliationIdentifiers($xml);
217 27
        $this->hydrateCreditCardExpiry($xml);
218
219 27
        if (isset($xml->CreatedDate)) {
220 21
            $this->createdDate = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', (string)$xml->CreatedDate);
221 21
            if ($this->createdDate === false) {
222 3
                $exception = new XmlException('The created date format is wrong');
223 3
                $exception->setXmlElement($xml);
224 3
                throw $exception;
225
            }
226
        }
227
228 24
        if (isset($xml->UpdatedDate)) {
229 21
            $this->updatedDate = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', (string)$xml->UpdatedDate);
230 21
            if ($this->updatedDate === false) {
231 3
                $exception = new XmlException('The updated date format is wrong');
232 3
                $exception->setXmlElement($xml);
233 3
                throw $exception;
234
            }
235
        }
236 21
    }
237
238
    /**
239
     * @return int
240
     */
241 3
    public function getTransactionId() : ?int
242
    {
243 3
        return $this->transactionId;
244
    }
245
246
    /**
247
     * @return string
248
     */
249 3
    public function getPaymentId() : ?string
250
    {
251 3
        return $this->paymentId;
252
    }
253
254
    /**
255
     * @return string
256
     */
257 6
    public function getAuthType(): ?string
258
    {
259 6
        return $this->authType;
260
    }
261
262
    /**
263
     * @return string
264
     */
265 3
    public function getCardStatus() : ?string
266
    {
267 3
        return $this->cardStatus;
268
    }
269
270
    /**
271
     * @return string
272
     */
273 3
    public function getCreditCardToken() : ?string
274
    {
275 3
        return $this->creditCardToken;
276
    }
277
278
    /**
279
     * @return string
280
     */
281 3
    public function getCreditCardMaskedPan() : ?string
282
    {
283 3
        return $this->creditCardMaskedPan;
284
    }
285
286
    /**
287
     * @return string
288
     */
289 3
    public function getThreeDSecureResult() : ?string
290
    {
291 3
        return $this->threeDSecureResult;
292
    }
293
294
    /**
295
     * @return string
296
     */
297 3
    public function getLiableForChargeback() : ?string
298
    {
299 3
        return $this->liableForChargeback;
300
    }
301
302
    /**
303
     * @return string
304
     */
305 6
    public function getCVVCheckResult(): ?string
306
    {
307 6
        return $this->CVVCheckResult;
308
    }
309
310
    /**
311
     * @return string
312
     */
313 3
    public function getBlacklistToken() : ?string
314
    {
315 3
        return $this->blacklistToken;
316
    }
317
318
    /**
319
     * @return string
320
     */
321 3
    public function getShopOrderId() : ?string
322
    {
323 3
        return $this->shopOrderId;
324
    }
325
326
    /**
327
     * @return string
328
     */
329 3
    public function getShop() : ?string
330
    {
331 3
        return $this->shop;
332
    }
333
334
    /**
335
     * @return string
336
     */
337 3
    public function getTerminal() : ?string
338
    {
339 3
        return $this->terminal;
340
    }
341
342
    /**
343
     * @return string
344
     */
345 3
    public function getTransactionStatus() : ?string
346
    {
347 3
        return $this->transactionStatus;
348
    }
349
350
    /**
351
     * @return string
352
     */
353 3
    public function getReasonCode() : ?string
354
    {
355 3
        return $this->reasonCode;
356
    }
357
358
    /**
359
     * @return int
360
     */
361 3
    public function getMerchantCurrency() : ?int
362
    {
363 3
        return $this->merchantCurrency;
364
    }
365
366
    /**
367
     * @return string
368
     */
369 3
    public function getMerchantCurrencyAlpha() : ?string
370
    {
371 3
        return $this->merchantCurrencyAlpha;
372
    }
373
374
    /**
375
     * @return int
376
     */
377 3
    public function getCardHolderCurrency() : ?int
378
    {
379 3
        return $this->cardHolderCurrency;
380
    }
381
382
    /**
383
     * @return string
384
     */
385 3
    public function getCardHolderCurrencyAlpha() : ?string
386
    {
387 3
        return $this->cardHolderCurrencyAlpha;
388
    }
389
390
    /**
391
     * @return float
392
     */
393 3
    public function getReservedAmount() : ?float
394
    {
395 3
        return $this->reservedAmount;
396
    }
397
398
    /**
399
     * @return float
400
     */
401 3
    public function getCapturedAmount() : ?float
402
    {
403 3
        return $this->capturedAmount;
404
    }
405
406
    /**
407
     * @return float
408
     */
409 3
    public function getRefundedAmount() : ?float
410
    {
411 3
        return $this->refundedAmount;
412
    }
413
414
    /**
415
     * @return float
416
     */
417 6
    public function getCreditedAmount(): ?float
418
    {
419 6
        return $this->creditedAmount;
420
    }
421
422
    /**
423
     * @return float
424
     */
425 3
    public function getRecurringDefaultAmount() : ?float
426
    {
427 3
        return $this->recurringDefaultAmount;
428
    }
429
430
    /**
431
     * @return float
432
     */
433 6
    public function getSurchargeAmount(): ?float
434
    {
435 6
        return $this->surchargeAmount;
436
    }
437
438
    /**
439
     * @return \DateTimeImmutable
440
     */
441 3
    public function getCreatedDate() : ?\DateTimeImmutable
442
    {
443 3
        return $this->createdDate;
444
    }
445
446
    /**
447
     * @return \DateTimeImmutable
448
     */
449 3
    public function getUpdatedDate() : ?\DateTimeImmutable
450
    {
451 3
        return $this->updatedDate;
452
    }
453
454
    /**
455
     * @return string
456
     */
457 3
    public function getPaymentNature() : ?string
458
    {
459 3
        return $this->paymentNature;
460
    }
461
462
    /**
463
     * @return float
464
     */
465 3
    public function getFraudRiskScore() : ?float
466
    {
467 3
        return $this->fraudRiskScore;
468
    }
469
470
    /**
471
     * @return string
472
     */
473 3
    public function getFraudExplanation() : ?string
474
    {
475 3
        return $this->fraudExplanation;
476
    }
477
}
478