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

Message   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 1
cbo 9
dl 0
loc 78
ccs 30
cts 35
cp 0.8571
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRootElement() 0 4 1
B addRecords() 0 32 5
B getAccount() 0 25 6
1
<?php
2
3
namespace Genkgo\Camt\Camt053\Decoder;
4
5
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder;
6
use Genkgo\Camt\Camt053\DTO as Camt053DTO;
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 11
    public function addRecords(DTO\Message $message, SimpleXMLElement $document)
18
    {
19 11
        $statements = [];
20
21 11
        $xmlStatements = $this->getRootElement($document)->Stmt;
0 ignored issues
show
Bug introduced by
The property Stmt 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 11
        foreach ($xmlStatements as $xmlStatement) {
23 11
            $statement = new Camt053DTO\Statement(
24 11
                (string) $xmlStatement->Id,
25 11
                $this->dateDecoder->decode((string)$xmlStatement->CreDtTm),
26 11
                $this->getAccount($xmlStatement)
27
            );
28
29 11
            if (isset($xmlStatement->StmtPgntn)) {
30 6
                $statement->setPagination(new DTO\Pagination(
31 6
                    (string) $xmlStatement->StmtPgntn->PgNb,
32 6
                    ('true' === (string) $xmlStatement->StmtPgntn->LastPgInd) ? true : false
33
                ));
34
            }
35
36 11
            if (isset($xmlStatement->AddtlStmtInf)) {
37 10
                $statement->setAdditionalInformation((string) $xmlStatement->AddtlStmtInf);
38
            }
39
40 11
            $this->addCommonRecordInformation($statement, $xmlStatement);
41 11
            $this->recordDecoder->addBalances($statement, $xmlStatement);
42 11
            $this->recordDecoder->addEntries($statement, $xmlStatement);
43
44 11
            $statements[] = $statement;
45
        }
46
47 11
        $message->setRecords($statements);
48 11
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 12
    public function getRootElement(SimpleXMLElement $document)
54
    {
55 12
        return $document->BkToCstmrStmt;
56
    }
57
58
    /**
59
     * @param SimpleXMLElement $xmlRecord
60
     *
61
     * @return DTO\Account
62
     */
63 11
    protected function getAccount(SimpleXMLElement $xmlRecord)
64
    {
65 11
        if (isset($xmlRecord->Acct->Id->IBAN)) {
66 9
            return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN));
67
        }
68
69 7
        $xmlOtherIdentification = $xmlRecord->Acct->Id->Othr;
70 7
        $otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id);
71
72 7
        if (isset($xmlOtherIdentification->SchmeNm)) {
73
            if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
74
                $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd);
75
            }
76
77
            if (isset($xmlOtherIdentification->SchmeNm->Prtry)) {
78
                $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry);
79
            }
80
        }
81
82 7
        if (isset($xmlOtherIdentification->Issr)) {
83
            $otherAccount->setIssuer($xmlOtherIdentification->Issr);
84
        }
85
86 7
        return $otherAccount;
87
    }
88
}
89