Completed
Pull Request — master (#22)
by Yann
04:24 queued 01:34
created

Message   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 75.61%

Importance

Changes 4
Bugs 0 Features 4
Metric Value
wmc 12
c 4
b 0
f 4
lcom 1
cbo 10
dl 0
loc 72
ccs 31
cts 41
cp 0.7561
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addRecords() 0 20 2
D getAccount() 0 39 10
1
<?php
2
3
namespace Genkgo\Camt\Camt052\Decoder;
4
5
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder;
6
use Genkgo\Camt\DTO;
7
use Genkgo\Camt\Camt052\DTO as Camt052DTO;
8
use \SimpleXMLElement;
9
use \DateTimeImmutable;
10
use Genkgo\Camt\Iban;
11
12
abstract class Message extends BaseMessageDecoder
13
{
14
    /**
15
     * @param DTO\Message      $message
16
     * @param SimpleXMLElement $document
17
     */
18 4
    public function addRecords(DTO\Message $message, SimpleXMLElement $document)
19
    {
20 4
        $reports = [];
21
22 4
        $xmlReports = $this->getRootElement($document)->Rpt;
0 ignored issues
show
Bug introduced by
The property Rpt 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 4
        foreach ($xmlReports as $xmlReport) {
24 4
            $report = new Camt052DTO\Report(
25 4
                (string) $xmlReport->Id,
26 4
                new DateTimeImmutable((string)$xmlReport->CreDtTm),
27 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...
28 4
            );
29
30 4
            $this->recordDecoder->addBalances($report, $xmlReport);
31 4
            $this->recordDecoder->addEntries($report, $xmlReport);
32
33 4
            $reports[] = $report;
34 4
        }
35
36 4
        $message->setRecords($reports);
37 4
    }
38
39
    /**
40
     * @param SimpleXMLElement $xmlRecord
41
     *
42
     * @return DTO\Account
43
     */
44 4
    protected function getAccount(SimpleXMLElement $xmlRecord)
45
    {
46 4
        if (isset($xmlRecord->Acct->Id->IBAN)) {
47 3
            return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN));
48
        }
49
50 4
        if (isset($xmlRecord->Acct->Id->BBAN)) {
51
            return new DTO\BBANAccount((string) $xmlRecord->Acct->Id->BBAN);
52 1
        }
53
54 4
        if (isset($xmlRecord->Acct->Id->UPIC)) {
55
            return new DTO\UPICAccount((string) $xmlRecord->Acct->Id->UPIC);
56
        }
57
58 4
        if (isset($xmlRecord->Acct->Id->PrtryAcct)) {
59 4
            return new DTO\ProprietaryAccount((string) $xmlRecord->Acct->Id->PrtryAcct->Id);
60
        }
61
62 3
        if (isset($xmlRecord->Acct->Id->Othr)) {
63 3
            $xmlOtherIdentification = $xmlRecord->Acct->Id->Othr;
64 3
            $otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id);
65
66 3
            if (isset($xmlOtherIdentification->SchmeNm)) {
67
                if (isset($xmlOtherIdentification->SchmeNm->Cd)) {
68
                    $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd);
69
                }
70
71
                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...
72
                    $otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry);
73
                }
74 3
            }
75
76 3
            if (isset($xmlOtherIdentification->Issr)) {
77 3
                $otherAccount->setIssuer($xmlOtherIdentification->Issr);
78
            }
79
80 3
            return $otherAccount;
81
        }
82
    }
83
}
84