Completed
Pull Request — master (#86)
by
unknown
03:35
created

AddressKeyFormat::toNode()   F

Complexity

Conditions 12
Paths 576

Size

Total Lines 43
Code Lines 23

Duplication

Lines 6
Ratio 13.95 %

Code Coverage

Tests 21
CRAP Score 18.922

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 6
loc 43
ccs 21
cts 33
cp 0.6364
rs 2.9657
cc 12
eloc 23
nc 576
nop 1
crap 18.922

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 Ups\Entity;
4
5
use DOMDocument;
6
use DOMElement;
7
8
class AddressKeyFormat extends Address
9
{
10
    /**
11
     * @var string
12
     */
13
    private $singleLineAddress;
14
15
    /**
16
     * @param null|object $attributes
17
     */
18 1
    public function __construct($attributes = null)
19
    {
20 1
        if (null !== $attributes) {
21
            if (isset($attributes->SingleLineAddress)) {
22
                $this->setSingleLineAddress($attributes->SingleLineAddress);
23
            }
24
        }
25
26 1
        parent::__construct($attributes);
27 1
    }
28
29
    /**
30
     * @return string
31
     */
32 1
    public function getSingleLineAddress()
33
    {
34 1
        return $this->singleLineAddress;
35
    }
36
37
    /**
38
     * @param string $singleLineAddress
39
     */
40
    public function setSingleLineAddress($singleLineAddress)
41
    {
42
        $this->singleLineAddress = $singleLineAddress;
43
    }
44
45
    /**
46
     * @param null|DOMDocument $document
47
     *
48
     * @return DOMElement
49
     */
50 1
    public function toNode(DOMDocument $document = null)
51
    {
52 1
        if (null === $document) {
53
            $document = new DOMDocument();
54
        }
55
56 1
        $node = $document->createElement('AddressKeyFormat');
57
58 1
        if ($this->getConsigneeName()) {
59
            $node->appendChild($document->createElement('ConsigneeName', $this->getConsigneeName()));
60
        }
61
62 1
        for ($i = 1; $i <= 3; $i++) {
63 1
            $line = $this->{'getAddressLine' . $i}();
64 1
            if ($line) {
65
                $node->appendChild($document->createElement('AddressLine' . ($i == 1 ? '' : $i), $line));
66
            }
67 1
        }
68
69 1 View Code Duplication
        for ($i = 1; $i <= 3; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70 1
            $line = $this->{'getPoliticalDivision' . $i}();
71 1
            if ($line) {
72
                $node->appendChild($document->createElement('PoliticalDivision' . $i, $line));
73
            }
74 1
        }
75
76 1
        if ($this->getPostcodePrimaryLow()) {
77 1
            $node->appendChild($document->createElement('PostcodePrimaryLow', $this->getPostcodePrimaryLow()));
78 1
        }
79 1
        if ($this->getPostcodeExtendedLow()) {
80
            $node->appendChild($document->createElement('PostcodeExtendedLow', $this->getPostcodeExtendedLow()));
81
        }
82
83 1
        if ($this->getCountryCode()) {
84 1
            $node->appendChild($document->createElement('CountryCode', $this->getCountryCode()));
85 1
        }
86
87 1
        if ($this->getSingleLineAddress()) {
88
            $node->appendChild($document->createElement('SingleLineAddress', $this->getSingleLineAddress()));
89
        }
90
91 1
        return $node;
92
    }
93
}
94