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
|
11 |
|
public function addReferences(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail) |
16
|
|
|
{ |
17
|
11 |
|
if (false === isset($xmlDetail->Refs->EndToEndId)) { |
18
|
3 |
|
return; |
19
|
|
|
} |
20
|
|
|
|
21
|
8 |
|
$endToEndId = (string)$xmlDetail->Refs->EndToEndId; |
22
|
9 |
|
$mandateId = null; |
23
|
|
|
|
24
|
8 |
|
if (isset($xmlDetail->Refs->MndtId)) { |
25
|
1 |
|
$mandateId = (string)$xmlDetail->Refs->MndtId; |
26
|
1 |
|
} |
27
|
|
|
|
28
|
8 |
|
$detail->addReference(new DTO\Reference($endToEndId, $mandateId)); |
29
|
8 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param DTO\EntryTransactionDetail $detail |
33
|
|
|
* @param SimpleXMLElement $xmlDetail |
34
|
|
|
*/ |
35
|
11 |
|
public function addRelatedParties(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail) |
36
|
|
|
{ |
37
|
11 |
|
if (false === isset($xmlDetail->RltdPties)) { |
38
|
1 |
|
return; |
39
|
|
|
} |
40
|
|
|
|
41
|
10 |
|
foreach ($xmlDetail->RltdPties as $xmlRelatedParty) { |
42
|
10 |
|
if (isset($xmlRelatedParty->Cdtr)) { |
43
|
10 |
|
$xmlRelatedPartyType = $xmlRelatedParty->Cdtr; |
44
|
10 |
|
$xmlRelatedPartyTypeAccount = $xmlRelatedParty->CdtrAcct; |
45
|
10 |
|
$relatedPartyType = $creditor = new DTO\Creditor((string) $xmlRelatedPartyType->Nm); |
|
|
|
|
46
|
10 |
|
} elseif (isset($xmlRelatedParty->Dbtr)) { |
47
|
|
|
$xmlRelatedPartyType = $xmlRelatedParty->Dbtr; |
48
|
|
|
$xmlRelatedPartyTypeAccount = $xmlRelatedParty->DbtrAcct; |
49
|
|
|
$relatedPartyType = $creditor = new DTO\Debtor((string) $xmlRelatedPartyType->Nm); |
|
|
|
|
50
|
|
|
} else { |
51
|
|
|
continue; |
52
|
|
|
} |
53
|
|
|
|
54
|
10 |
|
if (isset($xmlRelatedPartyType->PstlAdr)) { |
55
|
8 |
|
$address = new DTO\Address(); |
56
|
8 |
|
if (isset($xmlRelatedPartyType->PstlAdr->Ctry)) { |
57
|
8 |
|
$address = $address->setCountry((string) $xmlRelatedPartyType->PstlAdr->Ctry); |
58
|
8 |
|
} |
59
|
8 |
|
if (isset($xmlRelatedPartyType->PstlAdr->AdrLine)) { |
60
|
1 |
|
foreach ($xmlRelatedPartyType->PstlAdr->AdrLine as $line) { |
61
|
1 |
|
$address = $address->addAddressLine((string)$line); |
62
|
1 |
|
} |
63
|
1 |
|
} |
64
|
|
|
|
65
|
8 |
|
$relatedPartyType->setAddress($address); |
66
|
8 |
|
} |
67
|
|
|
|
68
|
10 |
|
$acount = null; |
|
|
|
|
69
|
10 |
|
if (isset($xmlRelatedPartyTypeAccount->Id->IBAN) && $ibanCode = (string) $xmlRelatedPartyTypeAccount->Id->IBAN) { |
70
|
10 |
|
$account = new DTO\Account(new Iban($ibanCode)); |
71
|
10 |
|
} |
72
|
|
|
|
73
|
10 |
|
$relatedParty = new DTO\RelatedParty($relatedPartyType, $account); |
|
|
|
|
74
|
10 |
|
$detail->addRelatedParty($relatedParty); |
75
|
10 |
|
} |
76
|
10 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param DTO\EntryTransactionDetail $detail |
80
|
|
|
* @param SimpleXMLElement $xmlDetail |
81
|
|
|
*/ |
82
|
12 |
|
public function addRemittanceInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail) |
83
|
|
|
{ |
84
|
12 |
|
if (false === isset($xmlDetail->RmtInf)) { |
85
|
1 |
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
11 |
|
if (isset($xmlDetail->RmtInf->Ustrd)) { |
89
|
8 |
|
$remittanceInformation = DTO\RemittanceInformation::fromUnstructured( |
90
|
8 |
|
(string)$xmlDetail->RmtInf->Ustrd |
91
|
8 |
|
); |
92
|
8 |
|
$detail->setRemittanceInformation($remittanceInformation); |
93
|
|
|
|
94
|
8 |
|
return; |
95
|
|
|
} |
96
|
|
|
|
97
|
3 |
|
if (isset($xmlDetail->RmtInf->Strd) |
98
|
3 |
|
&& isset($xmlDetail->RmtInf->Strd->CdtrRefInf) |
99
|
3 |
|
&& isset($xmlDetail->RmtInf->Strd->CdtrRefInf->Ref) |
100
|
3 |
|
) { |
101
|
3 |
|
$creditorReferenceInformation = DTO\CreditorReferenceInformation::fromUnstructured( |
102
|
3 |
|
(string)$xmlDetail->RmtInf->Strd->CdtrRefInf->Ref |
103
|
3 |
|
); |
104
|
3 |
|
$remittanceInformation = new DTO\RemittanceInformation(); |
105
|
3 |
|
$remittanceInformation->setCreditorReferenceInformation($creditorReferenceInformation); |
106
|
3 |
|
$detail->setRemittanceInformation($remittanceInformation); |
107
|
3 |
|
} |
108
|
3 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param DTO\EntryTransactionDetail $detail |
112
|
|
|
* @param SimpleXMLElement $xmlDetail |
113
|
|
|
*/ |
114
|
11 |
|
public function addReturnInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail) |
115
|
|
|
{ |
116
|
11 |
|
if (isset($xmlDetail->RtrInf) && isset($xmlDetail->RtrInf->Rsn->Cd)) { |
117
|
1 |
|
$remittanceInformation = DTO\ReturnInformation::fromUnstructured( |
118
|
1 |
|
(string)$xmlDetail->RtrInf->Rsn->Cd, |
119
|
1 |
|
(string)$xmlDetail->RtrInf->AddtlInf |
120
|
1 |
|
); |
121
|
1 |
|
$detail->setReturnInformation($remittanceInformation); |
122
|
1 |
|
} |
123
|
11 |
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param DTO\EntryTransactionDetail $detail |
127
|
|
|
* @param SimpleXMLElement $xmlDetail |
128
|
|
|
*/ |
129
|
11 |
|
public function addAdditionalTransactionInformation(DTO\EntryTransactionDetail $detail, SimpleXMLElement $xmlDetail) |
130
|
|
|
{ |
131
|
11 |
|
if (isset($xmlDetail->AddtlTxInf)) { |
132
|
1 |
|
$additionalInformation = new DTO\AdditionalTransactionInformation( |
133
|
1 |
|
(string) $xmlDetail->AddtlTxInf |
134
|
1 |
|
); |
135
|
1 |
|
$detail->setAdditionalTransactionInformation($additionalInformation); |
136
|
1 |
|
} |
137
|
11 |
|
} |
138
|
|
|
} |
139
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.