LineItemType   F
last analyzed

Complexity

Total Complexity 74

Size/Duplication

Total Lines 785
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 74
lcom 1
cbo 1
dl 0
loc 785
ccs 0
cts 30
cp 0
rs 2.295
c 0
b 0
f 0

54 Methods

Rating   Name   Duplication   Size   Complexity  
A getItemId() 0 4 1
A setItemId() 0 5 1
A getName() 0 4 1
A setName() 0 5 1
A getDescription() 0 4 1
A setDescription() 0 5 1
A getQuantity() 0 4 1
A setQuantity() 0 5 1
A getUnitPrice() 0 4 1
A setUnitPrice() 0 5 1
A getTaxable() 0 4 1
A setTaxable() 0 5 1
A getUnitOfMeasure() 0 4 1
A setUnitOfMeasure() 0 5 1
A getTypeOfSupply() 0 4 1
A setTypeOfSupply() 0 5 1
A getTaxRate() 0 4 1
A setTaxRate() 0 5 1
A getTaxAmount() 0 4 1
A setTaxAmount() 0 5 1
A getNationalTax() 0 4 1
A setNationalTax() 0 5 1
A getLocalTax() 0 4 1
A setLocalTax() 0 5 1
A getVatRate() 0 4 1
A setVatRate() 0 5 1
A getAlternateTaxId() 0 4 1
A setAlternateTaxId() 0 5 1
A getAlternateTaxType() 0 4 1
A setAlternateTaxType() 0 5 1
A getAlternateTaxTypeApplied() 0 4 1
A setAlternateTaxTypeApplied() 0 5 1
A getAlternateTaxRate() 0 4 1
A setAlternateTaxRate() 0 5 1
A getAlternateTaxAmount() 0 4 1
A setAlternateTaxAmount() 0 5 1
A getTotalAmount() 0 4 1
A setTotalAmount() 0 5 1
A getCommodityCode() 0 4 1
A setCommodityCode() 0 5 1
A getProductCode() 0 4 1
A setProductCode() 0 5 1
A getProductSKU() 0 4 1
A setProductSKU() 0 5 1
A getDiscountRate() 0 4 1
A setDiscountRate() 0 5 1
A getDiscountAmount() 0 4 1
A setDiscountAmount() 0 5 1
A getTaxIncludedInTotal() 0 4 1
A setTaxIncludedInTotal() 0 5 1
A getTaxIsAfterDiscount() 0 4 1
A setTaxIsAfterDiscount() 0 5 1
B jsonSerialize() 0 28 7
C set() 0 46 15

How to fix   Complexity   

Complex Class

Complex classes like LineItemType 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 LineItemType, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace net\authorize\api\contract\v1;
4
5
/**
6
 * Class representing LineItemType
7
 *
8
 * 
9
 * XSD Type: lineItemType
10
 */
11
class LineItemType implements \JsonSerializable
12
{
13
14
    /**
15
     * @property string $itemId
16
     */
17
    private $itemId = null;
18
19
    /**
20
     * @property string $name
21
     */
22
    private $name = null;
23
24
    /**
25
     * @property string $description
26
     */
27
    private $description = null;
28
29
    /**
30
     * @property float $quantity
31
     */
32
    private $quantity = null;
33
34
    /**
35
     * @property float $unitPrice
36
     */
37
    private $unitPrice = null;
38
39
    /**
40
     * @property boolean $taxable
41
     */
42
    private $taxable = null;
43
44
    /**
45
     * @property string $unitOfMeasure
46
     */
47
    private $unitOfMeasure = null;
48
49
    /**
50
     * @property string $typeOfSupply
51
     */
52
    private $typeOfSupply = null;
53
54
    /**
55
     * @property float $taxRate
56
     */
57
    private $taxRate = null;
58
59
    /**
60
     * @property float $taxAmount
61
     */
62
    private $taxAmount = null;
63
64
    /**
65
     * @property float $nationalTax
66
     */
67
    private $nationalTax = null;
68
69
    /**
70
     * @property float $localTax
71
     */
72
    private $localTax = null;
73
74
    /**
75
     * @property float $vatRate
76
     */
77
    private $vatRate = null;
78
79
    /**
80
     * @property string $alternateTaxId
81
     */
82
    private $alternateTaxId = null;
83
84
    /**
85
     * @property string $alternateTaxType
86
     */
87
    private $alternateTaxType = null;
88
89
    /**
90
     * @property string $alternateTaxTypeApplied
91
     */
92
    private $alternateTaxTypeApplied = null;
93
94
    /**
95
     * @property float $alternateTaxRate
96
     */
97
    private $alternateTaxRate = null;
98
99
    /**
100
     * @property float $alternateTaxAmount
101
     */
102
    private $alternateTaxAmount = null;
103
104
    /**
105
     * @property float $totalAmount
106
     */
107
    private $totalAmount = null;
108
109
    /**
110
     * @property string $commodityCode
111
     */
112
    private $commodityCode = null;
113
114
    /**
115
     * @property string $productCode
116
     */
117
    private $productCode = null;
118
119
    /**
120
     * @property string $productSKU
121
     */
122
    private $productSKU = null;
123
124
    /**
125
     * @property float $discountRate
126
     */
127
    private $discountRate = null;
128
129
    /**
130
     * @property float $discountAmount
131
     */
132
    private $discountAmount = null;
133
134
    /**
135
     * @property boolean $taxIncludedInTotal
136
     */
137
    private $taxIncludedInTotal = null;
138
139
    /**
140
     * @property boolean $taxIsAfterDiscount
141
     */
142
    private $taxIsAfterDiscount = null;
143
144
    /**
145
     * Gets as itemId
146
     *
147
     * @return string
148
     */
149
    public function getItemId()
150
    {
151
        return $this->itemId;
152
    }
153
154
    /**
155
     * Sets a new itemId
156
     *
157
     * @param string $itemId
158
     * @return self
159
     */
160
    public function setItemId($itemId)
161
    {
162
        $this->itemId = $itemId;
163
        return $this;
164
    }
165
166
    /**
167
     * Gets as name
168
     *
169
     * @return string
170
     */
171
    public function getName()
172
    {
173
        return $this->name;
174
    }
175
176
    /**
177
     * Sets a new name
178
     *
179
     * @param string $name
180
     * @return self
181
     */
182
    public function setName($name)
183
    {
184
        $this->name = $name;
185
        return $this;
186
    }
187
188
    /**
189
     * Gets as description
190
     *
191
     * @return string
192
     */
193
    public function getDescription()
194
    {
195
        return $this->description;
196
    }
197
198
    /**
199
     * Sets a new description
200
     *
201
     * @param string $description
202
     * @return self
203
     */
204
    public function setDescription($description)
205
    {
206
        $this->description = $description;
207
        return $this;
208
    }
209
210
    /**
211
     * Gets as quantity
212
     *
213
     * @return float
214
     */
215
    public function getQuantity()
216
    {
217
        return $this->quantity;
218
    }
219
220
    /**
221
     * Sets a new quantity
222
     *
223
     * @param float $quantity
224
     * @return self
225
     */
226
    public function setQuantity($quantity)
227
    {
228
        $this->quantity = $quantity;
229
        return $this;
230
    }
231
232
    /**
233
     * Gets as unitPrice
234
     *
235
     * @return float
236
     */
237
    public function getUnitPrice()
238
    {
239
        return $this->unitPrice;
240
    }
241
242
    /**
243
     * Sets a new unitPrice
244
     *
245
     * @param float $unitPrice
246
     * @return self
247
     */
248
    public function setUnitPrice($unitPrice)
249
    {
250
        $this->unitPrice = $unitPrice;
251
        return $this;
252
    }
253
254
    /**
255
     * Gets as taxable
256
     *
257
     * @return boolean
258
     */
259
    public function getTaxable()
260
    {
261
        return $this->taxable;
262
    }
263
264
    /**
265
     * Sets a new taxable
266
     *
267
     * @param boolean $taxable
268
     * @return self
269
     */
270
    public function setTaxable($taxable)
271
    {
272
        $this->taxable = $taxable;
273
        return $this;
274
    }
275
276
    /**
277
     * Gets as unitOfMeasure
278
     *
279
     * @return string
280
     */
281
    public function getUnitOfMeasure()
282
    {
283
        return $this->unitOfMeasure;
284
    }
285
286
    /**
287
     * Sets a new unitOfMeasure
288
     *
289
     * @param string $unitOfMeasure
290
     * @return self
291
     */
292
    public function setUnitOfMeasure($unitOfMeasure)
293
    {
294
        $this->unitOfMeasure = $unitOfMeasure;
295
        return $this;
296
    }
297
298
    /**
299
     * Gets as typeOfSupply
300
     *
301
     * @return string
302
     */
303
    public function getTypeOfSupply()
304
    {
305
        return $this->typeOfSupply;
306
    }
307
308
    /**
309
     * Sets a new typeOfSupply
310
     *
311
     * @param string $typeOfSupply
312
     * @return self
313
     */
314
    public function setTypeOfSupply($typeOfSupply)
315
    {
316
        $this->typeOfSupply = $typeOfSupply;
317
        return $this;
318
    }
319
320
    /**
321
     * Gets as taxRate
322
     *
323
     * @return float
324
     */
325
    public function getTaxRate()
326
    {
327
        return $this->taxRate;
328
    }
329
330
    /**
331
     * Sets a new taxRate
332
     *
333
     * @param float $taxRate
334
     * @return self
335
     */
336
    public function setTaxRate($taxRate)
337
    {
338
        $this->taxRate = $taxRate;
339
        return $this;
340
    }
341
342
    /**
343
     * Gets as taxAmount
344
     *
345
     * @return float
346
     */
347
    public function getTaxAmount()
348
    {
349
        return $this->taxAmount;
350
    }
351
352
    /**
353
     * Sets a new taxAmount
354
     *
355
     * @param float $taxAmount
356
     * @return self
357
     */
358
    public function setTaxAmount($taxAmount)
359
    {
360
        $this->taxAmount = $taxAmount;
361
        return $this;
362
    }
363
364
    /**
365
     * Gets as nationalTax
366
     *
367
     * @return float
368
     */
369
    public function getNationalTax()
370
    {
371
        return $this->nationalTax;
372
    }
373
374
    /**
375
     * Sets a new nationalTax
376
     *
377
     * @param float $nationalTax
378
     * @return self
379
     */
380
    public function setNationalTax($nationalTax)
381
    {
382
        $this->nationalTax = $nationalTax;
383
        return $this;
384
    }
385
386
    /**
387
     * Gets as localTax
388
     *
389
     * @return float
390
     */
391
    public function getLocalTax()
392
    {
393
        return $this->localTax;
394
    }
395
396
    /**
397
     * Sets a new localTax
398
     *
399
     * @param float $localTax
400
     * @return self
401
     */
402
    public function setLocalTax($localTax)
403
    {
404
        $this->localTax = $localTax;
405
        return $this;
406
    }
407
408
    /**
409
     * Gets as vatRate
410
     *
411
     * @return float
412
     */
413
    public function getVatRate()
414
    {
415
        return $this->vatRate;
416
    }
417
418
    /**
419
     * Sets a new vatRate
420
     *
421
     * @param float $vatRate
422
     * @return self
423
     */
424
    public function setVatRate($vatRate)
425
    {
426
        $this->vatRate = $vatRate;
427
        return $this;
428
    }
429
430
    /**
431
     * Gets as alternateTaxId
432
     *
433
     * @return string
434
     */
435
    public function getAlternateTaxId()
436
    {
437
        return $this->alternateTaxId;
438
    }
439
440
    /**
441
     * Sets a new alternateTaxId
442
     *
443
     * @param string $alternateTaxId
444
     * @return self
445
     */
446
    public function setAlternateTaxId($alternateTaxId)
447
    {
448
        $this->alternateTaxId = $alternateTaxId;
449
        return $this;
450
    }
451
452
    /**
453
     * Gets as alternateTaxType
454
     *
455
     * @return string
456
     */
457
    public function getAlternateTaxType()
458
    {
459
        return $this->alternateTaxType;
460
    }
461
462
    /**
463
     * Sets a new alternateTaxType
464
     *
465
     * @param string $alternateTaxType
466
     * @return self
467
     */
468
    public function setAlternateTaxType($alternateTaxType)
469
    {
470
        $this->alternateTaxType = $alternateTaxType;
471
        return $this;
472
    }
473
474
    /**
475
     * Gets as alternateTaxTypeApplied
476
     *
477
     * @return string
478
     */
479
    public function getAlternateTaxTypeApplied()
480
    {
481
        return $this->alternateTaxTypeApplied;
482
    }
483
484
    /**
485
     * Sets a new alternateTaxTypeApplied
486
     *
487
     * @param string $alternateTaxTypeApplied
488
     * @return self
489
     */
490
    public function setAlternateTaxTypeApplied($alternateTaxTypeApplied)
491
    {
492
        $this->alternateTaxTypeApplied = $alternateTaxTypeApplied;
493
        return $this;
494
    }
495
496
    /**
497
     * Gets as alternateTaxRate
498
     *
499
     * @return float
500
     */
501
    public function getAlternateTaxRate()
502
    {
503
        return $this->alternateTaxRate;
504
    }
505
506
    /**
507
     * Sets a new alternateTaxRate
508
     *
509
     * @param float $alternateTaxRate
510
     * @return self
511
     */
512
    public function setAlternateTaxRate($alternateTaxRate)
513
    {
514
        $this->alternateTaxRate = $alternateTaxRate;
515
        return $this;
516
    }
517
518
    /**
519
     * Gets as alternateTaxAmount
520
     *
521
     * @return float
522
     */
523
    public function getAlternateTaxAmount()
524
    {
525
        return $this->alternateTaxAmount;
526
    }
527
528
    /**
529
     * Sets a new alternateTaxAmount
530
     *
531
     * @param float $alternateTaxAmount
532
     * @return self
533
     */
534
    public function setAlternateTaxAmount($alternateTaxAmount)
535
    {
536
        $this->alternateTaxAmount = $alternateTaxAmount;
537
        return $this;
538
    }
539
540
    /**
541
     * Gets as totalAmount
542
     *
543
     * @return float
544
     */
545
    public function getTotalAmount()
546
    {
547
        return $this->totalAmount;
548
    }
549
550
    /**
551
     * Sets a new totalAmount
552
     *
553
     * @param float $totalAmount
554
     * @return self
555
     */
556
    public function setTotalAmount($totalAmount)
557
    {
558
        $this->totalAmount = $totalAmount;
559
        return $this;
560
    }
561
562
    /**
563
     * Gets as commodityCode
564
     *
565
     * @return string
566
     */
567
    public function getCommodityCode()
568
    {
569
        return $this->commodityCode;
570
    }
571
572
    /**
573
     * Sets a new commodityCode
574
     *
575
     * @param string $commodityCode
576
     * @return self
577
     */
578
    public function setCommodityCode($commodityCode)
579
    {
580
        $this->commodityCode = $commodityCode;
581
        return $this;
582
    }
583
584
    /**
585
     * Gets as productCode
586
     *
587
     * @return string
588
     */
589
    public function getProductCode()
590
    {
591
        return $this->productCode;
592
    }
593
594
    /**
595
     * Sets a new productCode
596
     *
597
     * @param string $productCode
598
     * @return self
599
     */
600
    public function setProductCode($productCode)
601
    {
602
        $this->productCode = $productCode;
603
        return $this;
604
    }
605
606
    /**
607
     * Gets as productSKU
608
     *
609
     * @return string
610
     */
611
    public function getProductSKU()
612
    {
613
        return $this->productSKU;
614
    }
615
616
    /**
617
     * Sets a new productSKU
618
     *
619
     * @param string $productSKU
620
     * @return self
621
     */
622
    public function setProductSKU($productSKU)
623
    {
624
        $this->productSKU = $productSKU;
625
        return $this;
626
    }
627
628
    /**
629
     * Gets as discountRate
630
     *
631
     * @return float
632
     */
633
    public function getDiscountRate()
634
    {
635
        return $this->discountRate;
636
    }
637
638
    /**
639
     * Sets a new discountRate
640
     *
641
     * @param float $discountRate
642
     * @return self
643
     */
644
    public function setDiscountRate($discountRate)
645
    {
646
        $this->discountRate = $discountRate;
647
        return $this;
648
    }
649
650
    /**
651
     * Gets as discountAmount
652
     *
653
     * @return float
654
     */
655
    public function getDiscountAmount()
656
    {
657
        return $this->discountAmount;
658
    }
659
660
    /**
661
     * Sets a new discountAmount
662
     *
663
     * @param float $discountAmount
664
     * @return self
665
     */
666
    public function setDiscountAmount($discountAmount)
667
    {
668
        $this->discountAmount = $discountAmount;
669
        return $this;
670
    }
671
672
    /**
673
     * Gets as taxIncludedInTotal
674
     *
675
     * @return boolean
676
     */
677
    public function getTaxIncludedInTotal()
678
    {
679
        return $this->taxIncludedInTotal;
680
    }
681
682
    /**
683
     * Sets a new taxIncludedInTotal
684
     *
685
     * @param boolean $taxIncludedInTotal
686
     * @return self
687
     */
688
    public function setTaxIncludedInTotal($taxIncludedInTotal)
689
    {
690
        $this->taxIncludedInTotal = $taxIncludedInTotal;
691
        return $this;
692
    }
693
694
    /**
695
     * Gets as taxIsAfterDiscount
696
     *
697
     * @return boolean
698
     */
699
    public function getTaxIsAfterDiscount()
700
    {
701
        return $this->taxIsAfterDiscount;
702
    }
703
704
    /**
705
     * Sets a new taxIsAfterDiscount
706
     *
707
     * @param boolean $taxIsAfterDiscount
708
     * @return self
709
     */
710
    public function setTaxIsAfterDiscount($taxIsAfterDiscount)
711
    {
712
        $this->taxIsAfterDiscount = $taxIsAfterDiscount;
713
        return $this;
714
    }
715
716
717
    // Json Serialize Code
718
    public function jsonSerialize(){
719
        $values = array_filter((array)get_object_vars($this),
720
        function ($val){
721
            return !is_null($val);
722
        });
723
        $mapper = \net\authorize\util\Mapper::Instance();
724
        foreach($values as $key => $value){
725
            $classDetails = $mapper->getClass(get_class() , $key);
726
            if (isset($value)){
727
                if ($classDetails->className === 'Date'){
728
                    $dateTime = $value->format('Y-m-d');
729
                    $values[$key] = $dateTime;
730
                }
731
                else if ($classDetails->className === 'DateTime'){
732
                    $dateTime = $value->format('Y-m-d\TH:i:s\Z');
733
                    $values[$key] = $dateTime;
734
                }
735
                if (is_array($value)){
736
                    if (!$classDetails->isInlineArray){
737
                        $subKey = $classDetails->arrayEntryname;
738
                        $subArray = [$subKey => $value];
739
                        $values[$key] = $subArray;
740
                    }
741
                }
742
            }
743
        }
744
        return $values;
745
    }
746
    
747
    // Json Set Code
748
    public function set($data)
749
    {
750
        if(is_array($data) || is_object($data)) {
751
			$mapper = \net\authorize\util\Mapper::Instance();
752
			foreach($data AS $key => $value) {
753
				$classDetails = $mapper->getClass(get_class() , $key);
754
	 
755
				if($classDetails !== NULL ) {
756
					if ($classDetails->isArray) {
757
						if ($classDetails->isCustomDefined) {
758
							foreach($value AS $keyChild => $valueChild) {
759
								$type = new $classDetails->className;
760
								$type->set($valueChild);
761
								$this->{'addTo' . $key}($type);
762
							}
763
						}
764
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
765
							foreach($value AS $keyChild => $valueChild) {
766
								$type = new \DateTime($valueChild);
767
								$this->{'addTo' . $key}($type);
768
							}
769
						}
770
						else {
771
							foreach($value AS $keyChild => $valueChild) {
772
								$this->{'addTo' . $key}($valueChild);
773
							}
774
						}
775
					}
776
					else {
777
						if ($classDetails->isCustomDefined){
778
							$type = new $classDetails->className;
779
							$type->set($value);
780
							$this->{'set' . $key}($type);
781
						}
782
						else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
783
							$type = new \DateTime($value);
784
							$this->{'set' . $key}($type);
785
						}
786
						else {
787
							$this->{'set' . $key}($value);
788
						}
789
					}
790
				}
791
			}
792
		}
793
    }
794
    
795
}
796
797