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

CreditCard::__construct()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 11.4603

Importance

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