Address::createFromXml()   F
last analyzed

Complexity

Conditions 11
Paths 512

Size

Total Lines 35
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 11.307

Importance

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

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