1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Genkgo\Camt\Camt052\Decoder; |
4
|
|
|
|
5
|
|
|
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder; |
6
|
|
|
use Genkgo\Camt\Camt052\DTO as Camt052DTO; |
7
|
|
|
use Genkgo\Camt\DTO; |
8
|
|
|
use \SimpleXMLElement; |
9
|
|
|
use \DateTimeImmutable; |
10
|
|
|
|
11
|
|
|
class Message extends BaseMessageDecoder |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param DTO\Message $message |
15
|
|
|
* @param SimpleXMLElement $document |
16
|
|
|
*/ |
17
|
4 |
|
public function addGroupHeader(DTO\Message $message, SimpleXMLElement $document) |
18
|
|
|
{ |
19
|
4 |
|
$xmlGroupHeader = $document->BkToCstmrAcctRptV01->GrpHdr; |
20
|
4 |
|
$groupHeader = new DTO\GroupHeader( |
21
|
4 |
|
(string)$xmlGroupHeader->MsgId, |
22
|
4 |
|
new DateTimeImmutable((string)$xmlGroupHeader->CreDtTm) |
23
|
4 |
|
); |
24
|
|
|
|
25
|
4 |
|
$message->setGroupHeader($groupHeader); |
26
|
4 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param DTO\Message $message |
30
|
|
|
* @param SimpleXMLElement $document |
31
|
|
|
*/ |
32
|
4 |
|
public function addRecords(DTO\Message $message, SimpleXMLElement $document) |
33
|
|
|
{ |
34
|
4 |
|
$reports = []; |
35
|
|
|
|
36
|
4 |
|
$xmlReports = $document->BkToCstmrAcctRptV01->Rpt; |
37
|
4 |
|
foreach ($xmlReports as $xmlReport) { |
38
|
4 |
|
$report = new Camt052DTO\Report( |
39
|
4 |
|
(string) $xmlReport->Id, |
40
|
4 |
|
new DateTimeImmutable((string)$xmlReport->CreDtTm), |
41
|
4 |
|
$this->getAccount($xmlReport) |
|
|
|
|
42
|
4 |
|
); |
43
|
|
|
|
44
|
4 |
|
$this->recordDecoder->addBalances($report, $xmlReport); |
45
|
4 |
|
$this->recordDecoder->addEntries($report, $xmlReport); |
46
|
|
|
|
47
|
4 |
|
$reports[] = $report; |
48
|
4 |
|
} |
49
|
|
|
|
50
|
4 |
|
$message->setRecords($reports); |
51
|
4 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param SimpleXMLElement $xmlRecord |
55
|
|
|
* |
56
|
|
|
* @return DTO\Account |
57
|
|
|
*/ |
58
|
4 |
|
protected function getAccount(SimpleXMLElement $xmlRecord) |
59
|
|
|
{ |
60
|
4 |
|
if (isset($xmlRecord->Acct->Id->IBAN)) { |
61
|
|
|
return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN)); |
62
|
|
|
} |
63
|
|
|
|
64
|
4 |
|
if (isset($xmlRecord->Acct->Id->BBAN)) { |
65
|
|
|
return new Camt052DTO\BBANAccount((string) $xmlRecord->Acct->Id->BBAN); |
66
|
|
|
} |
67
|
|
|
|
68
|
4 |
|
if (isset($xmlRecord->Acct->Id->UPIC)) { |
69
|
|
|
return new Camt052DTO\UPICAccount((string) $xmlRecord->Acct->Id->UPIC); |
70
|
|
|
} |
71
|
|
|
|
72
|
4 |
|
if (isset($xmlRecord->Acct->Id->PrtryAcct)) { |
73
|
4 |
|
return new Camt052DTO\ProprietaryAccount((string) $xmlRecord->Acct->Id->PrtryAcct->Id); |
74
|
3 |
|
} |
75
|
3 |
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.