Completed
Push — master ( b5ae25...349033 )
by Frederik
02:37
created

Message   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 91.18%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 9
dl 0
loc 66
ccs 31
cts 34
cp 0.9118
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addGroupHeader() 0 10 1
A addRecords() 0 20 2
B getAccount() 0 18 5
1
<?php
2
3
namespace Genkgo\Camt\Camt052\Decoder;
4
5
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder;
6
use Genkgo\Camt\Camt052\DTO as Camt052DTO;
7
use Genkgo\Camt\DTO;
8
use \SimpleXMLElement;
9
use \DateTimeImmutable;
10
11
class Message extends BaseMessageDecoder
12
{
13
    /**
14
     * @param DTO\Message      $message
15
     * @param SimpleXMLElement $document
16
     */
17 4
    public function addGroupHeader(DTO\Message $message, SimpleXMLElement $document)
18
    {
19 4
        $xmlGroupHeader = $document->BkToCstmrAcctRptV01->GrpHdr;
20 4
        $groupHeader = new DTO\GroupHeader(
21 4
            (string)$xmlGroupHeader->MsgId,
22 4
            new DateTimeImmutable((string)$xmlGroupHeader->CreDtTm)
23 4
        );
24
25 4
        $message->setGroupHeader($groupHeader);
26 4
    }
27
28
    /**
29
     * @param DTO\Message      $message
30
     * @param SimpleXMLElement $document
31
     */
32 4
    public function addRecords(DTO\Message $message, SimpleXMLElement $document)
33
    {
34 4
        $reports = [];
35
36 4
        $xmlReports = $document->BkToCstmrAcctRptV01->Rpt;
37 4
        foreach ($xmlReports as $xmlReport) {
38 4
            $report = new Camt052DTO\Report(
39 4
                (string) $xmlReport->Id,
40 4
                new DateTimeImmutable((string)$xmlReport->CreDtTm),
41 4
                $this->getAccount($xmlReport)
0 ignored issues
show
Bug introduced by
It seems like $this->getAccount($xmlReport) targeting Genkgo\Camt\Camt052\Decoder\Message::getAccount() can also be of type null; however, Genkgo\Camt\DTO\Record::__construct() does only seem to accept object<Genkgo\Camt\DTO\Account>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
42 4
            );
43
44 4
            $this->recordDecoder->addBalances($report, $xmlReport);
45 4
            $this->recordDecoder->addEntries($report, $xmlReport);
46
47 4
            $reports[] = $report;
48 4
        }
49
50 4
        $message->setRecords($reports);
51 4
    }
52
53
    /**
54
     * @param SimpleXMLElement $xmlRecord
55
     *
56
     * @return DTO\Account
57
     */
58 4
    protected function getAccount(SimpleXMLElement $xmlRecord)
59
    {
60 4
        if (isset($xmlRecord->Acct->Id->IBAN)) {
61
            return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN));
62
        }
63
64 4
        if (isset($xmlRecord->Acct->Id->BBAN)) {
65
            return new Camt052DTO\BBANAccount((string) $xmlRecord->Acct->Id->BBAN);
66
        }
67
68 4
        if (isset($xmlRecord->Acct->Id->UPIC)) {
69
            return new Camt052DTO\UPICAccount((string) $xmlRecord->Acct->Id->UPIC);
70
        }
71
72 4
        if (isset($xmlRecord->Acct->Id->PrtryAcct)) {
73 4
            return new Camt052DTO\ProprietaryAccount((string) $xmlRecord->Acct->Id->PrtryAcct->Id);
74 3
        }
75 3
    }
76
}
77