Completed
Pull Request — master (#31)
by
unknown
03:17
created

Address::createFromXml()   F

Complexity

Conditions 11
Paths 512

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 11.7975

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 36
ccs 26
cts 32
cp 0.8125
rs 3.1764
cc 11
eloc 22
nc 512
nop 1
crap 11.7975

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 22
    public static function createFromXml(SimpleXMLElement $xmlAddress)
16
    {
17 22
        $address = new DTO\Address();
18
19 22
        if (isset($xmlAddress->Ctry)) {
20 22
            $address = $address->setCountry((string) $xmlAddress->Ctry);
21 22
        }
22 22
        if (isset($xmlAddress->CtrySubDvsn)) {
23
            $address = $address->setCountrySubDivision((string) $xmlAddress->CtrySubDvsn);
24
        }
25 22
        if (isset($xmlAddress->Dept)) {
26
            $address = $address->setDepartment((string) $xmlAddress->Dept);
27
        }
28 22
        if (isset($xmlAddress->SubDept)) {
29
            $address = $address->setSubDepartment((string) $xmlAddress->SubDept);
30
        }
31 22
        if (isset($xmlAddress->StrtNm)) {
32 21
            $address = $address->setStreetName((string) $xmlAddress->StrtNm);
33 21
        }
34 22
        if (isset($xmlAddress->BldgNb)) {
35 6
            $address = $address->setBuildingNumber((string) $xmlAddress->BldgNb);
36 6
        }
37 22
        if (isset($xmlAddress->PstCd)) {
38 6
            $address = $address->setPostCode((string) $xmlAddress->PstCd);
39 6
        }
40 22
        if (isset($xmlAddress->TwnNm)) {
41 6
            $address = $address->setTownName((string) $xmlAddress->TwnNm);
42 6
        }
43 22
        if (isset($xmlAddress->AdrLine)) {
44 16
            foreach ($xmlAddress->AdrLine as $line) {
45 16
                $address = $address->addAddressLine((string)$line);
46 16
            }
47 16
        }
48
49 22
        return $address;
50
    }
51
}
52