Completed
Pull Request — master (#31)
by
unknown
20:56
created

EntryTransactionDetail::getRelatedPartyAccount()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
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 20
    public function addReferences(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
17
    {
18 20
        if (false === isset($xmlDetail->Refs)) {
19 6
            return;
20 15
        }
21
22 17
        $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 11
            $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 20
    public function addRelatedParties(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
54
    {
55 20
        if (false === isset($xmlDetail->RltdPties)) {
56 5
            return;
57
        }
58
59 18
        foreach ($xmlDetail->RltdPties as $xmlRelatedParty) {
60 18
            if (isset($xmlRelatedParty->Cdtr)) {
61 17
                $xmlRelatedPartyType = $xmlRelatedParty->Cdtr;
62 17
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->CdtrAcct;
63 17
                $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 18
            } elseif (isset($xmlRelatedParty->Dbtr)) {
65 9
                $xmlRelatedPartyType = $xmlRelatedParty->Dbtr;
66 9
                $xmlRelatedPartyTypeAccount = $xmlRelatedParty->DbtrAcct;
67 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...
68 9
            } else {
69
                continue;
70
            }
71
72 18
            if (isset($xmlRelatedPartyType->PstlAdr)) {
73 15
                $relatedPartyType->setAddress(DTOFactory\Address::createFromXml($xmlRelatedPartyType->PstlAdr));
74 15
            }
75
76 18
            $relatedParty = new DTO\RelatedParty($relatedPartyType, $this->getRelatedPartyAccount($xmlRelatedPartyTypeAccount));
77 18
            $detail->addRelatedParty($relatedParty);
78 18
        }
79 18
    }
80
81
    /**
82
     * @param DTO\EntryTransactionDetail $detail
83
     * @param SimpleXMLElement           $xmlDetail
84
     */
85 18
    public function addRelatedAgents(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
86
    {
87 18
        if (false === isset($xmlDetail->RltdAgts)) {
88 12
            return;
89
        }
90
91 14
        foreach ($xmlDetail->RltdAgts as $xmlRelatedAgent) {
92 14
            if(isset($xmlRelatedAgent->CdtrAgt)) {
93 14
                $agent = new DTO\CreditorAgent((string)$xmlRelatedAgent->CdtrAgt->FinInstnId->Nm, (string)$xmlRelatedAgent->CdtrAgt->FinInstnId->BIC);
94 14
                $relatedAgent =  new DTO\RelatedAgent($agent);
95 14
                $detail->addRelatedAgent($relatedAgent);
96 14
            }
97
98 14
            if(isset($xmlRelatedAgent->DbtrAgt)) {
99 14
                $agent = new DTO\DebtorAgent((string)$xmlRelatedAgent->DbtrAgt->FinInstnId->Nm, (string)$xmlRelatedAgent->DbtrAgt->FinInstnId->BIC);
100 14
                $relatedAgent =  new DTO\RelatedAgent($agent);
101 14
                $detail->addRelatedAgent($relatedAgent);
102 14
            }
103 14
        }
104 14
    }
105
106
    /**
107
     * @param DTO\EntryTransactionDetail $detail
108
     * @param SimpleXMLElement           $xmlDetail
109
     */
110 21
    public function addRemittanceInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
111
    {
112 21
        if (false === isset($xmlDetail->RmtInf)) {
113 9
            return;
114
        }
115
116 18
        if (isset($xmlDetail->RmtInf->Ustrd)) {
117 9
            $remittanceInformation = DTO\RemittanceInformation::fromUnstructured(
118 9
                (string)$xmlDetail->RmtInf->Ustrd
119 9
            );
120 9
            $detail->setRemittanceInformation($remittanceInformation);
121
122 9
            return;
123
        }
124
125 9
        if (isset($xmlDetail->RmtInf->Strd)
126 9
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf)
127 9
            && isset($xmlDetail->RmtInf->Strd->CdtrRefInf->Ref)
128 9
        ) {
129 9
            $creditorReferenceInformation = DTO\CreditorReferenceInformation::fromUnstructured(
130 9
                (string)$xmlDetail->RmtInf->Strd->CdtrRefInf->Ref
131 9
            );
132 9
            $remittanceInformation = new DTO\RemittanceInformation();
133 9
            $remittanceInformation->setCreditorReferenceInformation($creditorReferenceInformation);
134 9
            $detail->setRemittanceInformation($remittanceInformation);
135 9
        }
136 9
    }
137
138
    /**
139
     * @param DTO\EntryTransactionDetail $detail
140
     * @param SimpleXMLElement           $xmlDetail
141
     */
142 20
    public function addReturnInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
143
    {
144 20
        if (isset($xmlDetail->RtrInf) && isset($xmlDetail->RtrInf->Rsn->Cd)) {
145 1
            $remittanceInformation = DTO\ReturnInformation::fromUnstructured(
146 1
                (string)$xmlDetail->RtrInf->Rsn->Cd,
147 1
                (string)$xmlDetail->RtrInf->AddtlInf
148 1
            );
149 1
            $detail->setReturnInformation($remittanceInformation);
150 1
        }
151 20
    }
152
153
    /**
154
     * @param DTO\EntryTransactionDetail $detail
155
     * @param SimpleXMLElement           $xmlDetail
156
     */
157 20
    public function addAdditionalTransactionInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
158
    {
159 20
        if (isset($xmlDetail->AddtlTxInf)) {
160 1
            $additionalInformation = new DTO\AdditionalTransactionInformation(
161 1
                (string) $xmlDetail->AddtlTxInf
162 1
            );
163 1
            $detail->setAdditionalTransactionInformation($additionalInformation);
164 1
        }
165 20
    }
166
167
    /**
168
     * @param DTO\EntryTransactionDetail $detail
169
     * @param SimpleXMLElement           $xmlDetail
170
     */
171
    public function addBankTransactionCode(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail)
172
    {
173
        $bankTransactionCode = new DTO\BankTransactionCode();
174
175
        if (isset($xmlDetail->BkTxCd)) {
176
            $bankTransactionCode = new DTO\BankTransactionCode();
177
178
            if (isset($xmlDetail->BkTxCd->Prtry)) {
179
                $proprietaryBankTransactionCode = new DTO\ProprietaryBankTransactionCode(
180
                    (string)$xmlDetail->BkTxCd->Prtry->Cd,
181
                    (string)$xmlDetail->BkTxCd->Prtry->Issr
182
                );
183
184
                $bankTransactionCode->setProprietary($proprietaryBankTransactionCode);
185
            }
186
        }
187
188
        $detail->setBankTransactionCode($bankTransactionCode);
189
    }
190
191
    /**
192
     * @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...
193
     *
194
     * @return DTO\Account|null
195
     */
196
    abstract public function getRelatedPartyAccount(SimpleXMLElement $xmlRelatedPartyTypeAccount);
197
}
198