Completed
Pull Request — master (#141)
by
unknown
03:07
created

ShipmentServiceOptions::__construct()   F

Complexity

Conditions 13
Paths 2049

Size

Total Lines 40
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 30.9637

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 40
ccs 20
cts 38
cp 0.5263
rs 2.7716
cc 13
eloc 25
nc 2049
nop 1
crap 30.9637

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
/**
10
 * Class ShipmentServiceOptions
11
 * @package Ups\Entity
12
 */
13
// @todo Refactor to private properties
14
class ShipmentServiceOptions implements NodeInterface
15
{
16
    /**
17
     * @var
18
     */
19
    public $SaturdayPickup;
20
21
    /**
22
     * @var
23
     */
24
    public $SaturdayDelivery;
25
26
    /**
27
     * @var
28
     */
29
    public $COD;
30
31
    /**
32
     * @var CallTagARS
33
     */
34
    public $CallTagARS;
35
36
    /**
37
     * @var
38
     */
39
    public $NegotiatedRatesIndicator;
40
41
    /**
42
     * @var
43
     */
44
    public $DirectDeliveryOnlyIndicator;
45
46
    /**
47
     * @var
48
     */
49
    public $DeliverToAddresseeOnlyIndicator;
50
51
    /**
52
     * @var
53
     */
54
    private $internationalForms;
55
56
    /**
57
     * @var
58
     */
59
    private $labelMethod;
60
61
    /**
62
     * @var array
63
     */
64
    private $notifications = [];
65
66
    /**
67
     * @var AccessPointCOD
68
     */
69
    private $accessPointCOD;
70
71
    /**
72
     * @var boolean
73
     */
74
    private $importControlIndicator;
75
76
    /**
77
     * @param null $response
78
     */
79 9
    public function __construct($response = null)
80
    {
81 9
        $this->CallTagARS = new CallTagARS();
82
83 9
        if (null !== $response) {
84 2
            if (isset($response->SaturdayPickup)) {
85
                $this->SaturdayPickup = $response->SaturdayPickup;
86
            }
87 2
            if (isset($response->SaturdayDelivery)) {
88
                $this->SaturdayDelivery = $response->SaturdayDelivery;
89
            }
90 2
            if (isset($response->COD)) {
91
                $this->COD = $response->COD;
92
            }
93 2
            if (isset($response->AccessPointCOD)) {
94
                $this->setAccessPointCOD(new AccessPointCOD($response->AccessPointCOD));
0 ignored issues
show
Unused Code introduced by
The call to AccessPointCOD::__construct() has too many arguments starting with $response->AccessPointCOD.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
95
            }
96 2
            if (isset($response->CallTagARS)) {
97
                $this->CallTagARS = new CallTagARS($response->CallTagARS);
98
            }
99 2
            if (isset($response->NegotiatedRatesIndicator)) {
100
                $this->NegotiatedRatesIndicator = $response->NegotiatedRatesIndicator;
101
            }
102 2
            if (isset($response->DirectDeliveryOnlyIndicator)) {
103
                $this->DirectDeliveryOnlyIndicator = $response->DirectDeliveryOnlyIndicator;
104
            }
105 2
            if (isset($response->DeliverToAddresseeOnlyIndicator)) {
106
                $this->DeliverToAddresseeOnlyIndicator = $response->DeliverToAddresseeOnlyIndicator;
107
            }
108 2
            if (isset($response->InternationalForms)) {
109
                $this->setInternationalForms($response->InternationalForms);
110
            }
111 2
            if (isset($response->ImportControlIndicator)) {
112 2
                $this->setImportControlIndicator($response->ImportControlIndicator);
113 2
            }
114 2
            if (isset($response->LabelMethod)) {
115 2
                $this->setLabelMethod(new LabelMethod($response->LabelMethod));
116 2
            }
117 2
        }
118 9
    }
119
120
    /**
121
     * @param null|DOMDocument $document
122
     *
123
     * @return DOMElement
124
     */
125 2
    public function toNode(DOMDocument $document = null)
126
    {
127 2
        if (null === $document) {
128
            $document = new DOMDocument();
129
        }
130
131 2
        $node = $document->createElement('ShipmentServiceOptions');
132
133 2
        if (isset($this->DirectDeliveryOnlyIndicator)) {
134
            $node->appendChild($document->createElement('DirectDeliveryOnlyIndicator'));
135
        }
136
137 2
        if (isset($this->DeliverToAddresseeOnlyIndicator)) {
138
            $node->appendChild($document->createElement('DeliverToAddresseeOnlyIndicator'));
139
        }
140
141 2
        if (isset($this->SaturdayPickup)) {
142
            $node->appendChild($document->createElement('SaturdayPickup'));
143
        }
144
145 2
        if (isset($this->SaturdayDelivery)) {
146
            $node->appendChild($document->createElement('SaturdayDelivery'));
147
        }
148
149 2
        if ($this->getCOD()) {
150
            $node->appendChild($this->getCOD()->toNode($document));
151
        }
152
153 2
        if ($this->getAccessPointCOD()) {
154
            $node->appendChild($this->getAccessPointCOD()->toNode($document));
155
        }
156
157 2
        if (isset($this->internationalForms)) {
158
            $node->appendChild($this->internationalForms->toNode($document));
159
        }
160
161 2
        if (isset($this->importControlIndicator)) {
162 1
            $node->appendChild($document->createElement('ImportControlIndicator'));
163 1
        }
164
165 2
        if (isset($this->labelMethod)) {
166 1
            $node->appendChild($this->labelMethod->toNode($document));
167 1
        }
168
169 2
        if (!empty($this->notifications)) {
170
            foreach ($this->notifications as $notification) {
171
                $node->appendChild($notification->toNode($document));
172
            }
173
        }
174
175 2
        return $node;
176
    }
177
178
    /**
179
     * @return AccessPointCOD
180
     */
181 2
    public function getAccessPointCOD()
182
    {
183 2
        return $this->accessPointCOD;
184
    }
185
186
    /**
187
     * @param $accessPointCOD
188
     * @return $this
189
     */
190
    public function setAccessPointCOD($accessPointCOD)
191
    {
192
        $this->accessPointCOD = $accessPointCOD;
193
        return $this;
194
    }
195
196
    /**
197
     * @param InternationalForms $data
198
     * @return $this
199
     */
200
    public function setInternationalForms(InternationalForms $data)
201
    {
202
        $this->internationalForms = $data;
203
        return $this;
204
    }
205
206
    /**
207
     * @return mixed
208
     */
209
    public function getInternationalForms()
210
    {
211
        return $this->internationalForms;
212
    }
213
214
    /**
215
     * @param LabelMethod $data
216
     * @return $this
217
     */
218 2
    public function setLabelMethod(LabelMethod $data)
219
    {
220 2
        $this->labelMethod = $data;
221 2
        return $this;
222
    }
223
224
    /**
225
     * @return mixed
226
     */
227 1
    public function getLabelMethod()
228
    {
229 1
        return $this->labelMethod;
230
    }
231
232
    /**
233
     * @param Notification $notification
234
     *
235
     * @throws \Exception
236
     *
237
     * @return $this
238
     */
239
    public function addNotification(Notification $notification)
240
    {
241
        $this->notifications[] = $notification;
242
243
        if (count($this->notifications) > 3) {
244
            throw new \Exception('Maximum 3 notifications allowed');
245
        }
246
247
        return $this;
248
    }
249
250
    /**
251
     * @return array
252
     */
253
    public function getNotifications()
254
    {
255
        return $this->notifications;
256
    }
257
258
    /**
259
     * @return mixed
260
     */
261
    public function getSaturdayPickup()
262
    {
263
        return $this->SaturdayPickup;
264
    }
265
266
    /**
267
     * @param mixed $SaturdayPickup
268
     * @return ShipmentServiceOptions
269
     */
270
    public function setSaturdayPickup($SaturdayPickup)
271
    {
272
        $this->SaturdayPickup = $SaturdayPickup;
273
        return $this;
274
    }
275
276
    /**
277
     * @return null|LabelMethod
278
     */
279
    public function getSaturdayDelivery()
280
    {
281
        return $this->SaturdayDelivery;
282
    }
283
284
    /**
285
     * @param mixed $SaturdayDelivery
286
     * @return ShipmentServiceOptions
287
     */
288
    public function setSaturdayDelivery($SaturdayDelivery)
289
    {
290
        $this->SaturdayDelivery = $SaturdayDelivery;
291
        return $this;
292
    }
293
294
    /**
295
     * @return mixed
296
     */
297 2
    public function getCOD()
298
    {
299 2
        return $this->COD;
300
    }
301
302
    /**
303
     * @param mixed $COD
304
     * @return ShipmentServiceOptions
305
     */
306
    public function setCOD($COD)
307
    {
308
        $this->COD = $COD;
309
        return $this;
310
    }
311
312
313
    /**
314
     * @return CallTagARS
315
     */
316
    public function getCallTagARS()
317
    {
318
        return $this->CallTagARS;
319
    }
320
321
    /**
322
     * @param CallTagARS $CallTagARS
323
     * @return ShipmentServiceOptions
324
     */
325
    public function setCallTagARS($CallTagARS)
326
    {
327
        $this->CallTagARS = $CallTagARS;
328
        return $this;
329
    }
330
331
    /**
332
     * @return boolean
333
     */
334
    public function isNegotiatedRatesIndicator()
335
    {
336
        return $this->NegotiatedRatesIndicator;
337
    }
338
339
    /**
340
     * @param boolean $NegotiatedRatesIndicator
341
     * @return ShipmentServiceOptions
342
     */
343
    public function setNegotiatedRatesIndicator($NegotiatedRatesIndicator)
344
    {
345
        $this->NegotiatedRatesIndicator = $NegotiatedRatesIndicator;
346
        return $this;
347
    }
348
349
    /**
350
     * @return boolean
351
     */
352 2
    public function isImportControlIndicator()
353
    {
354 2
        return $this->importControlIndicator;
355
    }
356
357
    /**
358
     * @param boolean $importControlIndicator
359
     * @return ShipmentServiceOptions
360
     */
361 3
    public function setImportControlIndicator($importControlIndicator)
362
    {
363 3
        $this->importControlIndicator = $importControlIndicator;
364 3
        return $this;
365
    }
366
367
    /**
368
     * @return boolean
369
     */
370
    public function isDirectDeliveryOnlyIndicator()
371
    {
372
        return $this->DirectDeliveryOnlyIndicator;
373
    }
374
375
    /**
376
     * @param boolean $DirectDeliveryOnlyIndicator
377
     * @return ShipmentServiceOptions
378
     */
379
    public function setDirectDeliveryOnlyIndicator($DirectDeliveryOnlyIndicator)
380
    {
381
        $this->DirectDeliveryOnlyIndicator = $DirectDeliveryOnlyIndicator;
382
        return $this;
383
    }
384
385
    /**
386
     * @return mixed
387
     */
388
    public function getDeliverToAddresseeOnlyIndicator()
389
    {
390
        return $this->DeliverToAddresseeOnlyIndicator;
391
    }
392
393
    /**
394
     * @param mixed $DeliverToAddresseeOnlyIndicator
395
     * @return ShipmentServiceOptions
396
     */
397
    public function setDeliverToAddresseeOnlyIndicator($DeliverToAddresseeOnlyIndicator)
398
    {
399
        $this->DeliverToAddresseeOnlyIndicator = $DeliverToAddresseeOnlyIndicator;
400
        return $this;
401
    }
402
}
403