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