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

Address::createFromXml()   F

Complexity

Conditions 11
Paths 512

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 11.307

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 36
ccs 19
cts 22
cp 0.8636
rs 3.1764
cc 11
eloc 22
nc 512
nop 1
crap 11.307

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Genkgo\Camt\Decoder\Factory\DTO;
4
5
use SimpleXMLElement;
6
use Genkgo\Camt\DTO;
7
8
class Address
9
{
10
    /**
11
     * @param SimpleXMLElement $xmlAddress
12
     *
13
     * @return DTO\Address
14
     */
15 19
    public static function createFromXml(SimpleXMLElement $xmlAddress)
16
    {
17 19
        $address = new DTO\Address();
18
19 19
        if (isset($xmlAddress->Ctry)) {
20 19
            $address = $address->setCountry((string) $xmlAddress->Ctry);
21
        }
22 19
        if (isset($xmlAddress->CtrySubDvsn)) {
23
            $address = $address->setCountrySubDivision((string) $xmlAddress->CtrySubDvsn);
24
        }
25 19
        if (isset($xmlAddress->Dept)) {
26
            $address = $address->setDepartment((string) $xmlAddress->Dept);
27
        }
28 19
        if (isset($xmlAddress->SubDept)) {
29
            $address = $address->setSubDepartment((string) $xmlAddress->SubDept);
30
        }
31 19
        if (isset($xmlAddress->StrtNm)) {
32 18
            $address = $address->setStreetName((string) $xmlAddress->StrtNm);
33
        }
34 19
        if (isset($xmlAddress->BldgNb)) {
35 3
            $address = $address->setBuildingNumber((string) $xmlAddress->BldgNb);
36
        }
37 19
        if (isset($xmlAddress->PstCd)) {
38 3
            $address = $address->setPostCode((string) $xmlAddress->PstCd);
39
        }
40 19
        if (isset($xmlAddress->TwnNm)) {
41 3
            $address = $address->setTownName((string) $xmlAddress->TwnNm);
42
        }
43 19
        if (isset($xmlAddress->AdrLine)) {
44 1
            foreach ($xmlAddress->AdrLine as $line) {
45 1
                $address = $address->addAddressLine((string)$line);
46
            }
47
        }
48
49 19
        return $address;
50
    }
51
}
52