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

Message::getAccount()   B

Complexity

Conditions 9
Paths 88

Size

Total Lines 34
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 10.4768

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 19
c 1
b 0
f 0
nc 88
nop 1
dl 0
loc 34
ccs 14
cts 19
cp 0.7368
crap 10.4768
rs 8.0555
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
        if (isset($xmlRecord->Acct->Id->IBAN)) {
61 10
            $account = new DTO\IbanAccount(new Iban((string)$xmlRecord->Acct->Id->IBAN));
62
        } else {
63 7
            $xmlOtherIdentification = $xmlRecord->Acct->Id->Othr;
64 7
            $account = new DTO\OtherAccount((string)$xmlOtherIdentification->Id);
65
66 7
            if (isset($xmlOtherIdentification->SchmeNm)) {
67
                if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
68
                    $account->setSchemeName((string)$xmlOtherIdentification->SchmeNm->Cd);
69
                }
70
71
                if (isset($xmlOtherIdentification->SchmeNm->Prtry)) {
72
                    $account->setSchemeName((string)$xmlOtherIdentification->SchmeNm->Prtry);
73
                }
74
            }
75
76 7
            if (isset($xmlOtherIdentification->Issr)) {
77
                $account->setIssuer((string)$xmlOtherIdentification->Issr);
78
            }
79
        }
80
81 12
        if ($Ownr = data_get($xmlRecord, 'Acct.Ownr')) {
82 7
            $this->accountAddOwnerInfo($account, $Ownr);
83
        }
84 12
        if ($Svcr = data_get($xmlRecord, 'Acct.Svcr')) {
85 7
            $this->accountAddServicerInfo($account, $Svcr);
86
        }
87 12
        if ($Ccy = data_get($xmlRecord, 'Acct.Ccy')) {
88 10
            $account->setCurrency(new \Money\Currency((string)$Ccy));
89
        }
90
91 12
        return $account;
92
    }
93
}
94