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

AddressKeyFormat::setSingleLineAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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