Test Failed
Pull Request — master (#181)
by
unknown
02:58
created

InternationalForms   C

Complexity

Total Complexity 60

Size/Duplication

Total Lines 553
Duplicated Lines 1.81 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 41.61%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 60
c 1
b 0
f 0
lcom 2
cbo 3
dl 10
loc 553
ccs 67
cts 161
cp 0.4161
rs 6.0975

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like InternationalForms often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use InternationalForms, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 168 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
0 ignored issues
show
Bug introduced by
Possible parse error: class missing opening or closing brace
Loading history...
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 = [
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
<<<<<<< HEAD
146
     * @var bool
147
     */
148
    private $additionalDocumentIndicator;
149
150
    /**
151
     * @var EEIFilingOption
152
     */
153
    private $eeiFilingOption;
154
=======
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_IS_IDENTICAL, expecting T_FUNCTION or T_CONST
Loading history...
155
     * @var OtherCharges
156
     */
157
    private $otherCharges;
158
159
    /**
160
     * @var string $declarationStatement
161
     */
162
    private $declarationStatement;
163
>>>>>>> develop
164
165
    /**
166
     * @return array
167
     */
168
    public static function getFormTypes()
169
    {
170
        return self::$typeNames;
171
    }
172
173
    /**
174
     * @param string $type
175 4
     *
176
     * @return string
177 4
     */
178 2
    public function getFormTypeName($type)
179
    {
180
        return self::$typeNames[$type];
181 2
    }
182
183
    /**
184 2
     * @param null|object $attributes
185
     */
186
    public function __construct($attributes = null)
187 2
    {
188
        if (null !== $attributes) {
189
            if (isset($attributes->FormType)) {
190 2
                $this->setType($attributes->FormType);
191
            }
192
            if (isset($attributes->InvoiceNumber)) {
193 2
                $this->setInvoiceNumber($attributes->InvoiceNumber);
194
            }
195
            if (isset($attributes->InvoiceDate)) {
196 2
                $this->setInvoiceDate(new DateTime($attributes->InvoiceDate));
197
            }
198
            if (isset($attributes->PurchaseOrderNumber)) {
199 2
                $this->setPurchaseOrderNumber($attributes->PurchaseOrderNumber);
200
            }
201
            if (isset($attributes->TermsOfShipment)) {
202 2
                $this->setTermsOfShipment($attributes->TermsOfShipment);
203 2
            }
204 2
            if (isset($attributes->Comments)) {
205 2
                $this->setComments($attributes->Comments);
206 4
            }
207
            if (isset($attributes->DeclarationStatement)) {
208
                $this->setDeclarationStatement($attributes->DeclarationStatement);
209
            }
210
            if (isset($attributes->CurrencyCode)) {
211
                $this->setCurrencyCode($attributes->CurrencyCode);
212
            }
213
<<<<<<< HEAD
214
            if (isset($attributes->EEIFilingOption)) {
215
                $this->setEEIFilingOption(new EEIFilingOption($attributes->EEIFilingOption));
216
=======
217
            if (isset($attributes->DeclarationStatement)) {
218
                $this->setDeclarationStatement($attributes->DeclarationStatement);
219
>>>>>>> develop
220
            }
221
        }
222
    }
223
224
    /**
225
     * @param $type string
226
     *
227
     * @return $this
228
     */
229
    public function setType($type)
230
    {
231
        return $this->setTypes([$type]);
232
    }
233 2
234
    /**
235 2
     * @param array $types
236
     *
237
     * @return $this
238
     */
239
    public function setTypes(array $types)
240
    {
241
        $this->types = $types;
242
243
        return $this;
244
    }
245
246
    /**
247
     * @return string
248
     */
249
    public function getTypes()
250
    {
251
        return $this->types;
252
    }
253 2
254
    /**
255 2
     * @param $freightCharges FreightCharges
256
     *
257
     * @return $this
258
     */
259
    public function setFreightCharges(FreightCharges $freightCharges)
260
    {
261
        $this->freightCharges = $freightCharges;
262
263
        return $this;
264
    }
265
266
    /**
267
     * @return FreightCharges
268
     */
269
    public function getFreightCharges()
270
    {
271
        return $this->freightCharges;
272
    }
273 2
274
    /**
275 2
     * @param $discount Discount
276
     *
277
     * @return $this
278
     */
279
    public function setDiscount(Discount $discount)
280
    {
281
        $this->discount = $discount;
282
283
        return $this;
284
    }
285
286
    /**
287
     * @return Discount
288
     */
289
    public function getDiscount()
290
    {
291
        return $this->discount;
292
    }
293
294
    /**
295
     * @param \Ups\Entity\OtherCharges $otherCharges
296
     *
297
     * @return $this
298
     */
299
    public function setOtherCharges(OtherCharges $otherCharges)
300
    {
301
        $this->otherCharges = $otherCharges;
302
303 2
        return $this;
304
    }
305 2
306
    /**
307
     * @return OtherCharges
308
     */
309 2
    public function getOtherCharges()
310
    {
311 2
        return $this->otherCharges;
312 2
    }
313 2
314 2
    /**
315
     * @param Product $product
316
     *
317 2
     * @return $this
318
     */
319
    public function addProduct(Product $product)
320 2
    {
321
        array_push($this->products, $product);
322
323 2
        return $this;
324
    }
325
326 2
    /**
327
     * @return array
328
     */
329 2
    public function getProducts()
330
    {
331
        return $this->products;
332 2
    }
333
334
    /**
335 2
     * @param null|DOMDocument $document
336
     *
337
     * @return DOMElement
338 2
     */
339
    public function toNode(DOMDocument $document = null)
340
    {
341 2
        if (null === $document) {
342
            $document = new DOMDocument();
343
        }
344 2
345
        $node = $document->createElement('InternationalForms');
346
347 2
        foreach ($this->getTypes() as $type) {
348 1
            $node->appendChild($document->createElement('FormType', $type));
349 1
        }
350 2
        if ($this->getInvoiceNumber() !== null) {
351
            $node->appendChild($document->createElement('InvoiceNumber', $this->getInvoiceNumber()));
352 2
        }
353
        if ($this->getInvoiceDate() !== null) {
354 2
            $node->appendChild($document->createElement('InvoiceDate', $this->getInvoiceDate()->format('Ymd')));
355
        }
356
        if ($this->getPurchaseOrderNumber() !== null) {
357
            $node->appendChild($document->createElement('PurchaseOrderNumber', $this->getPurchaseOrderNumber()));
358
        }
359
        if ($this->getTermsOfShipment() !== null) {
360
            $node->appendChild($document->createElement('TermsOfShipment', $this->getTermsOfShipment()));
361
        }
362
        if ($this->getReasonForExport() !== null) {
363
            $node->appendChild($document->createElement('ReasonForExport', $this->getReasonForExport()));
364
        }
365
        if ($this->getComments() !== null) {
366
            $node->appendChild($document->createElement('Comments', $this->getComments()));
367
        }
368
        if ($this->getDeclarationStatement() !== null) {
369
            $node->appendChild($document->createElement('DeclarationStatement', $this->getDeclarationStatement()));
370
        }
371
        if ($this->getCurrencyCode() !== null) {
372 2
            $node->appendChild($document->createElement('CurrencyCode', $this->getCurrencyCode()));
373
        }
374 2
        if ($this->getDeclarationStatement() !== null) {
375
            $node->appendChild($document->createElement('DeclarationStatement', $this->getDeclarationStatement()));
376
        }
377
        if ($this->getDiscount() !== null) {
378
            $node->appendChild($this->getDiscount()->toNode($document));
379
        }
380
        if ($this->getFreightCharges() !== null) {
381
            $node->appendChild($this->getFreightCharges()->toNode($document));
382
        }
383
<<<<<<< HEAD
384
        if ($this->getAdditionalDocumentIndicator() !== null) {
385
            $node->appendChild($document->createElement('AdditionalDocumentIndicator'));
386
        }
387
        if ($this->getEEIFilingOption() !== null) {
388
            $node->appendChild($this->getEEIFilingOption()->toNode($document));
389
=======
390
        if ($this->getOtherCharges() !== null) {
391
            $node->appendChild($this->getOtherCharges()->toNode($document));
392 2
>>>>>>> develop
393
        }
394 2
        foreach ($this->products as $product) {
395
            $node->appendChild($product->toNode($document));
396
        }
397
398
        return $node;
399
    }
400
401
    /**
402
     * @param $number string
403
     *
404
     * @return $this
405
     */
406
    public function setInvoiceNumber($number)
407
    {
408
        $this->invoiceNumber = $number;
409
410
        return $this;
411
    }
412 2
413
    /**
414 2
     * @return string
415
     */
416
    public function getInvoiceNumber()
417
    {
418
        return $this->invoiceNumber;
419
    }
420
421
    /**
422
     * @param DateTime $date
423
     *
424
     * @return $this
425
     */
426
    public function setInvoiceDate(DateTime $date)
427
    {
428
        $this->invoiceDate = $date;
429
430
        return $this;
431
    }
432 2
433
    /**
434 2
     * @return DateTime
435
     */
436
    public function getInvoiceDate()
437
    {
438
        return $this->invoiceDate;
439
    }
440
441
    /**
442
     * @param $number
443
     *
444
     * @return $this
445
     */
446
    public function setPurchaseOrderNumber($number)
447
    {
448
        $this->purchaseOrderNumber = $number;
449
450
        return $this;
451
    }
452
453
    /**
454
     * @return string
455
     */
456 2
    public function getPurchaseOrderNumber()
457
    {
458 2
        return $this->purchaseOrderNumber;
459
    }
460
461
    /**
462
     * @param $terms
463
     *
464
     * @return $this
465
     */
466
    public function setTermsOfShipment($terms)
467
    {
468
        $this->termsOfShipment = $terms;
469
470
        return $this;
471
    }
472
473
    /**
474
     * @return string
475
     */
476
    public function getTermsOfShipment()
477
    {
478
        return $this->termsOfShipment;
479
    }
480 2
481
    /**
482 2
     * @param $reason
483
     *
484
     * @return $this
485
     */
486
    public function setReasonForExport($reason)
487
    {
488
        if (strlen($reason) > 20) {
489
            $reason = substr($reason, 0, 20);
490
        }
491
492
        $this->reasonForExport = $reason;
493
494
        return $this;
495
    }
496
497
    /**
498
     * @return string
499
     */
500 2
    public function getReasonForExport()
501
    {
502 2
        return $this->reasonForExport;
503
    }
504
505
    /**
506
     * @param $comments
507
     *
508
     * @return $this
509
     */
510
    public function setComments($comments)
511
    {
512
        if (strlen($comments) > 150) {
513
            $comments = substr($comments, 0, 150);
514
        }
515
516
        $this->comments = $comments;
517
518
        return $this;
519
    }
520 2
521
    /**
522 2
     * @return string
523
     */
524
    public function getComments()
525
    {
526
        return $this->comments;
527
    }
528
529
    /**
530
     * @param string $statement
531
     *
532
     * @return $this
533
     */
534
    public function setDeclarationStatement($statement)
535
    {
536
        $this->declarationStatement = $statement;
537
538 2
        return $this;
539
    }
540 2
541
    /**
542
     * @return string
543
     */
544
    public function getDeclarationStatement()
545
    {
546
        return $this->declarationStatement;
547
    }
548 3
549
    /**
550 3
     * @param $code
551
     *
552 3
     * @return $this
553
     */
554
    public function setCurrencyCode($code)
555
    {
556
        $this->currencyCode = $code;
557
558 4
        return $this;
559
    }
560 4
561
    /**
562
     * @return string
563
     */
564
    public function getCurrencyCode()
565
    {
566
        return $this->currencyCode;
567
    }
568
569
    /**
570
<<<<<<< HEAD
571
     * @param $additionalDocumentIndicator
572
     *
573
     * @return $this
574
     */
575
    public function setAdditionalDocumentIndicator($additionalDocumentIndicator)
576
    {
577
        $this->additionalDocumentIndicator = $additionalDocumentIndicator;
578
    }
579
580
    /**
581
     * @return bool
582
     */
583
    public function getAdditionalDocumentIndicator()
584
    {
585
        return $this->additionalDocumentIndicator;
586
    }
587
588
    /**
589
     * @param EEIFilingOption $eeiFilingOption
590
     *
591
     * @return $this
592
     */
593
    public function setEEIFilingOption(EEIFilingOption $eeiFilingOption)
594
    {
595
        $this->eeiFilingOption = $eeiFilingOption;
596
597
        return $this;
598
    }
599
600
    /**
601
     * @return EEIFilingOption
602
     */
603
    public function getEEIFilingOption()
604
    {
605
        return $this->eeiFilingOption;
606
    }
607
=======
608
     * @return string
609
     */
610
    public function getDeclarationStatement()
611
    {
612
        return $this->declarationStatement;
613
    }
614
615
    public function setDeclarationStatement($statement)
616
    {
617
        $this->declarationStatement = $statement;
618
619
        return $this;
620
    }
621
>>>>>>> develop
622
}
623