Completed
Pull Request — master (#37)
by
unknown
06:42
created

EntryTransactionDetail::addRemittanceInformation()   D

Complexity

Conditions 10
Paths 6

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 10

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 23
cts 23
cp 1
rs 4.8196
c 0
b 0
f 0
cc 10
eloc 16
nc 6
nop 2
crap 10

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
namespace Genkgo\Camt\Decoder;
4
5
use Genkgo\Camt\DTO;
6
use \SimpleXMLElement;
7
use Genkgo\Camt\Decoder\Factory\DTO as DTOFactory;
8
use Genkgo\Camt\Iban;
9
10
abstract class EntryTransactionDetail
11
{
12
    /**
13
     * @param DTO\EntryTransactionDetail $detail
14
     * @param SimpleXMLElement           $xmlDetail
15
     */
16 22
    public function addReferences(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
17
    {
18 22
        if (false === isset($xmlDetail->Refs)) {
19 8
            return;
20 21
        }
21
22 20
        $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...
23 17
        $reference = new DTO\Reference();
24
25 17
        $reference->setMessageId(isset($refs->MsgId) ? (string) $refs->MsgId : null);
26 17
        $reference->setAccountServiceReference(isset($refs->AcctSvcrRef) ? (string) $refs->AcctSvcrRef : null);
27 17
        $reference->setPaymentInformationId(isset($refs->PmtInfId) ? (string) $refs->PmtInfId : null);
28 17
        $reference->setInstructionId(isset($refs->InstrId) ? (string) $refs->InstrId : null);
29 17
        $reference->setEndToEndId(isset($refs->EndToEndId) ? (string) $refs->EndToEndId : null);
30 17
        $reference->setTransactionId(isset($refs->TxId) ? (string) $refs->TxId : null);
31 17
        $reference->setMandateId(isset($refs->MndtId) ? (string) $refs->MndtId : null);
32 17
        $reference->setChequeNumber(isset($refs->ChqNb) ? (string) $refs->ChqNb : null);
33 17
        $reference->setClearingSystemReference(isset($refs->ClrSysRef) ? (string) $refs->ClrSysRef : null);
34 17
        $reference->setAccountOwnerTransactionId(isset($refs->AcctOwnrTxId) ? (string) $refs->AcctOwnrTxId : null);
35 17
        $reference->setAccountServicerTransactionId(isset($refs->AcctSvcrTxId) ? (string) $refs->AcctSvcrTxId : null);
36 17
        $reference->setMarketInfrastructureTransactionId(isset($refs->MktInfrstrctrTxId) ? (string) $refs->MktInfrstrctrTxId : null);
37 17
        $reference->setProcessingId(isset($refs->PrcgId) ? (string) $refs->PrcgId : null);
38
39 18
        foreach ($refs->Prtry as $xmlProprietary) {
40 8
            $type = isset($xmlProprietary->Tp) ? (string) $xmlProprietary->Tp : null;
41 14
            $subReference = isset($xmlProprietary->Ref) ? (string) $xmlProprietary->Ref : null;
42
43 8
            $reference->addProprietary(new DTO\ProprietaryReference($type, $subReference));
44 17
        }
45
46 17
        $detail->addReference($reference);
47 17
    }
48
49
    /**
50
     * @param DTO\EntryTransactionDetail $detail
51
     * @param SimpleXMLElement           $xmlDetail
52
     */
53 22
    public function addRelatedParties(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
54
    {
55 22
        if (false === isset($xmlDetail->RltdPties)) {
56 1
            return;
57
        }
58
59 21
        foreach ($xmlDetail->RltdPties as $xmlRelatedParty) {
60 21
            if (isset($xmlRelatedParty->Cdtr)) {
61 21
                $xmlRelatedPartyType = $xmlRelatedParty->Cdtr;
62 21
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->CdtrAcct;
63 21
                $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...
64
65 21
                $this->addRelatedParty($detail, $xmlRelatedPartyType, $relatedPartyType, $xmlRelatedPartyTypeAccount);
66 21
            }
67
68 21
            if (isset($xmlRelatedParty->Dbtr)) {
69 18
                $xmlRelatedPartyType = $xmlRelatedParty->Dbtr;
70 18
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->DbtrAcct;
71 18
                $relatedPartyType = $debtor = new DTO\Debtor((string) $xmlRelatedPartyType->Nm);
0 ignored issues
show
Unused Code introduced by
$debtor 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...
72
73 18
                $this->addRelatedParty($detail, $xmlRelatedPartyType, $relatedPartyType, $xmlRelatedPartyTypeAccount);
74 18
            }
75 21
        }
76 21
    }
77
78
    /**
79
     * @param DTO\EntryTransactionDetail $detail
80
     * @param $xmlRelatedPartyType
81
     * @param $relatedPartyType
82
     * @param $xmlRelatedPartyTypeAccount
83
     * @return DTO\RelatedParty
84
     */
85 21
    protected function addRelatedParty(DTO\EntryTransactionDetail $detail, $xmlRelatedPartyType, $relatedPartyType, $xmlRelatedPartyTypeAccount)
86
    {
87 21
        if (isset($xmlRelatedPartyType->PstlAdr)) {
88 21
            $relatedPartyType->setAddress(DTOFactory\Address::createFromXml($xmlRelatedPartyType->PstlAdr));
89 21
        }
90
91 21
        $relatedParty = new DTO\RelatedParty($relatedPartyType, $this->getRelatedPartyAccount($xmlRelatedPartyTypeAccount));
92
93 21
        $detail->addRelatedParty($relatedParty);
94
95 21
        return $relatedParty;
96
    }
97
98
    /**
99
     * @param DTO\EntryTransactionDetail $detail
100
     * @param SimpleXMLElement           $xmlDetail
101
     */
102 20
    public function addRelatedAgents(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
103
    {
104 20
        if (false === isset($xmlDetail->RltdAgts)) {
105 12
            return;
106
        }
107
108 16
        foreach ($xmlDetail->RltdAgts as $xmlRelatedAgent) {
109 16
            if (isset($xmlRelatedAgent->CdtrAgt)) {
110 16
                $agent = new DTO\CreditorAgent((string)$xmlRelatedAgent->CdtrAgt->FinInstnId->Nm, (string)$xmlRelatedAgent->CdtrAgt->FinInstnId->BIC);
111 16
                $relatedAgent =  new DTO\RelatedAgent($agent);
112 16
                $detail->addRelatedAgent($relatedAgent);
113 16
            }
114
115 16
            if (isset($xmlRelatedAgent->DbtrAgt)) {
116 16
                $agent = new DTO\DebtorAgent((string)$xmlRelatedAgent->DbtrAgt->FinInstnId->Nm, (string)$xmlRelatedAgent->DbtrAgt->FinInstnId->BIC);
117 16
                $relatedAgent =  new DTO\RelatedAgent($agent);
118 16
                $detail->addRelatedAgent($relatedAgent);
119 16
            }
120 16
        }
121 16
    }
122
123
    /**
124
     * @param DTO\EntryTransactionDetail $detail
125
     * @param SimpleXMLElement           $xmlDetail
126
     */
127 23
    public function addRemittanceInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
128
    {
129 23
        if (false === isset($xmlDetail->RmtInf)) {
130 11
            return;
131
        }
132
133 18
        if (isset($xmlDetail->RmtInf->Ustrd) || (isset($xmlDetail->RmtInf->Strd)
134 9
                                                 && isset($xmlDetail->RmtInf->Strd->CdtrRefInf)
135 9
                                                 && isset($xmlDetail->RmtInf->Strd->CdtrRefInf->Ref))
136 18
        ) {
137
            
138 18
            $remittanceInformation = new DTO\RemittanceInformation();
139
140 18
            if (isset($xmlDetail->RmtInf->Ustrd)) {
141 9
                $remittanceInformation->setMessage((string)$xmlDetail->RmtInf->Ustrd);
142 9
            }
143
144 18
            if (isset($xmlDetail->RmtInf->Strd)
145 18
                && isset($xmlDetail->RmtInf->Strd->CdtrRefInf)
146 18
                && isset($xmlDetail->RmtInf->Strd->CdtrRefInf->Ref)
147 18
            ) {
148 9
                $creditorReferenceInformation = DTO\CreditorReferenceInformation::fromUnstructured(
149 9
                    (string)$xmlDetail->RmtInf->Strd->CdtrRefInf->Ref
150 9
                );
151 9
                $remittanceInformation->setCreditorReferenceInformation($creditorReferenceInformation);
152
                
153 9
            }
154 18
            $detail->setRemittanceInformation($remittanceInformation);
155 18
        }
156 18
    }
157
158
    /**
159
     * @param DTO\EntryTransactionDetail $detail
160
     * @param SimpleXMLElement           $xmlDetail
161
     */
162 22
    public function addReturnInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
163
    {
164 22
        if (isset($xmlDetail->RtrInf) && isset($xmlDetail->RtrInf->Rsn->Cd)) {
165 1
            $remittanceInformation = DTO\ReturnInformation::fromUnstructured(
166 1
                (string)$xmlDetail->RtrInf->Rsn->Cd,
167 1
                (string)$xmlDetail->RtrInf->AddtlInf
168 1
            );
169 1
            $detail->setReturnInformation($remittanceInformation);
170 1
        }
171 22
    }
172
173
    /**
174
     * @param DTO\EntryTransactionDetail $detail
175
     * @param SimpleXMLElement           $xmlDetail
176
     */
177 22
    public function addAdditionalTransactionInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
178
    {
179 22
        if (isset($xmlDetail->AddtlTxInf)) {
180 1
            $additionalInformation = new DTO\AdditionalTransactionInformation(
181 1
                (string) $xmlDetail->AddtlTxInf
182 1
            );
183 1
            $detail->setAdditionalTransactionInformation($additionalInformation);
184 1
        }
185 22
    }
186
187
    /**
188
     * @param DTO\EntryTransactionDetail $detail
189
     * @param SimpleXMLElement           $xmlDetail
190
     */
191 20
    public function addBankTransactionCode(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
192
    {
193 20
        $bankTransactionCode = new DTO\BankTransactionCode();
194
195 20
        if (isset($xmlDetail->BkTxCd)) {
196 18
            $bankTransactionCode = new DTO\BankTransactionCode();
197
198 18
            if (isset($xmlDetail->BkTxCd->Prtry)) {
199 18
                $proprietaryBankTransactionCode = new DTO\ProprietaryBankTransactionCode(
200 18
                    (string)$xmlDetail->BkTxCd->Prtry->Cd,
201 18
                    (string)$xmlDetail->BkTxCd->Prtry->Issr
202 18
                );
203
204 18
                $bankTransactionCode->setProprietary($proprietaryBankTransactionCode);
205 18
            }
206 18
        }
207
208 20
        $detail->setBankTransactionCode($bankTransactionCode);
209 20
    }
210
211
    /**
212
     * @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...
213
     *
214
     * @return DTO\Account|null
215
     */
216
    abstract public function getRelatedPartyAccount(SimpleXMLElement $xmlRelatedPartyTypeAccount);
217
}
218