Completed
Push — master ( fd90eb...52b814 )
by Stefan
04:00
created

Shipper::__construct()   F

Complexity

Conditions 11
Paths 513

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 92.0605

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
ccs 4
cts 32
cp 0.125
rs 3.1764
cc 11
eloc 21
nc 513
nop 1
crap 92.0605

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
use Ups\NodeInterface;
8
9
class Shipper implements NodeInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $name;
15
16
    /**
17
     * @var string
18
     */
19
    protected $companyName;
20
21
    /**
22
     * @var string
23
     */
24
    protected $attentionName;
25
26
    /**
27
     * @var string
28
     */
29
    protected $taxIdentificationNumber;
30
31
    /**
32
     * @var string
33
     */
34
    protected $phoneNumber;
35
36
    /**
37
     * @var string
38
     */
39
    protected $faxNumber;
40
41
    /**
42
     * @var string
43
     */
44
    protected $shipperNumber;
45
46
    /**
47
     * @var string
48
     */
49
    protected $emailAddress;
50
51
    /**
52
     * @var Address
53
     */
54
    protected $address;
55
56
    /**
57
     * @param null|object $attributes
58
     */
59 7
    public function __construct($attributes = null)
60
    {
61 7
        $this->address = new Address();
62
63 7
        if (null !== $attributes) {
64
            if (isset($attributes->Name)) {
65
                $this->setName($attributes->Name);
66
            }
67
            if (isset($attributes->CompanyName)) {
68
                $this->setCompanyName($attributes->CompanyName);
69
            }
70
            if (isset($attributes->AttentionName)) {
71
                $this->setAttentionName($attributes->AttentionName);
72
            }
73
            if (isset($attributes->TaxIdentificationNumber)) {
74
                $this->setTaxIdentificationNumber($attributes->TaxIdentificationNumber);
75
            }
76
            if (isset($attributes->PhoneNumber)) {
77
                $this->setPhoneNumber($attributes->PhoneNumber);
78
            }
79
            if (isset($attributes->FaxNumber)) {
80
                $this->setFaxNumber($attributes->FaxNumber);
81
            }
82
            if (isset($attributes->ShipperNumber)) {
83
                $this->setShipperNumber($attributes->ShipperNumber);
84
            }
85
            if (isset($attributes->EMailAddress)) {
86
                $this->setEmailAddress($attributes->EMailAddress);
87
            }
88
            if (isset($attributes->Address)) {
89
                $this->setAddress(new Address($attributes->Address));
90
            }
91
        }
92 7
    }
93
94
    /**
95
     * @param null|DOMDocument $document
96
     *
97
     * @return DOMElement
98
     */
99 1
    public function toNode(DOMDocument $document = null)
100
    {
101 1
        if (null === $document) {
102
            $document = new DOMDocument();
103
        }
104
105 1
        $node = $document->createElement('Shipper');
106
107 1
        $shipperName = $this->getName();
108 1
        if (isset($shipperName)) {
109
            $node->appendChild($document->createElement('Name', $shipperName));
110
        }
111
112 1
        $shipperNumber = $this->getShipperNumber();
113 1
        if (isset($shipperNumber)) {
114
            $node->appendChild($document->createElement('ShipperNumber', $shipperNumber));
115
        }
116
117 1
        $address = $this->getAddress();
118 1
        if (isset($address)) {
119 1
            $node->appendChild($address->toNode($document));
120 1
        }
121
122 1
        return $node;
123
    }
124
125
    /**
126
     * @return Address
127
     */
128 2
    public function getAddress()
129
    {
130 2
        return $this->address;
131
    }
132
133
    /**
134
     * @param Address $address
135
     *
136
     * @return Shipper
137
     */
138
    public function setAddress(Address $address)
139
    {
140
        $this->address = $address;
141
142
        return $this;
143
    }
144
145
    /**
146
     * @return string
147
     */
148 1
    public function getAttentionName()
149
    {
150 1
        return $this->attentionName;
151
    }
152
153
    /**
154
     * @param string $attentionName
155
     *
156
     * @return Shipper
157
     */
158
    public function setAttentionName($attentionName)
159
    {
160
        $this->attentionName = $attentionName;
161
162
        return $this;
163
    }
164
165
    /**
166
     * @return string
167
     */
168
    public function getEmailAddress()
169
    {
170
        return $this->emailAddress;
171
    }
172
173
    /**
174
     * @param string $emailAddress
175
     *
176
     * @return Shipper
177
     */
178
    public function setEmailAddress($emailAddress)
179
    {
180
        $this->emailAddress = $emailAddress;
181
182
        return $this;
183
    }
184
185
    /**
186
     * @return string
187
     */
188
    public function getFaxNumber()
189
    {
190
        return $this->faxNumber;
191
    }
192
193
    /**
194
     * @param string $faxNumber
195
     *
196
     * @return Shipper
197
     */
198
    public function setFaxNumber($faxNumber)
199
    {
200
        $this->faxNumber = $faxNumber;
201
202
        return $this;
203
    }
204
205
    /**
206
     * @return string
207
     */
208 1
    public function getName()
209
    {
210 1
        return $this->name;
211
    }
212
213
    /**
214
     * @param string $name
215
     *
216
     * @return Shipper
217
     */
218
    public function setName($name)
219
    {
220
        $this->name = $name;
221
222
        return $this;
223
    }
224
225
    /**
226
     * @return string
227
     */
228
    public function getPhoneNumber()
229
    {
230
        return $this->phoneNumber;
231
    }
232
233
    /**
234
     * @param string $phoneNumber
235
     *
236
     * @return Shipper
237
     */
238
    public function setPhoneNumber($phoneNumber)
239
    {
240
        $this->phoneNumber = $phoneNumber;
241
242
        return $this;
243
    }
244
245
    /**
246
     * @return string
247
     */
248 1
    public function getShipperNumber()
249
    {
250 1
        return $this->shipperNumber;
251
    }
252
253
    /**
254
     * @param string $shipperNumber
255
     *
256
     * @return Shipper
257
     */
258
    public function setShipperNumber($shipperNumber)
259
    {
260
        $this->shipperNumber = $shipperNumber;
261
262
        return $this;
263
    }
264
265
    /**
266
     * @return string
267
     */
268
    public function getTaxIdentificationNumber()
269
    {
270
        return $this->taxIdentificationNumber;
271
    }
272
273
    /**
274
     * @param string $taxIdentificationNumber
275
     *
276
     * @return Shipper
277
     */
278
    public function setTaxIdentificationNumber($taxIdentificationNumber)
279
    {
280
        $this->taxIdentificationNumber = $taxIdentificationNumber;
281
282
        return $this;
283
    }
284
285
    /**
286
     * @return string
287
     */
288 1
    public function getCompanyName()
289
    {
290 1
        return $this->companyName;
291
    }
292
293
    /**
294
     * @param string $companyName
295
     * @return Shipper
296
     */
297
    public function setCompanyName($companyName = null)
298
    {
299
        $this->companyName = $companyName;
300
301
        return $this;
302
    }
303
}
304