Failed Conditions
Pull Request — master (#92)
by
unknown
08:11
created

Message::accountAddOwnerInfo()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
nc 16
nop 2
dl 0
loc 17
ccs 0
cts 12
cp 0
crap 30
rs 9.6111
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Genkgo\Camt\Decoder;
6
7
use Genkgo\Camt\Decoder\Factory\DTO as DTOFactory;
8
use Genkgo\Camt\DTO;
9
use SimpleXMLElement;
10
11
abstract class Message
12
{
13
    /**
14
     * @var Record
15
     */
16
    protected $recordDecoder;
17
18
    /**
19
     * @var DateDecoderInterface
20
     */
21
    protected $dateDecoder;
22
23
    /**
24
     * Message constructor.
25
     */
26 7
    public function __construct(Record $recordDecoder, DateDecoderInterface $dateDecoder)
27
    {
28 7
        $this->recordDecoder = $recordDecoder;
29 7
        $this->dateDecoder = $dateDecoder;
30 7
    }
31
32 3
    public function addGroupHeader(DTO\Message $message, SimpleXMLElement $document): void
33
    {
34 3
        $xmlGroupHeader = $this->getRootElement($document)->GrpHdr;
35 3
        $groupHeader = new DTO\GroupHeader(
36 3
            (string) $xmlGroupHeader->MsgId,
37 3
            $this->dateDecoder->decode((string) $xmlGroupHeader->CreDtTm)
38
        );
39
40 3
        if (isset($xmlGroupHeader->AddtlInf)) {
41
            $groupHeader->setAdditionalInformation((string) $xmlGroupHeader->AddtlInf);
42
        }
43
44 3
        if (isset($xmlGroupHeader->MsgRcpt)) {
45 1
            $groupHeader->setMessageRecipient(
46 1
                DTOFactory\Recipient::createFromXml($xmlGroupHeader->MsgRcpt)
47
            );
48
        }
49
50 3
        if (isset($xmlGroupHeader->MsgPgntn)) {
51
            $groupHeader->setPagination(new DTO\Pagination(
52
                (string) $xmlGroupHeader->MsgPgntn->PgNb,
53
                ('true' === (string) $xmlGroupHeader->MsgPgntn->LastPgInd) ? true : false
54
            ));
55
        }
56
57 3
        $message->setGroupHeader($groupHeader);
58 3
    }
59
60 3
    public function addCommonRecordInformation(DTO\Record $record, SimpleXMLElement $xmlRecord): void
61
    {
62 3
        if (isset($xmlRecord->ElctrncSeqNb)) {
63
            $record->setElectronicSequenceNumber((string) $xmlRecord->ElctrncSeqNb);
64
        }
65 3
        if (isset($xmlRecord->CpyDplctInd)) {
66
            $record->setCopyDuplicateIndicator((string) $xmlRecord->CpyDplctInd);
67
        }
68 3
        if (isset($xmlRecord->LglSeqNb)) {
69
            $record->setLegalSequenceNumber((string) $xmlRecord->LglSeqNb);
70
        }
71 3
        if (isset($xmlRecord->FrToDt)) {
72
            $record->setFromDate($this->dateDecoder->decode((string) $xmlRecord->FrToDt->FrDtTm));
73
            $record->setToDate($this->dateDecoder->decode((string) $xmlRecord->FrToDt->ToDtTm));
74
        }
75 3
    }
76
77
    abstract public function addRecords(DTO\Message $message, SimpleXMLElement $document): void;
78
79
    abstract public function getRootElement(SimpleXMLElement $document): SimpleXMLElement;
80
81
    protected function accountAddOwnerInfo(DTO\Account $account, SimpleXMLElement $acctOwnrElement): void
82
    {
83
        $owner = new DTO\AccountOwner();
84
        if ($acctOwnrElement->Id->OrgId->Othr->Id) {
85
            $owner->setId((string)$acctOwnrElement->Id->OrgId->Othr->Id);
86
        }
87
        if ($acctOwnrElement->Id->PrvtId->Othr->Id) {
88
            $owner->setId((string)$acctOwnrElement->Id->PrvtId->Othr->Id);
89
        }
90
        if ($acctOwnrElement->Nm) {
91
            $owner->setName((string)$acctOwnrElement->Nm);
92
        }
93
        if ($acctOwnrElement->PstlAdr) {
94
            $address = \Genkgo\Camt\Decoder\Factory\DTO\Address::createFromXml($acctOwnrElement->PstlAdr);
95
            $owner->setAddress($address);
96
        }
97
        $account->setOwner($owner);
98
    }
99
100
    protected function accountAddServicerInfo(DTO\Account $account, SimpleXMLElement $acctSvcrElement): void
101
    {
102
        $servicer = new DTO\AccountServicer();
103
        if ($acctSvcrElement->FinInstnId->Othr->Id) {
104
            $servicer->setId((string)$acctSvcrElement->FinInstnId->Othr->Id);
105
        }
106
        if ($acctSvcrElement->FinInstnId->BIC) {
107
            $servicer->setBic((string)$acctSvcrElement->FinInstnId->BIC);
108
        }
109
        if ($acctSvcrElement->FinInstnId->Nm) {
110
            $servicer->setName((string)$acctSvcrElement->FinInstnId->Nm);
111
        }
112
        if ($acctSvcrElement->FinInstnId->Othr->SchmeNm->Cd) {
113
            $servicer->setSchmeNm((string)$acctSvcrElement->FinInstnId->Othr->SchmeNm->Cd);
114
        }
115
116
        if ($acctSvcrElement->FinInstnId->PstlAdr) {
117
            $address = \Genkgo\Camt\Decoder\Factory\DTO\Address::createFromXml($acctSvcrElement->FinInstnId->PstlAdr);
118
            $servicer->setAddress($address);
119
        }
120
        $account->setServicer($servicer);
121
    }
122
}
123