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

Recipient::createFromXml()   C

Complexity

Conditions 8
Paths 80

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 8.3364

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 27
ccs 19
cts 23
cp 0.8261
rs 5.3846
cc 8
eloc 16
nc 80
nop 1
crap 8.3364
1
<?php
2
3
namespace Genkgo\Camt\Decoder\Factory\DTO;
4
5
use SimpleXMLElement;
6
use Genkgo\Camt\DTO;
7
8
class Recipient
9
{
10
    /**
11
     * @param SimpleXMLElement $xmlRecipient
12
     *
13
     * @return DTO\Recipient
14
     */
15 17
    public static function createFromXml(SimpleXMLElement $xmlRecipient)
16
    {
17 17
        $recipient = new DTO\Recipient();
18
19 17
        if (isset($xmlRecipient->Nm)) {
20 17
            $recipient->setName((string) $xmlRecipient->Nm);
21 17
        }
22 17
        if (isset($xmlRecipient->PstlAdr)) {
23 17
            $recipient->setAddress(Address::createFromXml($xmlRecipient->PstlAdr));
24 17
        }
25 17
        if (isset($xmlRecipient->CtryOfRes)) {
26 17
            $recipient->setCountryOfResidence((string) $xmlRecipient->CtryOfRes);
27 17
        }
28 17
        if (isset($xmlRecipient->CtctDtls)) {
29
            $recipient->setContactDetails(ContactDetails::createFromXml($xmlRecipient->CtctDtls));
30
        }
31 17
        if (isset($xmlRecipient->Id)) {
32 17
            if (isset($xmlRecipient->Id->OrgId)) {
33 17
                $recipient->setIdentification(OrganisationIdentification::createFromXml($xmlRecipient->Id->OrgId));
34 17
            }
35 17
            if (isset($xmlRecipient->Id->PrvtId)) {
36
                $recipient->setIdentification(PersonIdentification::createFromXml($xmlRecipient->Id->PrvtId));
37
            }
38 17
        }
39
40 17
        return $recipient;
41
    }
42
}
43