Completed
Push — master ( a4151f...f7c7ac )
by Frederik
03:04
created

Message::getRootElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Genkgo\Camt\Camt054\Decoder;
4
5
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder;
6
use Genkgo\Camt\Camt054\DTO as Camt054DTO;
7
use Genkgo\Camt\DTO;
8
use \SimpleXMLElement;
9
use Genkgo\Camt\Iban;
10
11
class Message extends BaseMessageDecoder
12
{
13
    /**
14
     * @param DTO\Message      $message
15
     * @param SimpleXMLElement $document
16
     */
17 4
    public function addRecords(DTO\Message $message, SimpleXMLElement $document)
18
    {
19 4
        $notifications = [];
20
21 4
        $xmlNotifications = $this->getRootElement($document)->Ntfctn;
0 ignored issues
show
Bug introduced by
The property Ntfctn 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...
22 4
        foreach ($xmlNotifications as $xmlNotification) {
23 4
            $notification = new Camt054DTO\Notification(
24 4
                (string) $xmlNotification->Id,
25 4
                $this->dateDecoder->decode((string)$xmlNotification->CreDtTm),
26 4
                $this->getAccount($xmlNotification)
0 ignored issues
show
Bug introduced by
It seems like $this->getAccount($xmlNotification) targeting Genkgo\Camt\Camt054\Decoder\Message::getAccount() can also be of type null; however, Genkgo\Camt\DTO\Record::__construct() does only seem to accept object<Genkgo\Camt\DTO\Account>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
27
            );
28
29 4
            if (isset($xmlNotification->NtfctnPgntn)) {
30 3
                $notification->setPagination(new DTO\Pagination(
31 3
                    (string) $xmlNotification->NtfctnPgntn->PgNb,
32 3
                    ('true' === (string) $xmlNotification->NtfctnPgntn->LastPgInd) ? true : false
33
                ));
34
            }
35
36 4
            if (isset($xmlNotification->AddtlNtfctnInf)) {
37 3
                $notification->setAdditionalInformation((string) $xmlNotification->AddtlNtfctnInf);
38
            }
39
40 4
            $this->addCommonRecordInformation($notification, $xmlNotification);
41 4
            $this->recordDecoder->addEntries($notification, $xmlNotification);
42
43 4
            $notifications[] = $notification;
44
        }
45
46 4
        $message->setRecords($notifications);
47 4
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 5
    public function getRootElement(SimpleXMLElement $document)
53
    {
54 5
        return $document->BkToCstmrDbtCdtNtfctn;
55
    }
56
57
    /**
58
     * @param SimpleXMLElement $xmlRecord
59
     *
60
     * @return DTO\Account
61
     */
62 4
    protected function getAccount(SimpleXMLElement $xmlRecord)
63
    {
64 4
        if (isset($xmlRecord->Acct->Id->IBAN)) {
65 3
            return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN));
66
        }
67
68 4
        if (isset($xmlRecord->Acct->Id->BBAN)) {
69
            return new DTO\BBANAccount((string) $xmlRecord->Acct->Id->BBAN);
70
        }
71
72 4
        if (isset($xmlRecord->Acct->Id->UPIC)) {
73
            return new DTO\UPICAccount((string) $xmlRecord->Acct->Id->UPIC);
74
        }
75
76 4
        if (isset($xmlRecord->Acct->Id->PrtryAcct)) {
77 1
            return new DTO\ProprietaryAccount((string) $xmlRecord->Acct->Id->PrtryAcct->Id);
78
        }
79
80 3
        if (isset($xmlRecord->Acct->Id->Othr)) {
81 3
            $xmlOtherIdentification = $xmlRecord->Acct->Id->Othr;
82 3
            $otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id);
83
84 3
            if (isset($xmlOtherIdentification->SchmeNm)) {
85
                if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
86
                    $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd);
87
                }
88
89
                if (isset($xmlOtherIdentification->SchmeNm->Prtry)) {
90
                    $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry);
91
                }
92
            }
93
94 3
            if (isset($xmlOtherIdentification->Issr)) {
95
                $otherAccount->setIssuer($xmlOtherIdentification->Issr);
96
            }
97
98 3
            return $otherAccount;
99
        }
100
    }
101
}
102