Passed
Pull Request — master (#121)
by
unknown
10:16
created

EntryTransactionDetail::addCharges()   C

Complexity

Conditions 12
Paths 5

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
eloc 18
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 31
ccs 0
cts 0
cp 0
crap 156
rs 6.9666

How to fix   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
3
declare(strict_types=1);
4
5
namespace Genkgo\Camt\Camt053\Decoder;
6
7
use Genkgo\Camt\Decoder\EntryTransactionDetail as BaseDecoder;
8
use Genkgo\Camt\DTO;
9
use Genkgo\Camt\Iban;
10
use SimpleXMLElement;
11
12
class EntryTransactionDetail extends BaseDecoder
13
{
14
    /**
15
     * @inheritDoc
16
     */
17 12
    public function getRelatedPartyAccount(?SimpleXMLElement $xmlRelatedPartyTypeAccount): ?DTO\Account
18
    {
19 12
        if (!$xmlRelatedPartyTypeAccount) {
20 5
            return null;
21
        }
22
23 12
        if (false === isset($xmlRelatedPartyTypeAccount->Id)) {
24
            return null;
25
        }
26
27 12
        if (isset($xmlRelatedPartyTypeAccount->Id->IBAN) && $ibanCode = (string) $xmlRelatedPartyTypeAccount->Id->IBAN) {
28 12
            return new DTO\IbanAccount(new Iban($ibanCode));
29
        }
30
31
        if (false === isset($xmlRelatedPartyTypeAccount->Id->Othr)) {
32
            return null;
33
        }
34
35
        $xmlOtherIdentification = $xmlRelatedPartyTypeAccount->Id->Othr;
36
        $otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id);
37
38
        if (isset($xmlOtherIdentification->SchmeNm)) {
39
            if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
40
                $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd);
41
            }
42
43
            if (isset($xmlOtherIdentification->SchmeNm->Prtry)) {
44
                $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry);
45
            }
46
        }
47
48
        if (isset($xmlOtherIdentification->Issr)) {
49
            $otherAccount->setIssuer((string) $xmlOtherIdentification->Issr);
50
        }
51
52
        return $otherAccount;
53
    }
54
    
55
    public function addCharges(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail): void
56
    {
57
        if (isset($xmlDetail->Chrgs)) {
58
            $charges = new DTO\Charges();
59
60
            if (isset($xmlDetail->Chrgs->TtlChrgsAndTaxAmt) && (string) $xmlDetail->Chrgs->TtlChrgsAndTaxAmt) {
61
                $money = $this->moneyFactory->create($xmlDetail->Chrgs->TtlChrgsAndTaxAmt, null);
62
                $charges->setTotalChargesAndTaxAmount($money);
63
            }
64
65
            $chargesRecords = $xmlDetail->Chrgs;
66
            if ($chargesRecords !== null) {
67
68
                /** @var SimpleXMLElement $chargesRecord */
69
                foreach ($xmlDetail->Chrgs as $chargesRecord) {
70
                    $chargesDetail = new DTO\ChargesRecord();
71
72
                    if (isset($chargesRecord->Amt) && (string) $chargesRecord->Amt) {
73
                        $money = $this->moneyFactory->create($chargesRecord->Amt, $chargesRecord->CdtDbtInd);
74
                        $chargesDetail->setAmount($money);
75
                    }
76
                    if (isset($chargesRecord->CdtDbtInd) && (string) $chargesRecord->CdtDbtInd === 'true') {
77
                        $chargesDetail->setChargesIncludedIndicator(true);
78
                    }
79
                    if (isset($chargesRecord->Tp->Prtry->Id) && (string) $chargesRecord->Tp->Prtry->Id) {
80
                        $chargesDetail->setIdentification((string) $chargesRecord->Tp->Prtry->Id);
81
                    }
82
                    $charges->addRecord($chargesDetail);
83
                }
84
            }
85
            $detail->setCharges($charges);
86
        }
87
    }
88
}
89