Completed
Push — master ( 0d5cb2...ca808c )
by Frederik
8s
created

EntryTransactionDetail::addRemittanceInformation()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
ccs 21
cts 21
cp 1
rs 8.439
cc 6
eloc 16
nc 4
nop 2
crap 6
1
<?php
2
3
namespace Genkgo\Camt\Decoder;
4
5
use Genkgo\Camt\DTO;
6
use \SimpleXMLElement;
7
use Genkgo\Camt\Iban;
8
9
abstract class EntryTransactionDetail
10
{
11
    /**
12
     * @param DTO\EntryTransactionDetail $detail
13
     * @param SimpleXMLElement           $xmlDetail
14
     */
15 18
    public function addReferences(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
16
    {
17 18
        if (false === isset($xmlDetail->Refs)) {
18 1
            return;
19
        }
20
21 18
        $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 17
        $reference = new DTO\Reference();
23
24 17
        $reference->setMessageId(isset($refs->MsgId) ? (string) $refs->MsgId : null);
25 17
        $reference->setAccountServiceReference(isset($refs->AcctSvcrRef) ? (string) $refs->AcctSvcrRef : null);
26 17
        $reference->setPaymentInformationId(isset($refs->PmtInfId) ? (string) $refs->PmtInfId : null);
27 17
        $reference->setInstructionId(isset($refs->InstrId) ? (string) $refs->InstrId : null);
28 17
        $reference->setEndToEndId(isset($refs->EndToEndId) ? (string) $refs->EndToEndId : null);
29 17
        $reference->setTransactionId(isset($refs->TxId) ? (string) $refs->TxId : null);
30 17
        $reference->setMandateId(isset($refs->MndtId) ? (string) $refs->MndtId : null);
31 17
        $reference->setChequeNumber(isset($refs->ChqNb) ? (string) $refs->ChqNb : null);
32 17
        $reference->setClearingSystemReference(isset($refs->ClrSysRef) ? (string) $refs->ClrSysRef : null);
33 17
        $reference->setAccountOwnerTransactionId(isset($refs->AcctOwnrTxId) ? (string) $refs->AcctOwnrTxId : null);
34 17
        $reference->setAccountServicerTransactionId(isset($refs->AcctSvcrTxId) ? (string) $refs->AcctSvcrTxId : null);
35 17
        $reference->setMarketInfrastructureTransactionId(isset($refs->MktInfrstrctrTxId) ? (string) $refs->MktInfrstrctrTxId : null);
36 17
        $reference->setProcessingId(isset($refs->PrcgId) ? (string) $refs->PrcgId : null);
37
38 17
        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 17
        }
44
45 17
        $detail->addReference($reference);
46 17
    }
47
48
    /**
49
     * @param DTO\EntryTransactionDetail $detail
50
     * @param SimpleXMLElement           $xmlDetail
51
     */
52 18
    public function addRelatedParties(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
53
    {
54 18
        if (false === isset($xmlDetail->RltdPties)) {
55 1
            return;
56
        }
57
58 17
        foreach ($xmlDetail->RltdPties as $xmlRelatedParty) {
59 17
            if (isset($xmlRelatedParty->Cdtr)) {
60 13
                $xmlRelatedPartyType = $xmlRelatedParty->Cdtr;
61 13
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->CdtrAcct;
62 13
                $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 17
            } elseif (isset($xmlRelatedParty->Dbtr)) {
64 9
                $xmlRelatedPartyType = $xmlRelatedParty->Dbtr;
65 9
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->DbtrAcct;
66 9
                $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 9
            } else {
68
                continue;
69
            }
70
71 17
            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->CtrySubDvsn)) {
77
                    $address = $address->setCountrySubDivision((string) $xmlRelatedPartyType->PstlAdr->CtrySubDvsn);
78
                }
79 11
                if (isset($xmlRelatedPartyType->PstlAdr->Dept)) {
80
                    $address = $address->setDepartment((string) $xmlRelatedPartyType->PstlAdr->Dept);
81
                }
82 11
                if (isset($xmlRelatedPartyType->PstlAdr->SubDept)) {
83
                    $address = $address->setSubDepartment((string) $xmlRelatedPartyType->PstlAdr->SubDept);
84
                }
85 11
                if (isset($xmlRelatedPartyType->PstlAdr->StrtNm)) {
86
                    $address = $address->setStreetName((string) $xmlRelatedPartyType->PstlAdr->StrtNm);
87
                }
88 11
                if (isset($xmlRelatedPartyType->PstlAdr->BldgNb)) {
89
                    $address = $address->setBuildingNumber((string) $xmlRelatedPartyType->PstlAdr->BldgNb);
90
                }
91 11
                if (isset($xmlRelatedPartyType->PstlAdr->PstCd)) {
92
                    $address = $address->setPostCode((string) $xmlRelatedPartyType->PstlAdr->PstCd);
93
                }
94 11
                if (isset($xmlRelatedPartyType->PstlAdr->TwnNm)) {
95
                    $address = $address->setTownName((string) $xmlRelatedPartyType->PstlAdr->TwnNm);
96
                }
97 11
                if (isset($xmlRelatedPartyType->PstlAdr->AdrLine)) {
98 1
                    foreach ($xmlRelatedPartyType->PstlAdr->AdrLine as $line) {
99 1
                        $address = $address->addAddressLine((string)$line);
100 1
                    }
101 1
                }
102
103 11
                $relatedPartyType->setAddress($address);
104 11
            }
105
106 17
            $relatedParty = new DTO\RelatedParty($relatedPartyType, $this->getRelatedPartyAccount($xmlRelatedPartyTypeAccount));
107 17
            $detail->addRelatedParty($relatedParty);
108 17
        }
109 17
    }
110
111
    /**
112
     * @param DTO\EntryTransactionDetail $detail
113
     * @param SimpleXMLElement           $xmlDetail
114
     */
115 19
    public function addRemittanceInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
116
    {
117 19
        if (false === isset($xmlDetail->RmtInf)) {
118 4
            return;
119
        }
120
121 15
        if (isset($xmlDetail->RmtInf->Ustrd)) {
122 6
            $remittanceInformation = DTO\RemittanceInformation::fromUnstructured(
123 6
                (string)$xmlDetail->RmtInf->Ustrd
124 6
            );
125 6
            $detail->setRemittanceInformation($remittanceInformation);
126
127 6
            return;
128
        }
129
        
130 9
        if (isset($xmlDetail->RmtInf->Strd)
131 9
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf)
132 9
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf->Ref)
133 9
        ) {
134 9
            $creditorReferenceInformation = DTO\CreditorReferenceInformation::fromUnstructured(
135 9
                (string)$xmlDetail->RmtInf->Strd->CdtrRefInf->Ref
136 9
            );
137 9
            $remittanceInformation = new DTO\RemittanceInformation();
138 9
            $remittanceInformation->setCreditorReferenceInformation($creditorReferenceInformation);
139 9
            $detail->setRemittanceInformation($remittanceInformation);
140 9
        }
141 9
    }
142
143
    /**
144
     * @param DTO\EntryTransactionDetail $detail
145
     * @param SimpleXMLElement           $xmlDetail
146
     */
147 18
    public function addReturnInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
148
    {
149 18
        if (isset($xmlDetail->RtrInf) && isset($xmlDetail->RtrInf->Rsn->Cd)) {
150 1
            $remittanceInformation = DTO\ReturnInformation::fromUnstructured(
151 1
                (string)$xmlDetail->RtrInf->Rsn->Cd,
152 1
                (string)$xmlDetail->RtrInf->AddtlInf
153 1
            );
154 1
            $detail->setReturnInformation($remittanceInformation);
155 1
        }
156 18
    }
157
158
    /**
159
     * @param DTO\EntryTransactionDetail $detail
160
     * @param SimpleXMLElement           $xmlDetail
161
     */
162 18
    public function addAdditionalTransactionInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
163
    {
164 18
        if (isset($xmlDetail->AddtlTxInf)) {
165 1
            $additionalInformation = new DTO\AdditionalTransactionInformation(
166 1
                (string) $xmlDetail->AddtlTxInf
167 1
            );
168 1
            $detail->setAdditionalTransactionInformation($additionalInformation);
169 1
        }
170 18
    }
171
172
    /**
173
     * @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...
174
     *
175
     * @return DTO\Account|null
176
     */
177
    abstract public function getRelatedPartyAccount(SimpleXMLElement $xmlRelatedPartyTypeAccount);
178
}
179