Passed
Pull Request — master (#149)
by
unknown
03:42
created

CreditCard::getAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
use DOMElement;
7
use Ups\NodeInterface;
8
9
/**
10
 * @author Eduard Sukharev <[email protected]>
11
 */
12
class CreditCard implements NodeInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $type;
18
19
    /**
20
     * @var string
21
     */
22
    private $number;
23
24
    /**
25
     * @var string
26
     */
27
    private $expirationDate;
28
29
    /**
30
     * @var string
31
     */
32
    private $securityCode;
33
34
    /**
35
     * @var Address
36
     */
37
    private $address;
38
39
    /**
40
     * @param \stdClass|null $attributes
41
     */
42 1
    public function __construct(\stdClass $attributes = null)
43
    {
44 1
        $this->setAddress(new Address(isset($attributes->Address) ? $attributes->Address : null));
45
46 1
        if (isset($attributes->Type)) {
47
            $this->setType($attributes->Type);
48
        }
49 1
        if (isset($attributes->Number)) {
50
            $this->setNumber($attributes->Number);
51
        }
52 1
        if (isset($attributes->ExpirationDate)) {
53
            $this->setExpirationDate($attributes->ExpirationDate);
54
        }
55 1
        if (isset($attributes->SecurityCode)) {
56
            $this->setSecurityCode($attributes->SecurityCode);
57
        }
58 1
    }
59
60
    /**
61
     * @param DOMDocument|null $document
62
     *
63
     * @return DOMElement
64
     */
65 1
    public function toNode(DOMDocument $document = null)
66
    {
67 1
        if (null === $document) {
68
            $document = new DOMDocument();
69
        }
70
71 1
        $node = $document->createElement('CreditCard');
72
73 1
        $node->appendChild($document->createElement('Type', $this->getType()));
74 1
        $node->appendChild($document->createElement('Number', $this->getNumber()));
75 1
        $node->appendChild($document->createElement('ExpirationDate', $this->getExpirationDate()));
76
77 1
        if ($this->getSecurityCode()) {
78
            $node->appendChild($document->createElement('SecurityCode', $this->getSecurityCode()));
79
        }
80
81 1
        if ($this->getAddress()) {
82 1
            $node->appendChild($this->getAddress()->toNode($document));
83 1
        }
84
85 1
        return $node;
86
    }
87
88
    /**
89
     * @return string
90
     */
91 1
    public function getType()
92
    {
93 1
        return $this->type;
94
    }
95
96
    /**
97
     * @param string $type
98
     * @return CreditCard
99
     */
100
    public function setType($type)
101
    {
102
        $this->type = $type;
103
104
        return $this;
105
    }
106
107
    /**
108
     * @return string
109
     */
110 1
    public function getNumber()
111
    {
112 1
        return $this->number;
113
    }
114
115
    /**
116
     * @param string $number
117
     * @return CreditCard
118
     */
119
    public function setNumber($number)
120
    {
121
        $this->number = $number;
122
123
        return $this;
124
    }
125
126
    /**
127
     * @return string
128
     */
129 1
    public function getSecurityCode()
130
    {
131 1
        return $this->securityCode;
132
    }
133
134
    /**
135
     * @param string $securityCode
136
     * @return CreditCard
137
     */
138
    public function setSecurityCode($securityCode)
139
    {
140
        $this->securityCode = $securityCode;
141
142
        return $this;
143
    }
144
145
    /**
146
     * @return Address
147
     */
148 1
    public function getAddress()
149
    {
150 1
        return $this->address;
151
    }
152
153
    /**
154
     * @param Address $address
155
     * @return CreditCard
156
     */
157 1
    public function setAddress(Address $address)
158
    {
159 1
        $this->address = $address;
160
161 1
        return $this;
162
    }
163
164
    /**
165
     * @return string
166
     */
167 1
    public function getExpirationDate()
168
    {
169 1
        return $this->expirationDate;
170
    }
171
172
    /**
173
     * @param string $expirationDate
174
     * @return CreditCard
175
     */
176
    public function setExpirationDate($expirationDate)
177
    {
178
        $this->expirationDate = $expirationDate;
179
180
        return $this;
181
    }
182
}
183