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

Message::getAccount()   B

Complexity

Conditions 10
Paths 99

Size

Total Lines 38
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 12.0279

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 22
c 1
b 0
f 0
nc 99
nop 1
dl 0
loc 38
ccs 16
cts 22
cp 0.7272
crap 12.0279
rs 7.6666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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