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

ShipmentServiceOptions::addNotification()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 6
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 ImportControlIndicator
73
     */
74
    private $importControlIndicator;
75
76
    /**
77
     * @param null $response
78
     */
79 10
    public function __construct($response = null)
80
    {
81 10
        $this->CallTagARS = new CallTagARS();
82
83 10
        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
                var_dump("HERE");
0 ignored issues
show
Security Debugging Code introduced by
var_dump('HERE'); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
116 2
                $this->setLabelMethod(new LabelMethod($response->LabelMethod));
117 2
            }
118 2
        }
119 10
    }
120
121
    /**
122
     * @param null|DOMDocument $document
123
     *
124
     * @return DOMElement
125
     */
126 2
    public function toNode(DOMDocument $document = null)
127
    {
128 2
        if (null === $document) {
129
            $document = new DOMDocument();
130
        }
131
132 2
        $node = $document->createElement('ShipmentServiceOptions');
133
134 2
        if (isset($this->DirectDeliveryOnlyIndicator)) {
135
            $node->appendChild($document->createElement('DirectDeliveryOnlyIndicator'));
136
        }
137
138 2
        if (isset($this->DeliverToAddresseeOnlyIndicator)) {
139
            $node->appendChild($document->createElement('DeliverToAddresseeOnlyIndicator'));
140
        }
141
142 2
        if (isset($this->SaturdayPickup)) {
143
            $node->appendChild($document->createElement('SaturdayPickup'));
144
        }
145
146 2
        if (isset($this->SaturdayDelivery)) {
147
            $node->appendChild($document->createElement('SaturdayDelivery'));
148
        }
149
150 2
        if ($this->getCOD()) {
151
            $node->appendChild($this->getCOD()->toNode($document));
152
        }
153
154 2
        if ($this->getAccessPointCOD()) {
155
            $node->appendChild($this->getAccessPointCOD()->toNode($document));
156
        }
157
158 2
        if (isset($this->internationalForms)) {
159
            $node->appendChild($this->internationalForms->toNode($document));
160
        }
161
162 2
        if (isset($this->importControlIndicator)) {
163 1
            $node->appendChild($document->createElement('ImportControlIndicator'));
164 1
        }
165
166 2
        if (isset($this->labelMethod)) {
167 1
            $node->appendChild($this->labelMethod->toNode($document));
168 1
        }
169
170 2
        if (!empty($this->notifications)) {
171
            foreach ($this->notifications as $notification) {
172
                $node->appendChild($notification->toNode($document));
173
            }
174
        }
175
176 2
        return $node;
177
    }
178
179
    /**
180
     * @return AccessPointCOD
181
     */
182 2
    public function getAccessPointCOD()
183
    {
184 2
        return $this->accessPointCOD;
185
    }
186
187
    /**
188
     * @param $accessPointCOD
189
     * @return $this
190
     */
191
    public function setAccessPointCOD($accessPointCOD)
192
    {
193
        $this->accessPointCOD = $accessPointCOD;
194
        return $this;
195
    }
196
197
    /**
198
     * @param InternationalForms $data
199
     * @return $this
200
     */
201
    public function setInternationalForms(InternationalForms $data)
202
    {
203
        $this->internationalForms = $data;
204
        return $this;
205
    }
206
207
    /**
208
     * @return mixed
209
     */
210
    public function getInternationalForms()
211
    {
212
        return $this->internationalForms;
213
    }
214
215
    /**
216
     * @param LabelMethod $data
217
     * @return $this
218
     */
219 2
    public function setLabelMethod(LabelMethod $data)
220
    {
221 2
        $this->labelMethod = $data;
222 2
        return $this;
223
    }
224
225
    /**
226
     * @return mixed
227
     */
228 1
    public function getLabelMethod()
229
    {
230 1
        return $this->labelMethod;
231
    }
232
233
    /**
234
     * @param Notification $notification
235
     *
236
     * @throws \Exception
237
     *
238
     * @return $this
239
     */
240
    public function addNotification(Notification $notification)
241
    {
242
        $this->notifications[] = $notification;
243
244
        if (count($this->notifications) > 3) {
245
            throw new \Exception('Maximum 3 notifications allowed');
246
        }
247
248
        return $this;
249
    }
250
251
    /**
252
     * @return array
253
     */
254
    public function getNotifications()
255
    {
256
        return $this->notifications;
257
    }
258
259
    /**
260
     * @return mixed
261
     */
262
    public function getSaturdayPickup()
263
    {
264
        return $this->SaturdayPickup;
265
    }
266
267
    /**
268
     * @param mixed $SaturdayPickup
269
     * @return ShipmentServiceOptions
270
     */
271
    public function setSaturdayPickup($SaturdayPickup)
272
    {
273
        $this->SaturdayPickup = $SaturdayPickup;
274
        return $this;
275
    }
276
277
    /**
278
     * @return mixed
279
     */
280
    public function getSaturdayDelivery()
281
    {
282
        return $this->SaturdayDelivery;
283
    }
284
285
    /**
286
     * @param mixed $SaturdayDelivery
287
     * @return ShipmentServiceOptions
288
     */
289
    public function setSaturdayDelivery($SaturdayDelivery)
290
    {
291
        $this->SaturdayDelivery = $SaturdayDelivery;
292
        return $this;
293
    }
294
295
    /**
296
     * @return mixed
297
     */
298 2
    public function getCOD()
299
    {
300 2
        return $this->COD;
301
    }
302
303
    /**
304
     * @param mixed $COD
305
     * @return ShipmentServiceOptions
306
     */
307
    public function setCOD($COD)
308
    {
309
        $this->COD = $COD;
310
        return $this;
311
    }
312
313
314
    /**
315
     * @return CallTagARS
316
     */
317
    public function getCallTagARS()
318
    {
319
        return $this->CallTagARS;
320
    }
321
322
    /**
323
     * @param CallTagARS $CallTagARS
324
     * @return ShipmentServiceOptions
325
     */
326
    public function setCallTagARS($CallTagARS)
327
    {
328
        $this->CallTagARS = $CallTagARS;
329
        return $this;
330
    }
331
332
    /**
333
     * @return boolean
334
     */
335
    public function isNegotiatedRatesIndicator()
336
    {
337
        return $this->NegotiatedRatesIndicator;
338
    }
339
340
    /**
341
     * @param boolean $NegotiatedRatesIndicator
342
     * @return ShipmentServiceOptions
343
     */
344
    public function setNegotiatedRatesIndicator($NegotiatedRatesIndicator)
345
    {
346
        $this->NegotiatedRatesIndicator = $NegotiatedRatesIndicator;
347
        return $this;
348
    }
349
350
    /**
351
     * @return boolean
352
     */
353 3
    public function isImportControlIndicator()
354
    {
355 3
        return isset($this->importControlIndicator);
356
    }
357
358
    /**
359
     * @param boolean $importControlIndicator
360
     * @return ShipmentServiceOptions
361
     */
362 3
    public function setImportControlIndicator($importControlIndicator)
363
    {
364 3
        $this->importControlIndicator = $importControlIndicator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $importControlIndicator of type boolean is incompatible with the declared type object<Ups\Entity\ImportControlIndicator> of property $importControlIndicator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
365 3
        return $this;
366
    }
367
368
    /**
369
     * @return ShipmentServiceOptions
370
     */
371 1
    public function unsImportControlIndicator()
372
    {
373 1
        unset($this->importControlIndicator);
374 1
        return $this;
375
    }
376
377
    /**
378
     * @return boolean
379
     */
380
    public function isDirectDeliveryOnlyIndicator()
381
    {
382
        return $this->DirectDeliveryOnlyIndicator;
383
    }
384
385
    /**
386
     * @param boolean $DirectDeliveryOnlyIndicator
387
     * @return ShipmentServiceOptions
388
     */
389
    public function setDirectDeliveryOnlyIndicator($DirectDeliveryOnlyIndicator)
390
    {
391
        $this->DirectDeliveryOnlyIndicator = $DirectDeliveryOnlyIndicator;
392
        return $this;
393
    }
394
395
    /**
396
     * @return mixed
397
     */
398
    public function getDeliverToAddresseeOnlyIndicator()
399
    {
400
        return $this->DeliverToAddresseeOnlyIndicator;
401
    }
402
403
    /**
404
     * @param mixed $DeliverToAddresseeOnlyIndicator
405
     * @return ShipmentServiceOptions
406
     */
407
    public function setDeliverToAddresseeOnlyIndicator($DeliverToAddresseeOnlyIndicator)
408
    {
409
        $this->DeliverToAddresseeOnlyIndicator = $DeliverToAddresseeOnlyIndicator;
410
        return $this;
411
    }
412
}
413