Completed
Pull Request — master (#27)
by Yann
02:57
created

Message   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 80%

Importance

Changes 3
Bugs 0 Features 3
Metric Value
wmc 16
c 3
b 0
f 3
lcom 1
cbo 11
dl 0
loc 91
ccs 44
cts 55
cp 0.8
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B addRecords() 0 31 5
A getRootElement() 0 4 1
D getAccount() 0 39 10
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 \DateTimeImmutable;
10
use Genkgo\Camt\Iban;
11
12
class Message extends BaseMessageDecoder
13
{
14
    /**
15
     * @param DTO\Message      $message
16
     * @param SimpleXMLElement $document
17
     */
18 4
    public function addRecords(DTO\Message $message, SimpleXMLElement $document)
19
    {
20 4
        $notifications = [];
21
22 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...
23 4
        foreach ($xmlNotifications as $xmlNotification) {
24 4
            $notification = new Camt054DTO\Notification(
25 4
                (string) $xmlNotification->Id,
26 4
                new DateTimeImmutable((string)$xmlNotification->CreDtTm),
27 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...
28 4
            );
29
30 4
            if (isset($xmlNotification->NtfctnPgntn)) {
31 3
                $notification->setPagination(new DTO\Pagination(
32 3
                    (string) $xmlNotification->NtfctnPgntn->PgNb,
33 3
                    ('true' === (string) $xmlNotification->NtfctnPgntn->LastPgInd) ? true : false
34 3
                ));
35 3
            }
36
37 4
            if (isset($xmlNotification->AddtlNtfctnInf)) {
38 3
                $notification->setAdditionalInformation((string) $xmlNotification->AddtlNtfctnInf);
39 3
            }
40
41 4
            $this->addCommonRecordInformation($notification, $xmlNotification);
42 4
            $this->recordDecoder->addEntries($notification, $xmlNotification);
43
44 4
            $notifications[] = $notification;
45 4
        }
46
47 4
        $message->setRecords($notifications);
48 4
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 5
    public function getRootElement(SimpleXMLElement $document)
54
    {
55 5
        return $document->BkToCstmrDbtCdtNtfctn;
56
    }
57
58
    /**
59
     * @param SimpleXMLElement $xmlRecord
60
     *
61
     * @return DTO\Account
62
     */
63 4
    protected function getAccount(SimpleXMLElement $xmlRecord)
64 3
    {
65 4
        if (isset($xmlRecord->Acct->Id->IBAN)) {
66 3
            return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN));
67
        }
68
69 4
        if (isset($xmlRecord->Acct->Id->BBAN)) {
70
            return new DTO\BBANAccount((string) $xmlRecord->Acct->Id->BBAN);
71
        }
72
73 4
        if (isset($xmlRecord->Acct->Id->UPIC)) {
74 3
            return new DTO\UPICAccount((string) $xmlRecord->Acct->Id->UPIC);
75 3
        }
76
77 4
        if (isset($xmlRecord->Acct->Id->PrtryAcct)) {
78 1
            return new DTO\ProprietaryAccount((string) $xmlRecord->Acct->Id->PrtryAcct->Id);
79 3
        }
80
81 3
        if (isset($xmlRecord->Acct->Id->Othr)) {
82 3
            $xmlOtherIdentification = $xmlRecord->Acct->Id->Othr;
83 3
            $otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id);
84
85 3
            if (isset($xmlOtherIdentification->SchmeNm)) {
86
                if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
87
                    $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd);
88
                }
89
90
                if (isset($otherIdentification->SchmeNm->Prtry)) {
0 ignored issues
show
Bug introduced by
The variable $otherIdentification does not exist. Did you mean $xmlOtherIdentification?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
91
                    $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry);
92
                }
93
            }
94
95 3
            if (isset($xmlOtherIdentification->Issr)) {
96
                $otherAccount->setIssuer($xmlOtherIdentification->Issr);
97
            }
98
99 3
            return $otherAccount;
100 3
        }
101
    }
102
}
103