Completed
Push — master ( 921a28...d5ebea )
by Stefan
04:36 queued 01:28
created

InternationalForms::getProducts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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 array
14
     */
15
    private $types = [
16
        self::TYPE_INVOICE
17
    ];
18
19
    /**
20
     * Form Types.
21
     */
22
    const TYPE_INVOICE = '01';
23
    const TYPE_CO = '03';
24
    const TYPE_NAFTA_CO = '04';
25
    const TYPE_PARTIAL_INVOICE = '05';
26
    const TYPE_PACKINGLIST = '06';
27
    const TYPE_CUSTOMER_GENERATED_FORMS = '07';
28
    const TYPE_AIR_FREIGHT_PACKING_LIST = '08';
29
    const TYPE_CN22_FORMS = '09';
30
    const TYPE_UPS_PREMIUM_CARE = '10';
31
    const TYPE_EEI_SHIPMENT_WITH_RETURN_SERVICE = '11';
32
33
    private static $typeNames = [
34
        '01' => 'Invoice',
35
        '03' => 'CO',
36
        '04' => 'NAFTA CO',
37
        '05' => 'Partial Invoice',
38
        '06' => 'Packinglist',
39
        '07' => 'Customer Generated Forms',
40
        '08' => 'Air Freight Packing List',
41
        '09' => 'CN22 Forms',
42
        '10' => 'UPS Premium Care',
43
        '11' => 'EEI. For shipment with return service',
44
    ];
45
46
    /**
47
     * @var string
48
     */
49
    private $termsOfShipment;
50
51
    /**
52
     * Terms of Shipment.
53
     */
54
    const TOS_COST_AND_FREIGHT = 'CFR';
55
    const TOS_COST_INSURANCE_AND_FREIGHT = 'CIF';
56
    const TOS_CARRIAGE_AND_INSURANCE_PAID = 'CIP';
57
    const TOS_CARRIAGE_PAID_TO = 'CPT';
58
    const TOS_DELIVERED_AT_FRONTIER = 'DAF';
59
    const TOS_DELIVERY_DUTY_PAID = 'DDP';
60
    const TOS_DELIVERY_DUTY_UNPAID = 'DDU';
61
    const TOS_DELIVERED_EX_QUAY = 'DEQ';
62
    const TOS_DELIVERED_EX_SHIP = 'DES';
63
    const TOS_EX_WORKS = 'EXW';
64
    const TOS_FREE_ALONGSIDE_SHIP = 'FAS';
65
    const TOS_FREE_CARRIER = 'FCA';
66
    const TOS_FREE_ON_BOARD = 'FOB';
67
68
    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...
69
        'CFR' => 'Cost and Freight',
70
        'CIF' => 'Cost, Insurance and Freight',
71
        'CIP' => 'Carriage and Insurance Paid',
72
        'CPT' => 'Carriage Paid To',
73
        'DAF' => 'Delivered at Frontier',
74
        'DDP' => 'Delivery Duty Paid',
75
        'DDU' => 'Delivery Duty Unpaid',
76
        'DEQ' => 'Delivered Ex Quay',
77
        'DES' => 'Delivered Ex Ship',
78
        'EXW' => 'Ex Works',
79
        'FAS' => 'Free Alongside Ship',
80
        'FCA' => 'Free Carrier',
81
        'FOB' => 'Free On Board',
82
    ];
83
84
    /**
85
     * @var string
86
     */
87
    private $reasonForExport;
88
89
    /**
90
     * Reasons for export.
91
     */
92
    const RFE_SALE = 'SALE';
93
    const RFE_GIFT = 'GIFT';
94
    const RFE_SAMPLE = 'SAMPLE';
95
    const RFE_RETURN = 'RETURN';
96
    const RFE_REPAIR = 'REPAIR';
97
    const RFE_INTERCOMPANYDATA = 'INTERCOMPANYDATA';
98
99
    /**
100
     * @var string
101
     */
102
    private $comments;
103
104
    /**
105
     * @var string
106
     */
107
    private $declarationStatement;
108
109
    /**
110
     * @var string
111
     */
112
    private $currencyCode;
113
114
    /**
115
     * @var string
116
     */
117
    private $invoiceNumber;
118
119
    /**
120
     * @var DateTime
121
     */
122
    private $invoiceDate;
123
124
    /**
125
     * @var string
126
     */
127
    private $purchaseOrderNumber;
128
129
    /**
130
     * @var array
131
     */
132
    private $products = [];
133
134
    /**
135
     * @var Discount
136
     */
137
    private $discount;
138
139
    /**
140
     * @var FreightCharges
141
     */
142
    private $freightCharges;
143
144
    /**
145
     * @var bool
146
     */
147
    private $additionalDocumentIndicator;
148
149
    /**
150
     * @var EEIFilingOption
151
     */
152
    private $eeiFilingOption;
153
154
    /**
155
     * @return array
156
     */
157
    public static function getFormTypes()
158
    {
159
        return self::$typeNames;
160
    }
161
162
    /**
163
     * @param string $type
164
     *
165
     * @return string
166
     */
167
    public function getFormTypeName($type)
168
    {
169
        return self::$typeNames[$type];
170
    }
171
172
    /**
173
     * @param null|object $attributes
174
     */
175 4
    public function __construct($attributes = null)
176
    {
177 4
        if (null !== $attributes) {
178 2
            if (isset($attributes->FormType)) {
179
                $this->setType($attributes->FormType);
180
            }
181 2
            if (isset($attributes->InvoiceNumber)) {
182
                $this->setInvoiceNumber($attributes->InvoiceNumber);
183
            }
184 2
            if (isset($attributes->InvoiceDate)) {
185
                $this->setInvoiceDate(new DateTime($attributes->InvoiceDate));
186
            }
187 2
            if (isset($attributes->PurchaseOrderNumber)) {
188
                $this->setPurchaseOrderNumber($attributes->PurchaseOrderNumber);
189
            }
190 2
            if (isset($attributes->TermsOfShipment)) {
191
                $this->setTermsOfShipment($attributes->TermsOfShipment);
192
            }
193 2
            if (isset($attributes->Comments)) {
194
                $this->setComments($attributes->Comments);
195
            }
196 2
            if (isset($attributes->DeclarationStatement)) {
197
                $this->setDeclarationStatement($attributes->DeclarationStatement);
198
            }
199 2
            if (isset($attributes->CurrencyCode)) {
200
                $this->setCurrencyCode($attributes->CurrencyCode);
201
            }
202 2
            if (isset($attributes->EEIFilingOption)) {
203 2
                $this->setEEIFilingOption(new EEIFilingOption($attributes->EEIFilingOption));
204 2
            }
205 2
        }
206 4
    }
207
208
    /**
209
     * @param $type string
210
     *
211
     * @return $this
212
     */
213
    public function setType($type)
214
    {
215
        return $this->setTypes([$type]);
216
    }
217
218
    /**
219
     * @param array $types
220
     *
221
     * @return $this
222
     */
223
    public function setTypes(array $types)
224
    {
225
        $this->types = $types;
226
227
        return $this;
228
    }
229
230
    /**
231
     * @return string
232
     */
233 2
    public function getTypes()
234
    {
235 2
        return $this->types;
236
    }
237
238
    /**
239
     * @param $freightCharges FreightCharges
240
     *
241
     * @return $this
242
     */
243
    public function setFreightCharges(FreightCharges $freightCharges)
244
    {
245
        $this->freightCharges = $freightCharges;
246
247
        return $this;
248
    }
249
250
    /**
251
     * @return FreightCharges
252
     */
253 2
    public function getFreightCharges()
254
    {
255 2
        return $this->freightCharges;
256
    }
257
258
    /**
259
     * @param $discount Discount
260
     *
261
     * @return $this
262
     */
263
    public function setDiscount(Discount $discount)
264
    {
265
        $this->discount = $discount;
266
267
        return $this;
268
    }
269
270
    /**
271
     * @return Discount
272
     */
273 2
    public function getDiscount()
274
    {
275 2
        return $this->discount;
276
    }
277
278
    /**
279
     * @param Product $product
280
     *
281
     * @return $this
282
     */
283
    public function addProduct(Product $product)
284
    {
285
        array_push($this->products, $product);
286
287
        return $this;
288
    }
289
290
    /**
291
     * @return array
292
     */
293
    public function getProducts()
294
    {
295
        return $this->products;
296
    }
297
298
    /**
299
     * @param null|DOMDocument $document
300
     *
301
     * @return DOMElement
302
     */
303 2
    public function toNode(DOMDocument $document = null)
304
    {
305 2
        if (null === $document) {
306
            $document = new DOMDocument();
307
        }
308
309 2
        $node = $document->createElement('InternationalForms');
310
311 2
        foreach ($this->getTypes() as $type) {
312 2
            $node->appendChild($document->createElement('FormType', $type));
313 2
        }
314 2
        if ($this->getInvoiceNumber() !== null) {
315
            $node->appendChild($document->createElement('InvoiceNumber', $this->getInvoiceNumber()));
316
        }
317 2
        if ($this->getInvoiceDate() !== null) {
318
            $node->appendChild($document->createElement('InvoiceDate', $this->getInvoiceDate()->format('Ymd')));
319
        }
320 2
        if ($this->getPurchaseOrderNumber() !== null) {
321
            $node->appendChild($document->createElement('PurchaseOrderNumber', $this->getPurchaseOrderNumber()));
322
        }
323 2
        if ($this->getTermsOfShipment() !== null) {
324
            $node->appendChild($document->createElement('TermsOfShipment', $this->getTermsOfShipment()));
325
        }
326 2
        if ($this->getReasonForExport() !== null) {
327
            $node->appendChild($document->createElement('ReasonForExport', $this->getReasonForExport()));
328
        }
329 2
        if ($this->getComments() !== null) {
330
            $node->appendChild($document->createElement('Comments', $this->getComments()));
331
        }
332 2
        if ($this->getDeclarationStatement() !== null) {
333
            $node->appendChild($document->createElement('DeclarationStatement', $this->getDeclarationStatement()));
334
        }
335 2
        if ($this->getCurrencyCode() !== null) {
336
            $node->appendChild($document->createElement('CurrencyCode', $this->getCurrencyCode()));
337
        }
338 2
        if ($this->getDiscount() !== null) {
339
            $node->appendChild($this->getDiscount()->toNode($document));
340
        }
341 2
        if ($this->getFreightCharges() !== null) {
342
            $node->appendChild($this->getFreightCharges()->toNode($document));
343
        }
344 2
        if ($this->getAdditionalDocumentIndicator() !== null) {
345
            $node->appendChild($document->createElement('AdditionalDocumentIndicator'));
346
        }
347 2
        if ($this->getEEIFilingOption() !== null) {
348 1
            $node->appendChild($this->getEEIFilingOption()->toNode($document));
349 1
        }
350 2
        foreach ($this->products as $product) {
351
            $node->appendChild($product->toNode($document));
352 2
        }
353
354 2
        return $node;
355
    }
356
357
    /**
358
     * @param $number string
359
     *
360
     * @return $this
361
     */
362
    public function setInvoiceNumber($number)
363
    {
364
        $this->invoiceNumber = $number;
365
366
        return $this;
367
    }
368
369
    /**
370
     * @return string
371
     */
372 2
    public function getInvoiceNumber()
373
    {
374 2
        return $this->invoiceNumber;
375
    }
376
377
    /**
378
     * @param DateTime $date
379
     *
380
     * @return $this
381
     */
382
    public function setInvoiceDate(DateTime $date)
383
    {
384
        $this->invoiceDate = $date;
385
386
        return $this;
387
    }
388
389
    /**
390
     * @return DateTime
391
     */
392 2
    public function getInvoiceDate()
393
    {
394 2
        return $this->invoiceDate;
395
    }
396
397
    /**
398
     * @param $number
399
     *
400
     * @return $this
401
     */
402
    public function setPurchaseOrderNumber($number)
403
    {
404
        $this->purchaseOrderNumber = $number;
405
406
        return $this;
407
    }
408
409
    /**
410
     * @return string
411
     */
412 2
    public function getPurchaseOrderNumber()
413
    {
414 2
        return $this->purchaseOrderNumber;
415
    }
416
417
    /**
418
     * @param $terms
419
     *
420
     * @return $this
421
     */
422
    public function setTermsOfShipment($terms)
423
    {
424
        $this->termsOfShipment = $terms;
425
426
        return $this;
427
    }
428
429
    /**
430
     * @return string
431
     */
432 2
    public function getTermsOfShipment()
433
    {
434 2
        return $this->termsOfShipment;
435
    }
436
437
    /**
438
     * @param $reason
439
     *
440
     * @return $this
441
     */
442
    public function setReasonForExport($reason)
443
    {
444
        if (strlen($reason) > 20) {
445
            $reason = substr($reason, 0, 20);
446
        }
447
448
        $this->reasonForExport = $reason;
449
450
        return $this;
451
    }
452
453
    /**
454
     * @return string
455
     */
456 2
    public function getReasonForExport()
457
    {
458 2
        return $this->reasonForExport;
459
    }
460
461
    /**
462
     * @param $comments
463
     *
464
     * @return $this
465
     */
466 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...
467
    {
468
        if (strlen($comments) > 150) {
469
            $comments = substr($comments, 0, 150);
470
        }
471
472
        $this->comments = $comments;
473
474
        return $this;
475
    }
476
477
    /**
478
     * @return string
479
     */
480 2
    public function getComments()
481
    {
482 2
        return $this->comments;
483
    }
484
485
    /**
486
     * @param string $statement
487
     *
488
     * @return $this
489
     */
490
    public function setDeclarationStatement($statement)
491
    {
492
        $this->declarationStatement = $statement;
493
494
        return $this;
495
    }
496
497
    /**
498
     * @return string
499
     */
500 2
    public function getDeclarationStatement()
501
    {
502 2
        return $this->declarationStatement;
503
    }
504
505
    /**
506
     * @param $code
507
     *
508
     * @return $this
509
     */
510
    public function setCurrencyCode($code)
511
    {
512
        $this->currencyCode = $code;
513
514
        return $this;
515
    }
516
517
    /**
518
     * @return string
519
     */
520 2
    public function getCurrencyCode()
521
    {
522 2
        return $this->currencyCode;
523
    }
524
525
    /**
526
     * @param $additionalDocumentIndicator
527
     *
528
     * @return $this
529
     */
530
    public function setAdditionalDocumentIndicator($additionalDocumentIndicator)
531
    {
532
        $this->additionalDocumentIndicator = $additionalDocumentIndicator;
533
    }
534
535
    /**
536
     * @return bool
537
     */
538 2
    public function getAdditionalDocumentIndicator()
539
    {
540 2
        return $this->additionalDocumentIndicator;
541
    }
542
543
    /**
544
     * @param EEIFilingOption $eeiFilingOption
545
     *
546
     * @return $this
547
     */
548 3
    public function setEEIFilingOption(EEIFilingOption $eeiFilingOption)
549
    {
550 3
        $this->eeiFilingOption = $eeiFilingOption;
551
552 3
        return $this;
553
    }
554
555
    /**
556
     * @return EEIFilingOption
557
     */
558 4
    public function getEEIFilingOption()
559
    {
560 4
        return $this->eeiFilingOption;
561
    }
562
}
563