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

Message   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 80.95%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
c 1
b 0
f 0
dl 0
loc 91
ccs 34
cts 42
cp 0.8095
rs 10
wmc 16

3 Methods

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