Completed
Pull Request — master (#32)
by
unknown
04:50
created

Message   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 1 Features 5
Metric Value
wmc 12
c 8
b 1
f 5
lcom 1
cbo 8
dl 0
loc 78
ccs 30
cts 30
cp 1
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 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 11
    public function addRecords(DTO\Message $message, SimpleXMLElement $document)
19
    {
20 11
        $statements = [];
21
22 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...
23 11
        foreach ($xmlStatements as $xmlStatement) {
24 11
            $statement = new Camt053DTO\Statement(
25 11
                (string) $xmlStatement->Id,
26 11
                new DateTimeImmutable((string)$xmlStatement->CreDtTm),
27 11
                $this->getAccount($xmlStatement)
28
            );
29
30 11
            if (isset($xmlStatement->StmtPgntn)) {
31 6
                $statement->setPagination(new DTO\Pagination(
32 6
                    (string) $xmlStatement->StmtPgntn->PgNb,
33 6
                    ('true' === (string) $xmlStatement->StmtPgntn->LastPgInd) ? true : false
34
                ));
35
            }
36
37 11
            if (isset($xmlStatement->AddtlStmtInf)) {
38 10
                $statement->setAdditionalInformation((string) $xmlStatement->AddtlStmtInf);
39
            }
40
41 11
            $this->addCommonRecordInformation($statement, $xmlStatement);
42 11
            $this->recordDecoder->addBalances($statement, $xmlStatement);
43 11
            $this->recordDecoder->addEntries($statement, $xmlStatement);
44
45 11
            $statements[] = $statement;
46
        }
47
48 11
        $message->setRecords($statements);
49 11
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 12
    public function getRootElement(SimpleXMLElement $document)
55
    {
56 12
        return $document->BkToCstmrStmt;
57
    }
58
59
    /**
60
     * @param SimpleXMLElement $xmlRecord
61
     *
62
     * @return DTO\Account
63
     */
64 11
    protected function getAccount(SimpleXMLElement $xmlRecord)
65
    {
66 11
        if (isset($xmlRecord->Acct->Id->IBAN)) {
67 9
            return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN));
68
        }
69
70 7
        $xmlOtherIdentification = $xmlRecord->Acct->Id->Othr;
71 7
        $otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id);
72
73 7
        if (isset($xmlOtherIdentification->SchmeNm)) {
74
            if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
75
                $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd);
76
            }
77
78
            if (isset($xmlOtherIdentification->SchmeNm->Prtry)) {
79
                $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry);
80
            }
81
        }
82
83 7
        if (isset($xmlOtherIdentification->Issr)) {
84
            $otherAccount->setIssuer($xmlOtherIdentification->Issr);
85
        }
86
87 7
        return $otherAccount;
88
    }
89
}
90