Completed
Pull Request — master (#86)
by
unknown
03:35
created

setNegotiatedRatesIndicator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
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 array
58
     */
59
    private $notifications = [];
60
61
    /**
62
     * @param null $response
63
     */
64 1
    public function __construct($response = null)
65
    {
66 1
        $this->CallTagARS = new CallTagARS();
67
68 1
        if (null != $response) {
69
            if (isset($response->SaturdayPickup)) {
70
                $this->SaturdayPickup = $response->SaturdayPickup;
71
            }
72
            if (isset($response->SaturdayDelivery)) {
73
                $this->SaturdayDelivery = $response->SaturdayDelivery;
74
            }
75
            if (isset($response->COD)) {
76
                $this->COD = $response->COD;
77
            }
78
            if (isset($response->CallTagARS)) {
79
                $this->CallTagARS = new CallTagARS($response->CallTagARS);
80
            }
81
            if (isset($response->NegotiatedRatesIndicator)) {
82
                $this->NegotiatedRatesIndicator = $response->NegotiatedRatesIndicator;
83
            }
84
            if (isset($response->DirectDeliveryOnlyIndicator)) {
85
                $this->DirectDeliveryOnlyIndicator = $response->DirectDeliveryOnlyIndicator;
86
            }
87
            if (isset($response->DeliverToAddresseeOnlyIndicator)) {
88
                $this->DeliverToAddresseeOnlyIndicator = $response->DeliverToAddresseeOnlyIndicator;
89
            }
90
            if (isset($response->InternationalForms)) {
91
                $this->setInternationalForms($response->InternationalForms);
92
            }
93
        }
94 1
    }
95
96
    /**
97
     * @param null|DOMDocument $document
98
     *
99
     * @return DOMElement
100
     */
101
    public function toNode(DOMDocument $document = null)
102
    {
103
        if (null === $document) {
104
            $document = new DOMDocument();
105
        }
106
107
        $node = $document->createElement('ShipmentServiceOptions');
108
109
        if (isset($this->DirectDeliveryOnlyIndicator)) {
110
            $node->appendChild($document->createElement('DirectDeliveryOnlyIndicator'));
111
        }
112
113
        if (isset($this->DeliverToAddresseeOnlyIndicator)) {
114
            $node->appendChild($document->createElement('DeliverToAddresseeOnlyIndicator'));
115
        }
116
117
        if (isset($this->SaturdayPickup)) {
118
            $node->appendChild($document->createElement('SaturdayPickup'));
119
        }
120
121
        if (isset($this->SaturdayDelivery)) {
122
            $node->appendChild($document->createElement('SaturdayDelivery'));
123
        }
124
125
        if ($this->getCOD()) {
126
            $node->appendChild($this->getCOD()->toNode($document));
127
        }
128
129
        if (isset($this->internationalForms)) {
130
            $node->appendChild($this->internationalForms->toNode($document));
131
        }
132
133
        if (!empty($this->notifications)) {
134
            foreach ($this->notifications as $notification) {
135
                $node->appendChild($notification->toNode($document));
136
            }
137
        }
138
139
        return $node;
140
    }
141
142
    /**
143
     * @param InternationalForms $data
144
     */
145
    public function setInternationalForms(InternationalForms $data)
146
    {
147
        $this->internationalForms = $data;
148
    }
149
150
    /**
151
     * @return mixed
152
     */
153
    public function getInternationalForms()
154
    {
155
        return $this->internationalForms;
156
    }
157
158
    /**
159
     * @param Notification $notification
160
     *
161
     * @throws \Exception
162
     *
163
     * @return $this
164
     */
165
    public function addNotification(Notification $notification)
166
    {
167
        $this->notifications[] = $notification;
168
169
        if (count($this->notifications) > 3) {
170
            throw new \Exception('Maximum 3 notifications allowed');
171
        }
172
173
        return $this;
174
    }
175
176
    /**
177
     * @return array
178
     */
179
    public function getNotifications()
180
    {
181
        return $this->notifications;
182
    }
183
184
    /**
185
     * @return mixed
186
     */
187
    public function getSaturdayPickup()
188
    {
189
        return $this->SaturdayPickup;
190
    }
191
192
    /**
193
     * @param mixed $SaturdayPickup
194
     * @return ShipmentServiceOptions
195
     */
196
    public function setSaturdayPickup($SaturdayPickup)
197
    {
198
        $this->SaturdayPickup = $SaturdayPickup;
199
        return $this;
200
    }
201
202
    /**
203
     * @return mixed
204
     */
205
    public function getSaturdayDelivery()
206
    {
207
        return $this->SaturdayDelivery;
208
    }
209
210
    /**
211
     * @param mixed $SaturdayDelivery
212
     * @return ShipmentServiceOptions
213
     */
214
    public function setSaturdayDelivery($SaturdayDelivery)
215
    {
216
        $this->SaturdayDelivery = $SaturdayDelivery;
217
        return $this;
218
    }
219
220
    /**
221
     * @return mixed
222
     */
223
    public function getCOD()
224
    {
225
        return $this->COD;
226
    }
227
228
    /**
229
     * @param mixed $COD
230
     * @return ShipmentServiceOptions
231
     */
232
    public function setCOD($COD)
233
    {
234
        $this->COD = $COD;
235
        return $this;
236
    }
237
238
239
    /**
240
     * @return CallTagARS
241
     */
242
    public function getCallTagARS()
243
    {
244
        return $this->CallTagARS;
245
    }
246
247
    /**
248
     * @param CallTagARS $CallTagARS
249
     * @return ShipmentServiceOptions
250
     */
251
    public function setCallTagARS($CallTagARS)
252
    {
253
        $this->CallTagARS = $CallTagARS;
254
        return $this;
255
    }
256
257
    /**
258
     * @return boolean
259
     */
260
    public function isNegotiatedRatesIndicator()
261
    {
262
        return $this->NegotiatedRatesIndicator;
263
    }
264
265
    /**
266
     * @param boolean $NegotiatedRatesIndicator
267
     * @return ShipmentServiceOptions
268
     */
269
    public function setNegotiatedRatesIndicator($NegotiatedRatesIndicator)
270
    {
271
        $this->NegotiatedRatesIndicator = $NegotiatedRatesIndicator;
272
        return $this;
273
    }
274
275
    /**
276
     * @return boolean
277
     */
278
    public function isDirectDeliveryOnlyIndicator()
279
    {
280
        return $this->DirectDeliveryOnlyIndicator;
281
    }
282
283
    /**
284
     * @param boolean $DirectDeliveryOnlyIndicator
285
     * @return ShipmentServiceOptions
286
     */
287
    public function setDirectDeliveryOnlyIndicator($DirectDeliveryOnlyIndicator)
288
    {
289
        $this->DirectDeliveryOnlyIndicator = $DirectDeliveryOnlyIndicator;
290
        return $this;
291
    }
292
293
    /**
294
     * @return mixed
295
     */
296
    public function getDeliverToAddresseeOnlyIndicator()
297
    {
298
        return $this->DeliverToAddresseeOnlyIndicator;
299
    }
300
301
    /**
302
     * @param mixed $DeliverToAddresseeOnlyIndicator
303
     * @return ShipmentServiceOptions
304
     */
305
    public function setDeliverToAddresseeOnlyIndicator($DeliverToAddresseeOnlyIndicator)
306
    {
307
        $this->DeliverToAddresseeOnlyIndicator = $DeliverToAddresseeOnlyIndicator;
308
        return $this;
309
    }
310
}
311