Message::addGroupHeader()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 14
nc 8
nop 2
dl 0
loc 26
ccs 16
cts 16
cp 1
crap 5
rs 9.4888
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
    protected Record $recordDecoder;
14
15
    protected DateDecoderInterface $dateDecoder;
16
17
    /**
18
     * Message constructor.
19
     */
20
    public function __construct(Record $recordDecoder, DateDecoderInterface $dateDecoder)
21
    {
22
        $this->recordDecoder = $recordDecoder;
23
        $this->dateDecoder = $dateDecoder;
24
    }
25
26 29
    public function addGroupHeader(DTO\Message $message, SimpleXMLElement $document): void
27
    {
28 29
        $xmlGroupHeader = $this->getRootElement($document)->GrpHdr;
29 29
        $groupHeader = new DTO\GroupHeader(
30 29
            (string) $xmlGroupHeader->MsgId,
31
            $this->dateDecoder->decode((string) $xmlGroupHeader->CreDtTm)
32 25
        );
33
34 25
        if (isset($xmlGroupHeader->AddtlInf)) {
35 25
            $groupHeader->setAdditionalInformation((string) $xmlGroupHeader->AddtlInf);
36 25
        }
37 25
38
        if (isset($xmlGroupHeader->MsgRcpt)) {
39
            $groupHeader->setMessageRecipient(
40 25
                DTOFactory\Recipient::createFromXml($xmlGroupHeader->MsgRcpt)
41 21
            );
42
        }
43
44 25
        if (isset($xmlGroupHeader->MsgPgntn)) {
45 23
            $groupHeader->setPagination(new DTO\Pagination(
46 23
                (string) $xmlGroupHeader->MsgPgntn->PgNb,
47
                ('true' === (string) $xmlGroupHeader->MsgPgntn->LastPgInd) ? true : false
48
            ));
49
        }
50 25
51 17
        $message->setGroupHeader($groupHeader);
52 17
    }
53 17
54
    public function addCommonRecordInformation(DTO\Record $record, SimpleXMLElement $xmlRecord): void
55
    {
56
        if (isset($xmlRecord->ElctrncSeqNb)) {
57 25
            $record->setElectronicSequenceNumber((string) $xmlRecord->ElctrncSeqNb);
58 25
        }
59
        if (isset($xmlRecord->CpyDplctInd)) {
60 25
            $record->setCopyDuplicateIndicator((string) $xmlRecord->CpyDplctInd);
61
        }
62 25
        if (isset($xmlRecord->LglSeqNb)) {
63 22
            $record->setLegalSequenceNumber((string) $xmlRecord->LglSeqNb);
64
        }
65 25
        if (isset($xmlRecord->FrToDt)) {
66 22
            $record->setFromDate($this->dateDecoder->decode((string) $xmlRecord->FrToDt->FrDtTm));
67
            $record->setToDate($this->dateDecoder->decode((string) $xmlRecord->FrToDt->ToDtTm));
68 25
        }
69 22
    }
70
71 25
    abstract public function addRecords(DTO\Message $message, SimpleXMLElement $document): void;
72 21
73 21
    abstract public function getRootElement(SimpleXMLElement $document): SimpleXMLElement;
74
}
75