1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Genkgo\Camt\Camt053\Decoder; |
4
|
|
|
|
5
|
|
|
use Genkgo\Camt\Camt053\DTO; |
6
|
|
|
use DateTimeImmutable; |
7
|
|
|
use SimpleXMLElement; |
8
|
|
|
use Genkgo\Camt\Iban; |
9
|
|
|
|
10
|
|
|
class Message |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Statement |
14
|
|
|
*/ |
15
|
|
|
private $statementDecoder; |
16
|
|
|
|
17
|
13 |
|
public function __construct(Statement $statementDecoder) |
18
|
|
|
{ |
19
|
13 |
|
$this->statementDecoder = $statementDecoder; |
20
|
13 |
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param DTO\Message $message |
24
|
|
|
* @param SimpleXMLElement $document |
25
|
|
|
*/ |
26
|
11 |
|
public function addGroupHeader(DTO\Message $message, SimpleXMLElement $document) |
27
|
|
|
{ |
28
|
11 |
|
$xmlGroupHeader = $document->BkToCstmrStmt->GrpHdr; |
29
|
11 |
|
$groupHeader = new DTO\GroupHeader( |
30
|
11 |
|
(string)$xmlGroupHeader->MsgId, |
31
|
11 |
|
new DateTimeImmutable((string)$xmlGroupHeader->CreDtTm) |
32
|
11 |
|
); |
33
|
|
|
|
34
|
11 |
|
$message->setGroupHeader($groupHeader); |
35
|
11 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param DTO\Message $message |
39
|
|
|
* @param SimpleXMLElement $document |
40
|
|
|
*/ |
41
|
11 |
|
public function addStatements(DTO\Message $message, SimpleXMLElement $document) |
42
|
10 |
|
{ |
43
|
11 |
|
$statements = []; |
44
|
|
|
|
45
|
11 |
|
$xmlStatements = $document->BkToCstmrStmt->Stmt; |
46
|
11 |
|
foreach ($xmlStatements as $xmlStatement) { |
47
|
11 |
|
$statement = new DTO\Statement( |
48
|
11 |
|
(string) $xmlStatement->Id, |
49
|
11 |
|
new DateTimeImmutable((string)$xmlStatement->CreDtTm), |
50
|
11 |
|
$this->getAccount($xmlStatement) |
51
|
11 |
|
); |
52
|
|
|
|
53
|
11 |
|
$this->statementDecoder->addBalances($statement, $xmlStatement); |
54
|
11 |
|
$this->statementDecoder->addEntries($statement, $xmlStatement); |
55
|
|
|
|
56
|
11 |
|
$statements[] = $statement; |
57
|
11 |
|
} |
58
|
|
|
|
59
|
11 |
|
$message->setStatements($statements); |
60
|
11 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param SimpleXMLElement $xmlStatement |
64
|
|
|
* |
65
|
|
|
* @return DTO\Account |
66
|
|
|
*/ |
67
|
11 |
|
private function getAccount(SimpleXMLElement $xmlStatement) |
68
|
|
|
{ |
69
|
11 |
|
if (isset($xmlStatement->Acct->Id->IBAN)) { |
70
|
9 |
|
return new DTO\IbanAccount(new Iban((string) $xmlStatement->Acct->Id->IBAN)); |
71
|
|
|
} |
72
|
|
|
|
73
|
7 |
|
$xmlOtherIdentification = $xmlStatement->Acct->Id->Othr; |
74
|
10 |
|
$otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id); |
75
|
|
|
|
76
|
10 |
|
if (isset($xmlOtherIdentification->SchmeNm)) { |
77
|
10 |
|
if (isset($xmlOtherIdentification->SchmeNm->Cd)) { |
78
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd); |
79
|
10 |
|
} |
80
|
|
|
|
81
|
|
|
if (isset($otherIdentification->SchmeNm->Prtry)) { |
|
|
|
|
82
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
7 |
|
if (isset($xmlOtherIdentification->Issr)) { |
87
|
|
|
$otherAccount->setIssuer($xmlOtherIdentification->Issr); |
88
|
|
|
} |
89
|
|
|
|
90
|
7 |
|
return $otherAccount; |
91
|
8 |
|
} |
92
|
|
|
} |
93
|
|
|
|
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.