Completed
Push — master ( 871c4d...79d74a )
by Stefan
03:24
created

InternationalForms::getDeclarationStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ups\Entity;
4
5
use DateTime;
6
use DOMDocument;
7
use DOMElement;
8
use Ups\NodeInterface;
9
10
class InternationalForms implements NodeInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $type = self::TYPE_INVOICE;
16
17
    /**
18
     * Form Types.
19
     */
20
    const TYPE_INVOICE = '01';
21
    const TYPE_CO = '03';
22
    const TYPE_NAFTA_CO = '04';
23
    const TYPE_PARTIAL_INVOICE = '05';
24
    const TYPE_PACKINGLIST = '06';
25
    const TYPE_CUSTOMER_GENERATED_FORMS = '07';
26
    const TYPE_AIR_FREIGHT_PACKING_LIST = '08';
27
    const TYPE_CN22_FORMS = '09';
28
    const TYPE_UPS_PREMIUM_CARE = '10';
29
    const TYPE_EEI_SHIPMENT_WITH_RETURN_SERVICE = '11';
30
31
    private static $typeNames = [
32
        '01' => 'Invoice',
33
        '03' => 'CO',
34
        '04' => 'NAFTA CO',
35
        '05' => 'Partial Invoice',
36
        '06' => 'Packinglist',
37
        '07' => 'Customer Generated Forms',
38
        '08' => 'Air Freight Packing List',
39
        '09' => 'CN22 Forms',
40
        '10' => 'UPS Premium Care',
41
        '11' => 'EEI. For shipment with return service',
42
    ];
43
44
    /**
45
     * @var string
46
     */
47
    private $termsOfShipment;
48
49
    /**
50
     * Terms of Shipment.
51
     */
52
    const TOS_COST_AND_FREIGHT = 'CFR';
53
    const TOS_COST_INSURANCE_AND_FREIGHT = 'CIF';
54
    const TOS_CARRIAGE_AND_INSURANCE_PAID = 'CIP';
55
    const TOS_CARRIAGE_PAID_TO = 'CPT';
56
    const TOS_DELIVERED_AT_FRONTIER = 'DAF';
57
    const TOS_DELIVERY_DUTY_PAID = 'DDP';
58
    const TOS_DELIVERY_DUTY_UNPAID = 'DDU';
59
    const TOS_DELIVERED_EX_QUAY = 'DEQ';
60
    const TOS_DELIVERED_EX_SHIP = 'DES';
61
    const TOS_EX_WORKS = 'EXW';
62
    const TOS_FREE_ALONGSIDE_SHIP = 'FAS';
63
    const TOS_FREE_CARRIER = 'FCA';
64
    const TOS_FREE_ON_BOARD = 'FOB';
65
66
    private static $termsOfShipmentNames = [
0 ignored issues
show
Unused Code introduced by
The property $termsOfShipmentNames is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
67
        'CFR' => 'Cost and Freight',
68
        'CIF' => 'Cost, Insurance and Freight',
69
        'CIP' => 'Carriage and Insurance Paid',
70
        'CPT' => 'Carriage Paid To',
71
        'DAF' => 'Delivered at Frontier',
72
        'DDP' => 'Delivery Duty Paid',
73
        'DDU' => 'Delivery Duty Unpaid',
74
        'DEQ' => 'Delivered Ex Quay',
75
        'DES' => 'Delivered Ex Ship',
76
        'EXW' => 'Ex Works',
77
        'FAS' => 'Free Alongside Ship',
78
        'FCA' => 'Free Carrier',
79
        'FOB' => 'Free On Board',
80
    ];
81
82
    /**
83
     * @var string
84
     */
85
    private $reasonForExport;
86
87
    /**
88
     * Reasons for export.
89
     */
90
    const RFE_SALE = 'SALE';
91
    const RFE_GIFT = 'GIFT';
92
    const RFE_SAMPLE = 'SAMPLE';
93
    const RFE_RETURN = 'RETURN';
94
    const RFE_REPAIR = 'REPAIR';
95
    const RFE_INTERCOMPANYDATA = 'INTERCOMPANYDATA';
96
97
    /**
98
     * @var string
99
     */
100
    private $comments;
101
102
    /**
103
     * @var string
104
     */
105
    private $declarationStatement;
106
107
    /**
108
     * @var string
109
     */
110
    private $currencyCode;
111
112
    /**
113
     * @var string
114
     */
115
    private $invoiceNumber;
116
117
    /**
118
     * @var DateTime
119
     */
120
    private $invoiceDate;
121
122
    /**
123
     * @var string
124
     */
125
    private $purchaseOrderNumber;
126
127
    /**
128
     * @var array
129
     */
130
    private $products = [];
131
132
    /**
133
     * @var Discount
134
     */
135
    private $discount;
136
137
    /**
138
     * @var FreightCharges
139
     */
140
    private $freightCharges;
141
142
    /**
143
     * @var bool
144
     */
145
    private $additionalDocumentIndicator;
146
147
    /**
148
     * @var EEIFilingOption
149
     */
150
    private $eeiFilingOption;
151
152
    /**
153
     * @return array
154
     */
155
    public static function getTypes()
156
    {
157
        return self::$typeNames;
158
    }
159
160
    /**
161
     * @return string
162
     */
163
    public function getTypeName()
164
    {
165
        return self::$typeNames[$this->getType()];
166
    }
167
168
    /**
169
     * @param null|object $attributes
170
     */
171 4
    public function __construct($attributes = null)
172
    {
173 4
        if (null !== $attributes) {
174 2
            if (isset($attributes->FormType)) {
175
                $this->setType($attributes->FormType);
176
            }
177 2
            if (isset($attributes->InvoiceNumber)) {
178
                $this->setInvoiceNumber($attributes->InvoiceNumber);
179
            }
180 2
            if (isset($attributes->InvoiceDate)) {
181
                $this->setInvoiceDate(new DateTime($attributes->InvoiceDate));
182
            }
183 2
            if (isset($attributes->PurchaseOrderNumber)) {
184
                $this->setPurchaseOrderNumber($attributes->PurchaseOrderNumber);
185
            }
186 2
            if (isset($attributes->TermsOfShipment)) {
187
                $this->setTermsOfShipment($attributes->TermsOfShipment);
188
            }
189 2
            if (isset($attributes->Comments)) {
190
                $this->setComments($attributes->Comments);
191
            }
192 2
            if (isset($attributes->DeclarationStatement)) {
193
                $this->setDeclarationStatement($attributes->DeclarationStatement);
194
            }
195 2
            if (isset($attributes->CurrencyCode)) {
196
                $this->setCurrencyCode($attributes->CurrencyCode);
197
            }
198 2
            if (isset($attributes->EEIFilingOption)) {
199 2
                $this->setEEIFilingOption(new EEIFilingOption($attributes->EEIFilingOption));
200 2
            }
201 2
        }
202 4
    }
203
204
    /**
205
     * @param $type string
206
     *
207
     * @return $this
208
     */
209
    public function setType($type)
210
    {
211
        $this->type = $type;
212
213
        return $this;
214
    }
215
216
    /**
217
     * @return string
218
     */
219 2
    public function getType()
220
    {
221 2
        return $this->type;
222
    }
223
224
    /**
225
     * @param $freightCharges FreightCharges
226
     *
227
     * @return $this
228
     */
229
    public function setFreightCharges(FreightCharges $freightCharges)
230
    {
231
        $this->freightCharges = $freightCharges;
232
233
        return $this;
234
    }
235
236
    /**
237
     * @return FreightCharges
238
     */
239 2
    public function getFreightCharges()
240
    {
241 2
        return $this->freightCharges;
242
    }
243
244
    /**
245
     * @param $discount Discount
246
     *
247
     * @return $this
248
     */
249
    public function setDiscount(Discount $discount)
250
    {
251
        $this->discount = $discount;
252
253
        return $this;
254
    }
255
256
    /**
257
     * @return Discount
258
     */
259 2
    public function getDiscount()
260
    {
261 2
        return $this->discount;
262
    }
263
264
    /**
265
     * @param Product $product
266
     *
267
     * @return $this
268
     */
269
    public function addProduct(Product $product)
270
    {
271
        array_push($this->products, $product);
272
273
        return $this;
274
    }
275
276
    /**
277
     * @return array
278
     */
279
    public function getProducts()
280
    {
281
        return $this->products;
282
    }
283
284
    /**
285
     * @param null|DOMDocument $document
286
     *
287
     * @return DOMElement
288
     */
289 2
    public function toNode(DOMDocument $document = null)
290
    {
291 2
        if (null === $document) {
292
            $document = new DOMDocument();
293
        }
294
295 2
        $node = $document->createElement('InternationalForms');
296
297 2
        if ($this->getType()) {
298 2
            $node->appendChild($document->createElement('FormType', $this->getType()));
299 2
        }
300 2
        if ($this->getInvoiceNumber() !== null) {
301
            $node->appendChild($document->createElement('InvoiceNumber', $this->getInvoiceNumber()));
302
        }
303 2
        if ($this->getInvoiceDate() !== null) {
304
            $node->appendChild($document->createElement('InvoiceDate', $this->getInvoiceDate()->format('Ymd')));
305
        }
306 2
        if ($this->getPurchaseOrderNumber() !== null) {
307
            $node->appendChild($document->createElement('PurchaseOrderNumber', $this->getPurchaseOrderNumber()));
308
        }
309 2
        if ($this->getTermsOfShipment() !== null) {
310
            $node->appendChild($document->createElement('TermsOfShipment', $this->getTermsOfShipment()));
311
        }
312 2
        if ($this->getReasonForExport() !== null) {
313
            $node->appendChild($document->createElement('ReasonForExport', $this->getReasonForExport()));
314
        }
315 2
        if ($this->getComments() !== null) {
316
            $node->appendChild($document->createElement('Comments', $this->getComments()));
317
        }
318 2
        if ($this->getDeclarationStatement() !== null) {
319
            $node->appendChild($document->createElement('DeclarationStatement', $this->getDeclarationStatement()));
320
        }
321 2
        if ($this->getCurrencyCode() !== null) {
322
            $node->appendChild($document->createElement('CurrencyCode', $this->getCurrencyCode()));
323
        }
324 2
        if ($this->getDiscount() !== null) {
325
            $node->appendChild($this->getDiscount()->toNode($document));
326
        }
327 2
        if ($this->getFreightCharges() !== null) {
328
            $node->appendChild($this->getFreightCharges()->toNode($document));
329
        }
330 2
        if ($this->getAdditionalDocumentIndicator() !== null) {
331
            $node->appendChild($document->createElement('AdditionalDocumentIndicator'));
332
        }
333 2
        if ($this->getEEIFilingOption() !== null) {
334 1
            $node->appendChild($this->getEEIFilingOption()->toNode($document));
335 1
        }
336 2
        foreach ($this->products as $product) {
337
            $node->appendChild($product->toNode($document));
338 2
        }
339
340 2
        return $node;
341
    }
342
343
    /**
344
     * @param $number string
345
     *
346
     * @return $this
347
     */
348
    public function setInvoiceNumber($number)
349
    {
350
        $this->invoiceNumber = $number;
351
352
        return $this;
353
    }
354
355
    /**
356
     * @return string
357
     */
358 2
    public function getInvoiceNumber()
359
    {
360 2
        return $this->invoiceNumber;
361
    }
362
363
    /**
364
     * @param DateTime $date
365
     *
366
     * @return $this
367
     */
368
    public function setInvoiceDate(DateTime $date)
369
    {
370
        $this->invoiceDate = $date;
371
372
        return $this;
373
    }
374
375
    /**
376
     * @return DateTime
377
     */
378 2
    public function getInvoiceDate()
379
    {
380 2
        return $this->invoiceDate;
381
    }
382
383
    /**
384
     * @param $number
385
     *
386
     * @return $this
387
     */
388
    public function setPurchaseOrderNumber($number)
389
    {
390
        $this->purchaseOrderNumber = $number;
391
392
        return $this;
393
    }
394
395
    /**
396
     * @return string
397
     */
398 2
    public function getPurchaseOrderNumber()
399
    {
400 2
        return $this->purchaseOrderNumber;
401
    }
402
403
    /**
404
     * @param $terms
405
     *
406
     * @return $this
407
     */
408
    public function setTermsOfShipment($terms)
409
    {
410
        $this->termsOfShipment = $terms;
411
412
        return $this;
413
    }
414
415
    /**
416
     * @return string
417
     */
418 2
    public function getTermsOfShipment()
419
    {
420 2
        return $this->termsOfShipment;
421
    }
422
423
    /**
424
     * @param $reason
425
     *
426
     * @return $this
427
     */
428
    public function setReasonForExport($reason)
429
    {
430
        if (strlen($reason) > 20) {
431
            $reason = substr($reason, 0, 20);
432
        }
433
434
        $this->reasonForExport = $reason;
435
436
        return $this;
437
    }
438
439
    /**
440
     * @return string
441
     */
442 2
    public function getReasonForExport()
443
    {
444 2
        return $this->reasonForExport;
445
    }
446
447
    /**
448
     * @param $comments
449
     *
450
     * @return $this
451
     */
452 View Code Duplication
    public function setComments($comments)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
453
    {
454
        if (strlen($comments) > 150) {
455
            $comments = substr($comments, 0, 150);
456
        }
457
458
        $this->comments = $comments;
459
460
        return $this;
461
    }
462
463
    /**
464
     * @return string
465
     */
466 2
    public function getComments()
467
    {
468 2
        return $this->comments;
469
    }
470
471
    /**
472
     * @param string $statement
473
     *
474
     * @return $this
475
     */
476
    public function setDeclarationStatement($statement)
477
    {
478
        $this->declarationStatement = $statement;
479
480
        return $this;
481
    }
482
483
    /**
484
     * @return string
485
     */
486 2
    public function getDeclarationStatement()
487
    {
488 2
        return $this->declarationStatement;
489
    }
490
491
    /**
492
     * @param $code
493
     *
494
     * @return $this
495
     */
496
    public function setCurrencyCode($code)
497
    {
498
        $this->currencyCode = $code;
499
500
        return $this;
501
    }
502
503
    /**
504
     * @return string
505
     */
506 2
    public function getCurrencyCode()
507
    {
508 2
        return $this->currencyCode;
509
    }
510
511
    /**
512
     * @param $additionalDocumentIndicator
513
     *
514
     * @return $this
515
     */
516
    public function setAdditionalDocumentIndicator($additionalDocumentIndicator)
517
    {
518
        $this->additionalDocumentIndicator = $additionalDocumentIndicator;
519
    }
520
521
    /**
522
     * @return bool
523
     */
524 2
    public function getAdditionalDocumentIndicator()
525
    {
526 2
        return $this->additionalDocumentIndicator;
527
    }
528
529
    /**
530
     * @param EEIFilingOption $eeiFilingOption
531
     *
532
     * @return $this
533
     */
534 3
    public function setEEIFilingOption(EEIFilingOption $eeiFilingOption)
535
    {
536 3
        $this->eeiFilingOption = $eeiFilingOption;
537
538 3
        return $this;
539
    }
540
541
    /**
542
     * @return EEIFilingOption
543
     */
544 4
    public function getEEIFilingOption()
545
    {
546 4
        return $this->eeiFilingOption;
547
    }
548
}
549