Completed
Pull Request — master (#27)
by Yann
02:57
created

Message   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 89.13%

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 41
cts 46
cp 0.8913
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B addRecords() 0 32 5
A getRootElement() 0 4 1
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 11
            );
29
30 11
            if (isset($xmlStatement->StmtPgntn)) {
31 6
                $statement->setPagination(new DTO\Pagination(
32 10
                    (string) $xmlStatement->StmtPgntn->PgNb,
33 10
                    ('true' === (string) $xmlStatement->StmtPgntn->LastPgInd) ? true : false
34 10
                ));
35 6
            }
36
37 11
            if (isset($xmlStatement->AddtlStmtInf)) {
38 10
                $statement->setAdditionalInformation((string) $xmlStatement->AddtlStmtInf);
39 10
            }
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 11
        }
47
48 11
        $message->setRecords($statements);
49 11
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 12
    public function getRootElement(SimpleXMLElement $document)
55 10
    {
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 9
    {
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 10
            if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
75 10
                $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd);
76 10
            }
77
78
            if (isset($otherIdentification->SchmeNm->Prtry)) {
0 ignored issues
show
Bug introduced by
The variable $otherIdentification does not exist. Did you mean $xmlOtherIdentification?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
79 10
                $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