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

Message::addGroupHeader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
crap 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