Completed
Push — master ( ee61c0...1ce428 )
by Adrien
03:11
created

Message   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 80.48%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
c 1
b 0
f 0
dl 0
loc 84
ccs 33
cts 41
cp 0.8048
rs 10
wmc 15

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addRecords() 0 31 5
B getAccount() 0 40 10
1
<?php
2
3
namespace Genkgo\Camt\Camt052\Decoder;
4
5
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder;
6
use Genkgo\Camt\DTO;
7
use Genkgo\Camt\Camt052\DTO as Camt052DTO;
8
use \SimpleXMLElement;
9
use Genkgo\Camt\Iban;
10
11
abstract class Message extends BaseMessageDecoder
12
{
13
    /**
14
     * @param DTO\Message      $message
15
     * @param SimpleXMLElement $document
16
     */
17 8
    public function addRecords(DTO\Message $message, SimpleXMLElement $document)
18
    {
19 8
        $reports = [];
20
21 8
        $xmlReports = $this->getRootElement($document)->Rpt;
22 8
        foreach ($xmlReports as $xmlReport) {
23 8
            $report = new Camt052DTO\Report(
24 8
                (string) $xmlReport->Id,
25 8
                $this->dateDecoder->decode((string)$xmlReport->CreDtTm),
26 8
                $this->getAccount($xmlReport)
27
            );
28
29 8
            if (isset($xmlReport->RptPgntn)) {
30 3
                $report->setPagination(new DTO\Pagination(
31 3
                    (string) $xmlReport->RptPgntn->PgNb,
32 3
                    ('true' === (string) $xmlReport->RptPgntn->LastPgInd) ? true : false
33
                ));
34
            }
35
36 8
            if (isset($xmlReport->AddtlRptInf)) {
37 7
                $report->setAdditionalInformation((string) $xmlReport->AddtlRptInf);
38
            }
39
40 8
            $this->addCommonRecordInformation($report, $xmlReport);
41 8
            $this->recordDecoder->addBalances($report, $xmlReport);
42 8
            $this->recordDecoder->addEntries($report, $xmlReport);
43
44 8
            $reports[] = $report;
45
        }
46
47 8
        $message->setRecords($reports);
48 8
    }
49
50
    /**
51
     * @param SimpleXMLElement $xmlRecord
52
     *
53
     * @return null|DTO\Account
54
     */
55 8
    protected function getAccount(SimpleXMLElement $xmlRecord)
56
    {
57 8
        if (isset($xmlRecord->Acct->Id->IBAN)) {
58 3
            return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN));
59
        }
60
61 8
        if (isset($xmlRecord->Acct->Id->BBAN)) {
62
            return new DTO\BBANAccount((string) $xmlRecord->Acct->Id->BBAN);
63
        }
64
65 8
        if (isset($xmlRecord->Acct->Id->UPIC)) {
66
            return new DTO\UPICAccount((string) $xmlRecord->Acct->Id->UPIC);
67
        }
68
69 8
        if (isset($xmlRecord->Acct->Id->PrtryAcct)) {
70 4
            return new DTO\ProprietaryAccount((string) $xmlRecord->Acct->Id->PrtryAcct->Id);
71
        }
72
73 7
        if (isset($xmlRecord->Acct->Id->Othr)) {
74 7
            $xmlOtherIdentification = $xmlRecord->Acct->Id->Othr;
75 7
            $otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id);
76
77 7
            if (isset($xmlOtherIdentification->SchmeNm)) {
78
                if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
79
                    $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd);
80
                }
81
82
                if (isset($xmlOtherIdentification->SchmeNm->Prtry)) {
83
                    $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry);
84
                }
85
            }
86
87 7
            if (isset($xmlOtherIdentification->Issr)) {
88
                $otherAccount->setIssuer($xmlOtherIdentification->Issr);
89
            }
90
91 7
            return $otherAccount;
92
        }
93
94
        return null;
95
    }
96
}
97