Completed
Pull Request — master (#149)
by
unknown
26:16
created

BillThirdParty::setThirdPartyAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Ups\Entity;
4
use DOMDocument;
5
use DOMElement;
6
use Ups\NodeInterface;
7
8
/**
9
 * @author Eduard Sukharev <[email protected]>
10
 */
11
class BillThirdParty implements NodeInterface
12
{
13
    /**
14
     * @var Address
15
     */
16
    private $thirdPartyAddress;
17
18
    /**
19
     * @var string
20
     */
21
    private $accountNumber;
22
23
    /**
24
     * @param \stdClass|null $attributes
25
     */
26 1
    public function __construct(\stdClass $attributes = null)
27
    {
28 1
        $this->thirdPartyAddress = new Address(isset($attributes->Address) ? $attributes->Address : null);
29 1
        $this->accountNumber = isset($attributes->AccountNumber) ? $attributes->AccountNumber : null;
30 1
    }
31
32
    /**
33
     * @return Address
34
     */
35 1
    public function getThirdPartyAddress()
36
    {
37 1
        return $this->thirdPartyAddress;
38
    }
39
40
    /**
41
     * @param Address $thirdPartyAddress
42
     * @return BillThirdParty
43
     */
44
    public function setThirdPartyAddress(Address $thirdPartyAddress = null)
45
    {
46
        $this->thirdPartyAddress = $thirdPartyAddress;
47
48
        return $this;
49
    }
50
51
    /**
52
     * @return string
53
     */
54 1
    public function getAccountNumber()
55
    {
56 1
        return $this->accountNumber;
57
    }
58
59
    /**
60
     * @param string $accountNumber
61
     * @return BillThirdParty
62
     */
63
    public function setAccountNumber($accountNumber)
64
    {
65
        $this->accountNumber = $accountNumber;
66
67
        return $this;
68
    }
69
70
    /**
71
     * @param DOMDocument|null $document
72
     * @return DOMElement
73
     */
74 1
    public function toNode(DOMDocument $document = null)
75
    {
76 1
        if (null === $document) {
77
            $document = new DOMDocument();
78
        }
79
80 1
        $node = $document->createElement('BillThirdParty');
81
82 1
        $btpNode = $node->appendChild($document->createElement('BillThirdPartyShipper'));
83 1
        $btpNode->appendChild($document->createElement('AccountNumber', $this->getAccountNumber()));
84
85 1
        $tpNode = $btpNode->appendChild($document->createElement('ThirdParty'));
86 1
        $addressNode = $tpNode->appendChild($document->createElement('Address'));
87
88 1
        $thirdPartAddress = $this->getThirdPartyAddress();
89 1
        if (isset($thirdPartAddress) && $this->getThirdPartyAddress()->getPostalCode()) {
90
            $addressNode->appendChild($document->createElement('PostalCode', $this->getThirdPartyAddress()->getPostalCode()));
91
        }
92
93 1
        $addressNode->appendChild($document->createElement('CountryCode', $this->getThirdPartyAddress()->getCountryCode()));
94
95 1
        return $node;
96
    }
97
}
98