Failed Conditions
Pull Request — master (#92)
by
unknown
02:39
created

Message::accountAddOwnerInfo()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.3906

Importance

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