Failed Conditions
Pull Request — master (#92)
by
unknown
03:25
created

Message   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 43
c 2
b 0
f 0
dl 0
loc 83
ccs 39
cts 45
cp 0.8667
rs 10
wmc 16

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRootElement() 0 3 1
B getAccount() 0 38 10
A addRecords() 0 33 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Genkgo\Camt\Camt053\Decoder;
6
7
use Genkgo\Camt\Camt053\DTO as Camt053DTO;
8
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder;
9
use Genkgo\Camt\DTO;
10
use SimpleXMLElement;
11
use Genkgo\Camt\Iban;
12
13
class Message extends BaseMessageDecoder
14
{
15 12
    public function addRecords(DTO\Message $message, SimpleXMLElement $document): void
16
    {
17 12
        $statements = [];
18
19 12
        $xmlStatements = $this->getRootElement($document)->Stmt;
20 12
        foreach ($xmlStatements as $xmlStatement) {
21 12
            $statement = new Camt053DTO\Statement(
22 12
                (string)$xmlStatement->Id,
23 12
                $this->dateDecoder->decode((string)$xmlStatement->CreDtTm),
24 12
                $this->getAccount($xmlStatement)
25
            );
26
27 12
            if (isset($xmlStatement->StmtPgntn)) {
28 6
                $statement->setPagination(
29 6
                    new DTO\Pagination(
30 6
                        (string)$xmlStatement->StmtPgntn->PgNb,
31 6
                        ('true' === (string)$xmlStatement->StmtPgntn->LastPgInd) ? true : false
32
                    )
33
                );
34
            }
35
36 12
            if (isset($xmlStatement->AddtlStmtInf)) {
37 11
                $statement->setAdditionalInformation((string)$xmlStatement->AddtlStmtInf);
38
            }
39
40 12
            $this->addCommonRecordInformation($statement, $xmlStatement);
41 12
            $this->recordDecoder->addBalances($statement, $xmlStatement);
42 12
            $this->recordDecoder->addEntries($statement, $xmlStatement);
43
44 12
            $statements[] = $statement;
45
        }
46
47 12
        $message->setRecords($statements);
48 12
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 13
    public function getRootElement(SimpleXMLElement $document): SimpleXMLElement
54
    {
55 13
        return $document->BkToCstmrStmt;
56
    }
57
58 12
    protected function getAccount(SimpleXMLElement $xmlRecord): DTO\Account
59
    {
60 12
        $account = null;
61 12
        if (isset($xmlRecord->Acct->Id->IBAN)) {
62 10
            $account = new DTO\IbanAccount(new Iban((string)$xmlRecord->Acct->Id->IBAN));
63
        } else {
64 7
            $xmlOtherIdentification = $xmlRecord->Acct->Id->Othr;
65 7
            $account = new DTO\OtherAccount((string)$xmlOtherIdentification->Id);
66
67 7
            if (isset($xmlOtherIdentification->SchmeNm)) {
68
                if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
69
                    $account->setSchemeName((string)$xmlOtherIdentification->SchmeNm->Cd);
70
                }
71
72
                if (isset($xmlOtherIdentification->SchmeNm->Prtry)) {
73
                    $account->setSchemeName((string)$xmlOtherIdentification->SchmeNm->Prtry);
74
                }
75
            }
76
77 7
            if (isset($xmlOtherIdentification->Issr)) {
78
                $account->setIssuer((string)$xmlOtherIdentification->Issr);
79
            }
80
        }
81
82 12
        if ($account instanceof DTO\Account) {
0 ignored issues
show
introduced by
$account is always a sub-type of Genkgo\Camt\DTO\Account.
Loading history...
83 12
            if ($xmlRecord->Acct->Ownr) {
84 7
                $this->accountAddOwnerInfo($account, $xmlRecord->Acct->Ownr);
85
            }
86 12
            if ($xmlRecord->Acct->Svcr) {
87 7
                $this->accountAddServicerInfo($account, $xmlRecord->Acct->Svcr);
88
            }
89 12
            if ($xmlRecord->Acct->Ccy) {
90 10
                $account->setCurrency(new \Money\Currency((string)$xmlRecord->Acct->Ccy));
91
            }
92 12
            return $account;
93
        }
94
95
        return $account;
96
    }
97
}
98