Completed
Pull Request — master (#24)
by Yann
08:06
created

Message::getRootElement()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
3
namespace Genkgo\Camt\Decoder;
4
5
use DateTimeImmutable;
6
use SimpleXMLElement;
7
use Genkgo\Camt\DTO;
8
use Genkgo\Camt\Iban;
9
10
abstract class Message
11
{
12
    /**
13
     * @var Record
14
     */
15
    protected $recordDecoder;
16
17 23
    public function __construct(Record $recordDecoder)
18
    {
19 23
        $this->recordDecoder = $recordDecoder;
20 23
    }
21
22
    /**
23
     * @param DTO\Message      $message
24
     * @param SimpleXMLElement $document
25
     */
26 19
    public function addGroupHeader(DTO\Message $message, SimpleXMLElement $document)
27
    {
28 19
        $xmlGroupHeader = $this->getRootElement($document)->GrpHdr;
0 ignored issues
show
Bug introduced by
The property GrpHdr does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
29 19
        $groupHeader = new DTO\GroupHeader(
30 19
            (string)$xmlGroupHeader->MsgId,
31 19
            new DateTimeImmutable((string)$xmlGroupHeader->CreDtTm)
32 19
        );
33
34 19
        $message->setGroupHeader($groupHeader);
35 19
    }
36
37
    /**
38
     * @param DTO\Record       $record
39
     * @param SimpleXMLElement $xmlRecord
40
     */
41 19
    public function addCommonRecordInformation(DTO\Record $record, SimpleXMLElement $xmlRecord)
42
    {
43 19
        if (isset($xmlRecord->ElctrncSeqNb)) {
44 16
            $record->setElectronicSequenceNumber((string) $xmlRecord->ElctrncSeqNb);
45 16
        }
46 19
        if (isset($xmlRecord->CpyDplctInd)) {
47 16
            $record->setCopyDuplicateIndicator((string) $xmlRecord->CpyDplctInd);
48 16
        }
49 19
        if (isset($xmlRecord->LglSeqNb)) {
50 16
            $record->setLegalSequenceNumber((string) $xmlRecord->LglSeqNb);
51 16
        }
52 19
        if (isset($xmlRecord->FrToDt)) {
53 15
            $record->setFromDate(new DateTimeImmutable((string) $xmlRecord->FrToDt->FrDtTm));
54 15
            $record->setToDate(new DateTimeImmutable((string) $xmlRecord->FrToDt->ToDtTm));
55 15
        }
56 19
    }
57
58
    /**
59
     * @param DTO\Message      $message
60
     * @param SimpleXMLElement $document
61
     */
62
    abstract public function addRecords(DTO\Message $message, SimpleXMLElement $document);
63
64
    /**
65
     * @param SimpleXMLElement $document
66
     *
67
     * @return SimpleXMLElement
68
     */
69
    abstract public function getRootElement(SimpleXMLElement $document);
70
}
71