Completed
Push — master ( 606f02...b5ae25 )
by Frederik
9s
created

EntryTransactionDetail::getRelatedPartyAccount()   D

Complexity

Conditions 9
Paths 13

Size

Total Lines 33
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 15.3773

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 33
ccs 12
cts 21
cp 0.5714
rs 4.909
cc 9
eloc 17
nc 13
nop 1
crap 15.3773
1
<?php
2
3
namespace Genkgo\Camt\Camt053\Decoder;
4
5
use Genkgo\Camt\Camt053\DTO;
6
use \SimpleXMLElement;
7
use Genkgo\Camt\Iban;
8
9
class EntryTransactionDetail
10
{
11
    /**
12
     * @param DTO\EntryTransactionDetail $detail
13
     * @param SimpleXMLElement           $xmlDetail
14
     */
15 12
    public function addReferences(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
16
    {
17 12
        if (false === isset($xmlDetail->Refs)) {
18 1
            return;
19
        }
20
21 11
        $refs = $xmlDetail->Refs;
0 ignored issues
show
Bug introduced by
The property Refs does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
22 12
        $reference = new DTO\Reference();
23
24 11
        $reference->setMessageId(isset($refs->MsgId) ? (string) $refs->MsgId : null);
25 11
        $reference->setAccountServiceReference(isset($refs->AcctSvcrRef) ? (string) $refs->AcctSvcrRef : null);
26 11
        $reference->setPaymentInformationId(isset($refs->PmtInfId) ? (string) $refs->PmtInfId : null);
27 11
        $reference->setInstructionId(isset($refs->InstrId) ? (string) $refs->InstrId : null);
28 11
        $reference->setEndToEndId(isset($refs->EndToEndId) ? (string) $refs->EndToEndId : null);
29 11
        $reference->setTransactionId(isset($refs->TxId) ? (string) $refs->TxId : null);
30 11
        $reference->setMandateId(isset($refs->MndtId) ? (string) $refs->MndtId : null);
31 11
        $reference->setChequeNumber(isset($refs->ChqNb) ? (string) $refs->ChqNb : null);
32 11
        $reference->setClearingSystemReference(isset($refs->ClrSysRef) ? (string) $refs->ClrSysRef : null);
33 11
        $reference->setAccountOwnerTransactionId(isset($refs->AcctOwnrTxId) ? (string) $refs->AcctOwnrTxId : null);
34 11
        $reference->setAccountServicerTransactionId(isset($refs->AcctSvcrTxId) ? (string) $refs->AcctSvcrTxId : null);
35 11
        $reference->setMarketInfrastructureTransactionId(isset($refs->MktInfrstrctrTxId) ? (string) $refs->MktInfrstrctrTxId : null);
36 11
        $reference->setProcessingId(isset($refs->PrcgId) ? (string) $refs->PrcgId : null);
37
38 11
        foreach ($refs->Prtry as $xmlProprietary) {
39 8
            $type = isset($xmlProprietary->Tp) ? (string) $xmlProprietary->Tp : null;
40 8
            $subReference = isset($xmlProprietary->Ref) ? (string) $xmlProprietary->Ref : null;
41
42 8
            $reference->addProprietary(new DTO\ProprietaryReference($type, $subReference));
43 11
        }
44
45 11
        $detail->addReference($reference);
46 11
    }
47
48
    /**
49
     * @param DTO\EntryTransactionDetail $detail
50
     * @param SimpleXMLElement           $xmlDetail
51
     */
52 12
    public function addRelatedParties(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
53
    {
54 12
        if (false === isset($xmlDetail->RltdPties)) {
55 1
            return;
56
        }
57
58 11
        foreach ($xmlDetail->RltdPties as $xmlRelatedParty) {
59 11
            if (isset($xmlRelatedParty->Cdtr)) {
60 10
                $xmlRelatedPartyType = $xmlRelatedParty->Cdtr;
61 10
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->CdtrAcct;
62 10
                $relatedPartyType = $creditor = new DTO\Creditor((string) $xmlRelatedPartyType->Nm);
0 ignored issues
show
Unused Code introduced by
$creditor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63 11
            } elseif (isset($xmlRelatedParty->Dbtr)) {
64 6
                $xmlRelatedPartyType = $xmlRelatedParty->Dbtr;
65 6
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->DbtrAcct;
66 6
                $relatedPartyType = $creditor = new DTO\Debtor((string) $xmlRelatedPartyType->Nm);
0 ignored issues
show
Unused Code introduced by
$creditor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
67 6
            } else {
68
                continue;
69
            }
70
71 11
            if (isset($xmlRelatedPartyType->PstlAdr)) {
72 11
                $address = new DTO\Address();
73 11
                if (isset($xmlRelatedPartyType->PstlAdr->Ctry)) {
74 11
                    $address = $address->setCountry((string) $xmlRelatedPartyType->PstlAdr->Ctry);
75 11
                }
76 11
                if (isset($xmlRelatedPartyType->PstlAdr->AdrLine)) {
77 1
                    foreach ($xmlRelatedPartyType->PstlAdr->AdrLine as $line) {
78 1
                        $address = $address->addAddressLine((string)$line);
79 1
                    }
80 1
                }
81
82 11
                $relatedPartyType->setAddress($address);
83 11
            }
84
85 11
            $relatedParty = new DTO\RelatedParty($relatedPartyType, $this->getRelatedPartyAccount($xmlRelatedPartyTypeAccount));
86 11
            $detail->addRelatedParty($relatedParty);
87 11
        }
88 11
    }
89
90
    /**
91
     * @param DTO\EntryTransactionDetail $detail
92
     * @param SimpleXMLElement           $xmlDetail
93
     */
94 13
    public function addRemittanceInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
95
    {
96 13
        if (false === isset($xmlDetail->RmtInf)) {
97 1
            return;
98
        }
99
100 12
        if (isset($xmlDetail->RmtInf->Ustrd)) {
101 3
            $remittanceInformation = DTO\RemittanceInformation::fromUnstructured(
102 3
                (string)$xmlDetail->RmtInf->Ustrd
103 3
            );
104 3
            $detail->setRemittanceInformation($remittanceInformation);
105
106 3
            return;
107
        }
108
        
109 9
        if (isset($xmlDetail->RmtInf->Strd)
110 9
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf)
111 9
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf->Ref)
112 9
        ) {
113 9
            $creditorReferenceInformation = DTO\CreditorReferenceInformation::fromUnstructured(
114 9
                (string)$xmlDetail->RmtInf->Strd->CdtrRefInf->Ref
115 9
            );
116 9
            $remittanceInformation = new DTO\RemittanceInformation();
117 9
            $remittanceInformation->setCreditorReferenceInformation($creditorReferenceInformation);
118 9
            $detail->setRemittanceInformation($remittanceInformation);
119 9
        }
120 9
    }
121
122
    /**
123
     * @param DTO\EntryTransactionDetail $detail
124
     * @param SimpleXMLElement           $xmlDetail
125
     */
126 12
    public function addReturnInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
127
    {
128 12
        if (isset($xmlDetail->RtrInf) && isset($xmlDetail->RtrInf->Rsn->Cd)) {
129 1
            $remittanceInformation = DTO\ReturnInformation::fromUnstructured(
130 1
                (string)$xmlDetail->RtrInf->Rsn->Cd,
131 1
                (string)$xmlDetail->RtrInf->AddtlInf
132 1
            );
133 1
            $detail->setReturnInformation($remittanceInformation);
134 1
        }
135 12
    }
136
137
    /**
138
     * @param DTO\EntryTransactionDetail $detail
139
     * @param SimpleXMLElement           $xmlDetail
140
     */
141 12
    public function addAdditionalTransactionInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
142
    {
143 12
        if (isset($xmlDetail->AddtlTxInf)) {
144 1
            $additionalInformation = new DTO\AdditionalTransactionInformation(
145 1
                (string) $xmlDetail->AddtlTxInf
146 1
            );
147 1
            $detail->setAdditionalTransactionInformation($additionalInformation);
148 1
        }
149 12
    }
150
151
    /**
152
     * @param SimpleXMLElement $xmlDetail
0 ignored issues
show
Bug introduced by
There is no parameter named $xmlDetail. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
153
     *
154
     * @return DTO\Account|null
155
     */
156 11
    private function getRelatedPartyAccount(SimpleXMLElement $xmlRelatedPartyTypeAccount)
157
    {
158 11
        if (false === isset($xmlRelatedPartyTypeAccount->Id)) {
159
            return;
160
        }
161
162 11
        if (isset($xmlRelatedPartyTypeAccount->Id->IBAN) && $ibanCode = (string) $xmlRelatedPartyTypeAccount->Id->IBAN) {
163 10
            return new DTO\IbanAccount(new Iban($ibanCode));
164
        }
165
166 6
        if (false === isset($xmlRelatedPartyTypeAccount->Id->Othr)) {
167
            return;
168
        }
169
170 6
        $xmlOtherIdentification = $xmlRelatedPartyTypeAccount->Id->Othr;
171 6
        $otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id);
172
173 6
        if (isset($xmlOtherIdentification->SchmeNm)) {
174
            if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
175
                $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd);
176
            }
177
178
            if (isset($xmlOtherIdentification->SchmeNm->Prtry)) {
179
                $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry);
180
            }
181
        }
182
183 6
        if (isset($xmlOtherIdentification->Issr)) {
184 6
            $otherAccount->setIssuer((string) $xmlOtherIdentification->Issr);
185 6
        }
186
187 6
        return $otherAccount;
188
    }
189
}
190