Passed
Push — master ( b12c40...c14c19 )
by
unknown
39s
created

ShipmentServiceOptions::setLabelDelivery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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 null|LabelMethod
58
     */
59
    private $labelMethod;
60
61
    /**
62
     * @var null|LabelDelivery
63
     */
64
    private $labelDelivery;
65
66
    /**
67
     * @var array
68
     */
69
    private $notifications = [];
70
71
    /**
72
     * @var AccessPointCOD
73
     */
74
    private $accessPointCOD;
75
76
    /**
77
     * @var boolean
78
     */
79
    private $importControlIndicator;
80
81
    /**
82
     * @var DeliveryConfirmation
83
     */
84
    private $deliveryConfirmation;
85
86
    /**
87
     * @param null $response
88
     */
89 9
    public function __construct($response = null)
90
    {
91 9
        $this->CallTagARS = new CallTagARS();
92
93 9
        if (null !== $response) {
94 2
            if (isset($response->SaturdayPickup)) {
95
                $this->SaturdayPickup = $response->SaturdayPickup;
96
            }
97 2
            if (isset($response->SaturdayDelivery)) {
98
                $this->SaturdayDelivery = $response->SaturdayDelivery;
99
            }
100 2
            if (isset($response->COD)) {
101
                $this->COD = $response->COD;
102
            }
103 2
            if (isset($response->AccessPointCOD)) {
104
                $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...
105
            }
106 2
            if (isset($response->CallTagARS)) {
107
                $this->CallTagARS = new CallTagARS($response->CallTagARS);
108
            }
109 2
            if (isset($response->NegotiatedRatesIndicator)) {
110
                $this->NegotiatedRatesIndicator = $response->NegotiatedRatesIndicator;
111
            }
112 2
            if (isset($response->DirectDeliveryOnlyIndicator)) {
113
                $this->DirectDeliveryOnlyIndicator = $response->DirectDeliveryOnlyIndicator;
114
            }
115 2
            if (isset($response->DeliverToAddresseeOnlyIndicator)) {
116
                $this->DeliverToAddresseeOnlyIndicator = $response->DeliverToAddresseeOnlyIndicator;
117
            }
118 2
            if (isset($response->InternationalForms)) {
119
                $this->setInternationalForms($response->InternationalForms);
120
            }
121 2
            if (isset($response->ImportControlIndicator)) {
122 2
                $this->setImportControlIndicator($response->ImportControlIndicator);
123 2
            }
124 2
            if (isset($response->DeliveryConfirmation)) {
125
                $this->setDeliveryConfirmation($response->DeliveryConfirmation);
126
            }
127 2
            if (isset($response->LabelMethod)) {
128 2
                $this->setLabelMethod(new LabelMethod($response->LabelMethod));
129 2
            }
130 2
            if (isset($response->EMailMessage)) {
131
                $this->setEMailMessage(new EMailMessage($response->EMailMessage));
0 ignored issues
show
Unused Code introduced by
The call to EmailMessage::__construct() has too many arguments starting with $response->EMailMessage.

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...
Bug introduced by
The method setEMailMessage() does not seem to exist on object<Ups\Entity\ShipmentServiceOptions>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
132
            }
133 2
        }
134 9
    }
135
136
    /**
137
     * @param null|DOMDocument $document
138
     *
139
     * @return DOMElement
140
     */
141 2
    public function toNode(DOMDocument $document = null)
142
    {
143 2
        if (null === $document) {
144
            $document = new DOMDocument();
145
        }
146
147 2
        $node = $document->createElement('ShipmentServiceOptions');
148
149 2
        if (isset($this->DirectDeliveryOnlyIndicator)) {
150
            $node->appendChild($document->createElement('DirectDeliveryOnlyIndicator'));
151
        }
152
153 2
        if (isset($this->DeliverToAddresseeOnlyIndicator)) {
154
            $node->appendChild($document->createElement('DeliverToAddresseeOnlyIndicator'));
155
        }
156
157 2
        if (isset($this->SaturdayPickup)) {
158
            $node->appendChild($document->createElement('SaturdayPickup'));
159
        }
160
161 2
        if (isset($this->SaturdayDelivery)) {
162
            $node->appendChild($document->createElement('SaturdayDelivery'));
163
        }
164
165 2
        if ($this->getCOD()) {
166
            $node->appendChild($this->getCOD()->toNode($document));
167
        }
168
169 2
        if ($this->getAccessPointCOD()) {
170
            $node->appendChild($this->getAccessPointCOD()->toNode($document));
171
        }
172
173 2
        if (isset($this->internationalForms)) {
174
            $node->appendChild($this->internationalForms->toNode($document));
175
        }
176
177 2
        if (isset($this->deliveryConfirmation)) {
178
            $node->appendChild($this->deliveryConfirmation->toNode($document));
179
        }
180
181 2
        if (isset($this->importControlIndicator)) {
182 1
            $node->appendChild($document->createElement('ImportControlIndicator'));
183 1
        }
184
185 2
        if (isset($this->labelMethod)) {
186 1
            $node->appendChild($this->labelMethod->toNode($document));
187 1
        }
188
189 2
        if (isset($this->labelDelivery)) {
190
            $labelDeliveryNode = $node->appendChild($document->createElement('LabelDelivery'));
191
            $emailMessageNode = $labelDeliveryNode->appendChild($document->createElement('EMailMessage'));
192
            $labelDelivery = $this->getLabelDelivery();
193
            foreach ($labelDelivery as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $labelDelivery of type null|object<Ups\Entity\LabelDelivery> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
194
                if ($key == 'LabelLinkIndicator') {
195
                    $labelDeliveryNode->appendChild($document->createElement($key, $value));
196
                } elseif ($key == 'SubjectCode') {
197
                    $SubjectNode = $emailMessageNode->appendChild($document->createElement('Subject'));
198
                    $SubjectNode->appendChild($document->createElement($key, $value));
199
                } else {
200
                    $emailMessageNode->appendChild($document->createElement($key, $value));
201
                }
202
            }
203
        }
204
205 2
        if (!empty($this->notifications)) {
206
            foreach ($this->notifications as $notification) {
207
                $node->appendChild($notification->toNode($document));
208
            }
209
        }
210
211 2
        return $node;
212
    }
213
214
    /**
215
     * @return AccessPointCOD
216
     */
217 2
    public function getAccessPointCOD()
218
    {
219 2
        return $this->accessPointCOD;
220
    }
221
222
    /**
223
     * @param AccessPointCOD $accessPointCOD
224
     * @return $this
225
     */
226
    public function setAccessPointCOD($accessPointCOD)
227
    {
228
        $this->accessPointCOD = $accessPointCOD;
229
        return $this;
230
    }
231
232
    /**
233
     * @param InternationalForms $data
234
     * @return $this
235
     */
236
    public function setInternationalForms(InternationalForms $data)
237
    {
238
        $this->internationalForms = $data;
239
        return $this;
240
    }
241
242
    /**
243
     * @return InternationalForms
244
     */
245
    public function getInternationalForms()
246
    {
247
        return $this->internationalForms;
248
    }
249
250
    /**
251
     * @param LabelMethod $data
252
     * @return $this
253
     */
254 2
    public function setLabelMethod(LabelMethod $data)
255
    {
256 2
        $this->labelMethod = $data;
257 2
        return $this;
258
    }
259
260
    /**
261
     * @return null|LabelMethod
262
     */
263 1
    public function getLabelMethod()
264
    {
265 1
        return $this->labelMethod;
266
    }
267
268
    /**
269
     * @param LabelDelivery $data
270
     * @return $this
271
     */
272
    public function setLabelDelivery(LabelDelivery $data)
273
    {
274
        $this->labelDelivery = $data;
275
        return $this;
276
    }
277
278
    /**
279
     * @return null|LabelDelivery
280
     */
281
    public function getLabelDelivery()
282
    {
283
        return $this->labelDelivery;
284
    }
285
286
    /**
287
     * @param Notification $notification
288
     *
289
     * @throws \Exception
290
     *
291
     * @return $this
292
     */
293
    public function addNotification(Notification $notification)
294
    {
295
        $this->notifications[] = $notification;
296
297
        if (count($this->notifications) > 3) {
298
            throw new \Exception('Maximum 3 notifications allowed');
299
        }
300
301
        return $this;
302
    }
303
304
    /**
305
     * @return array
306
     */
307
    public function getNotifications()
308
    {
309
        return $this->notifications;
310
    }
311
312
    /**
313
     * @return mixed
314
     */
315
    public function getSaturdayPickup()
316
    {
317
        return $this->SaturdayPickup;
318
    }
319
320
    /**
321
     * @param mixed $SaturdayPickup
322
     * @return ShipmentServiceOptions
323
     */
324
    public function setSaturdayPickup($SaturdayPickup)
325
    {
326
        $this->SaturdayPickup = $SaturdayPickup;
327
        return $this;
328
    }
329
330
    /**
331
     * @return mixed
332
     */
333
    public function getSaturdayDelivery()
334
    {
335
        return $this->SaturdayDelivery;
336
    }
337
338
    /**
339
     * @param mixed $SaturdayDelivery
340
     * @return ShipmentServiceOptions
341
     */
342
    public function setSaturdayDelivery($SaturdayDelivery)
343
    {
344
        $this->SaturdayDelivery = $SaturdayDelivery;
345
        return $this;
346
    }
347
348
    /**
349
     * @return mixed
350
     */
351 2
    public function getCOD()
352
    {
353 2
        return $this->COD;
354
    }
355
356
    /**
357
     * @param mixed $COD
358
     * @return ShipmentServiceOptions
359
     */
360
    public function setCOD($COD)
361
    {
362
        $this->COD = $COD;
363
        return $this;
364
    }
365
366
367
    /**
368
     * @return CallTagARS
369
     */
370
    public function getCallTagARS()
371
    {
372
        return $this->CallTagARS;
373
    }
374
375
    /**
376
     * @param CallTagARS $CallTagARS
377
     * @return ShipmentServiceOptions
378
     */
379
    public function setCallTagARS($CallTagARS)
380
    {
381
        $this->CallTagARS = $CallTagARS;
382
        return $this;
383
    }
384
385
    /**
386
     * @return boolean
387
     */
388
    public function isNegotiatedRatesIndicator()
389
    {
390
        return $this->NegotiatedRatesIndicator;
391
    }
392
393
    /**
394
     * @param boolean $NegotiatedRatesIndicator
395
     * @return ShipmentServiceOptions
396
     */
397
    public function setNegotiatedRatesIndicator($NegotiatedRatesIndicator)
398
    {
399
        $this->NegotiatedRatesIndicator = $NegotiatedRatesIndicator;
400
        return $this;
401
    }
402
403
    /**
404
     * @return boolean
405
     */
406 2
    public function isImportControlIndicator()
407
    {
408 2
        return $this->importControlIndicator;
409
    }
410
411
    /**
412
     * @param boolean $importControlIndicator
413
     * @return ShipmentServiceOptions
414
     */
415 3
    public function setImportControlIndicator($importControlIndicator)
416
    {
417 3
        $this->importControlIndicator = $importControlIndicator;
418 3
        return $this;
419
    }
420
421
    /**
422
     * @param DeliveryConfirmation $deliveryConfirmation
423
     * @return ShipmentServiceOptions
424
     */
425
    public function setDeliveryConfirmation(DeliveryConfirmation $deliveryConfirmation)
426
    {
427
        $this->deliveryConfirmation = $deliveryConfirmation;
428
        return $this;
429
    }
430
431
    /**
432
     * @return DeliveryConfirmation|null
433
     */
434
    public function getDeliveryConfirmation()
435
    {
436
        return $this->deliveryConfirmation;
437
    }
438
439
    /**
440
     * @return boolean
441
     */
442
    public function isDirectDeliveryOnlyIndicator()
443
    {
444
        return $this->DirectDeliveryOnlyIndicator;
445
    }
446
447
    /**
448
     * @param boolean $DirectDeliveryOnlyIndicator
449
     * @return ShipmentServiceOptions
450
     */
451
    public function setDirectDeliveryOnlyIndicator($DirectDeliveryOnlyIndicator)
452
    {
453
        $this->DirectDeliveryOnlyIndicator = $DirectDeliveryOnlyIndicator;
454
        return $this;
455
    }
456
457
    /**
458
     * @return mixed
459
     */
460
    public function getDeliverToAddresseeOnlyIndicator()
461
    {
462
        return $this->DeliverToAddresseeOnlyIndicator;
463
    }
464
465
    /**
466
     * @param mixed $DeliverToAddresseeOnlyIndicator
467
     * @return ShipmentServiceOptions
468
     */
469
    public function setDeliverToAddresseeOnlyIndicator($DeliverToAddresseeOnlyIndicator)
470
    {
471
        $this->DeliverToAddresseeOnlyIndicator = $DeliverToAddresseeOnlyIndicator;
472
        return $this;
473
    }
474
}
475