Failed Conditions
Pull Request — experimental/sf (#31)
by Kentaro
06:59
created

OrderItem   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 761
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 761
rs 5.839
c 0
b 0
f 0
wmc 55
lcom 3
cbo 5

51 Methods

Rating   Name   Duplication   Size   Complexity  
A getPriceIncTax() 0 9 3
A getTotalPrice() 0 4 1
A getOrderItemTypeId() 0 8 2
A isProduct() 0 4 1
A isDeliveryFee() 0 4 1
A isCharge() 0 4 1
A isDiscount() 0 4 1
A isTax() 0 4 1
A isPoint() 0 4 1
A getId() 0 4 1
A setProductName() 0 6 1
A getProductName() 0 4 1
A setProductCode() 0 6 1
A getProductCode() 0 4 1
A setClassName1() 0 6 1
A getClassName1() 0 4 1
A setClassName2() 0 6 1
A getClassName2() 0 4 1
A setClassCategoryName1() 0 6 1
A getClassCategoryName1() 0 4 1
A setClassCategoryName2() 0 6 1
A getClassCategoryName2() 0 4 1
A setPrice() 0 6 1
A getPrice() 0 4 1
A setQuantity() 0 6 1
A getQuantity() 0 4 1
A getTax() 0 4 1
A setTax() 0 6 1
A setTaxRate() 0 6 1
A getTaxRate() 0 4 1
A setTaxRuleId() 0 6 1
A getTaxRuleId() 0 4 1
A getCurrencyCode() 0 4 1
A setCurrencyCode() 0 6 1
A setOrder() 0 6 1
A getOrder() 0 4 1
A getOrderId() 0 8 2
A setProduct() 0 6 1
A getProduct() 0 4 1
A setProductClass() 0 6 1
A getProductClass() 0 4 1
A setShipping() 0 6 1
A getShipping() 0 4 1
A getRoundingType() 0 4 1
A setRoundingType() 0 6 1
A setTaxType() 0 6 1
A getTaxType() 0 4 1
A setTaxDisplayType() 0 6 1
A getTaxDisplayType() 0 4 1
A setOrderItemType() 0 6 1
A getOrderItemType() 0 4 1

How to fix   Complexity   

Complex Class

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

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Entity;
15
16
use Doctrine\ORM\Mapping as ORM;
17
use Eccube\Entity\Master\OrderItemType;
18
use Eccube\Entity\Master\RoundingType;
19
use Eccube\Entity\Master\TaxDisplayType;
20
use Eccube\Entity\Master\TaxType;
21
22
if (!class_exists('\Eccube\Entity\OrderItem')) {
23
    /**
24
     * OrderItem
25
     *
26
     * @ORM\Table(name="dtb_order_item")
27
     * @ORM\InheritanceType("SINGLE_TABLE")
28
     * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
29
     * @ORM\HasLifecycleCallbacks()
30
     * @ORM\Entity(repositoryClass="Eccube\Repository\OrderItemRepository")
31
     */
32
    class OrderItem extends \Eccube\Entity\AbstractEntity implements ItemInterface
33
    {
34
        use PointRateTrait;
35
36
        /**
37
         * Get price IncTax
38
         *
39
         * @return string
40
         */
41
        public function getPriceIncTax()
42
        {
43
            // 税表示区分が税込の場合は, priceに税込金額が入っている.
44
            if ($this->TaxDisplayType && $this->TaxDisplayType->getId() == TaxDisplayType::INCLUDED) {
45
                return $this->price;
46
            }
47
48
            return $this->price + $this->tax;
49
        }
50
51
        /**
52
         * @return integer
53
         */
54
        public function getTotalPrice()
55
        {
56
            return $this->getPriceIncTax() * $this->getQuantity();
57
        }
58
59
        /**
60
         * @return integer
61
         */
62
        public function getOrderItemTypeId()
63
        {
64
            if (is_object($this->getOrderItemType())) {
65
                return $this->getOrderItemType()->getId();
66
            }
67
68
            return null;
69
        }
70
71
        /**
72
         * 商品明細かどうか.
73
         *
74
         * @return boolean 商品明細の場合 true
75
         */
76
        public function isProduct()
77
        {
78
            return $this->getOrderItemTypeId() === OrderItemType::PRODUCT;
79
        }
80
81
        /**
82
         * 送料明細かどうか.
83
         *
84
         * @return boolean 送料明細の場合 true
85
         */
86
        public function isDeliveryFee()
87
        {
88
            return $this->getOrderItemTypeId() === OrderItemType::DELIVERY_FEE;
89
        }
90
91
        /**
92
         * 手数料明細かどうか.
93
         *
94
         * @return boolean 手数料明細の場合 true
95
         */
96
        public function isCharge()
97
        {
98
            return $this->getOrderItemTypeId() === OrderItemType::CHARGE;
99
        }
100
101
        /**
102
         * 値引き明細かどうか.
103
         *
104
         * @return boolean 値引き明細の場合 true
105
         */
106
        public function isDiscount()
107
        {
108
            return $this->getOrderItemTypeId() === OrderItemType::DISCOUNT;
109
        }
110
111
        /**
112
         * 税額明細かどうか.
113
         *
114
         * @return boolean 税額明細の場合 true
115
         */
116
        public function isTax()
117
        {
118
            return $this->getOrderItemTypeId() === OrderItemType::TAX;
119
        }
120
121
        /**
122
         * ポイント明細かどうか.
123
         *
124
         * @return boolean ポイント明細の場合 true
125
         */
126
        public function isPoint()
127
        {
128
            return $this->getOrderItemTypeId() === OrderItemType::POINT;
129
        }
130
131
        /**
132
         * @var integer
133
         *
134
         * @ORM\Column(name="id", type="integer", options={"unsigned":true})
135
         * @ORM\Id
136
         * @ORM\GeneratedValue(strategy="IDENTITY")
137
         */
138
        private $id;
139
140
        /**
141
         * @var string
142
         *
143
         * @ORM\Column(name="product_name", type="string", length=255)
144
         */
145
        private $product_name;
146
147
        /**
148
         * @var string|null
149
         *
150
         * @ORM\Column(name="product_code", type="string", length=255, nullable=true)
151
         */
152
        private $product_code;
153
154
        /**
155
         * @var string|null
156
         *
157
         * @ORM\Column(name="class_name1", type="string", length=255, nullable=true)
158
         */
159
        private $class_name1;
160
161
        /**
162
         * @var string|null
163
         *
164
         * @ORM\Column(name="class_name2", type="string", length=255, nullable=true)
165
         */
166
        private $class_name2;
167
168
        /**
169
         * @var string|null
170
         *
171
         * @ORM\Column(name="class_category_name1", type="string", length=255, nullable=true)
172
         */
173
        private $class_category_name1;
174
175
        /**
176
         * @var string|null
177
         *
178
         * @ORM\Column(name="class_category_name2", type="string", length=255, nullable=true)
179
         */
180
        private $class_category_name2;
181
182
        /**
183
         * @var string
184
         *
185
         * @ORM\Column(name="price", type="decimal", precision=12, scale=2, options={"default":0})
186
         */
187
        private $price = 0;
188
189
        /**
190
         * @var string
191
         *
192
         * @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"default":0})
193
         */
194
        private $quantity = 0;
195
196
        /**
197
         * @var string
198
         *
199
         * @ORM\Column(name="tax", type="decimal", precision=10, scale=0, options={"default":0})
200
         */
201
        private $tax = 0;
202
203
        /**
204
         * @var string
205
         *
206
         * @ORM\Column(name="tax_rate", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0})
207
         */
208
        private $tax_rate = 0;
209
210
        /**
211
         * @var int|null
212
         *
213
         * @ORM\Column(name="tax_rule_id", type="smallint", nullable=true, options={"unsigned":true})
214
         */
215
        private $tax_rule_id;
216
217
        /**
218
         * @var string|null
219
         *
220
         * @ORM\Column(name="currency_code", type="string", nullable=true)
221
         */
222
        private $currency_code;
223
224
        /**
225
         * @var \Eccube\Entity\Order
226
         *
227
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="OrderItems")
228
         * @ORM\JoinColumns({
229
         *   @ORM\JoinColumn(name="order_id", referencedColumnName="id")
230
         * })
231
         */
232
        private $Order;
233
234
        /**
235
         * @var \Eccube\Entity\Product
236
         *
237
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Product")
238
         * @ORM\JoinColumns({
239
         *   @ORM\JoinColumn(name="product_id", referencedColumnName="id")
240
         * })
241
         */
242
        private $Product;
243
244
        /**
245
         * @var \Eccube\Entity\ProductClass
246
         *
247
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\ProductClass")
248
         * @ORM\JoinColumns({
249
         *   @ORM\JoinColumn(name="product_class_id", referencedColumnName="id")
250
         * })
251
         */
252
        private $ProductClass;
253
254
        /**
255
         * @var \Eccube\Entity\Shipping
256
         *
257
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Shipping", inversedBy="OrderItems")
258
         * @ORM\JoinColumns({
259
         *   @ORM\JoinColumn(name="shipping_id", referencedColumnName="id")
260
         * })
261
         */
262
        private $Shipping;
263
264
        /**
265
         * @var \Eccube\Entity\Master\RoundingType
266
         *
267
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\RoundingType")
268
         * @ORM\JoinColumns({
269
         *   @ORM\JoinColumn(name="rounding_type_id", referencedColumnName="id")
270
         * })
271
         */
272
        private $RoundingType;
273
274
        /**
275
         * @var \Eccube\Entity\Master\TaxType
276
         *
277
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxType")
278
         * @ORM\JoinColumns({
279
         *   @ORM\JoinColumn(name="tax_type_id", referencedColumnName="id")
280
         * })
281
         */
282
        private $TaxType;
283
284
        /**
285
         * @var \Eccube\Entity\Master\TaxDisplayType
286
         *
287
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxDisplayType")
288
         * @ORM\JoinColumns({
289
         *   @ORM\JoinColumn(name="tax_display_type_id", referencedColumnName="id")
290
         * })
291
         */
292
        private $TaxDisplayType;
293
294
        /**
295
         * @var \Eccube\Entity\Master\OrderItemType
296
         *
297
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\OrderItemType")
298
         * @ORM\JoinColumns({
299
         *   @ORM\JoinColumn(name="order_item_type_id", referencedColumnName="id")
300
         * })
301
         */
302
        private $OrderItemType;
303
304
        /**
305
         * Get id.
306
         *
307
         * @return int
308
         */
309
        public function getId()
310
        {
311
            return $this->id;
312
        }
313
314
        /**
315
         * Set productName.
316
         *
317
         * @param string $productName
318
         *
319
         * @return OrderItem
320
         */
321
        public function setProductName($productName)
322
        {
323
            $this->product_name = $productName;
324
325
            return $this;
326
        }
327
328
        /**
329
         * Get productName.
330
         *
331
         * @return string
332
         */
333
        public function getProductName()
334
        {
335
            return $this->product_name;
336
        }
337
338
        /**
339
         * Set productCode.
340
         *
341
         * @param string|null $productCode
342
         *
343
         * @return OrderItem
344
         */
345
        public function setProductCode($productCode = null)
346
        {
347
            $this->product_code = $productCode;
348
349
            return $this;
350
        }
351
352
        /**
353
         * Get productCode.
354
         *
355
         * @return string|null
356
         */
357
        public function getProductCode()
358
        {
359
            return $this->product_code;
360
        }
361
362
        /**
363
         * Set className1.
364
         *
365
         * @param string|null $className1
366
         *
367
         * @return OrderItem
368
         */
369
        public function setClassName1($className1 = null)
370
        {
371
            $this->class_name1 = $className1;
372
373
            return $this;
374
        }
375
376
        /**
377
         * Get className1.
378
         *
379
         * @return string|null
380
         */
381
        public function getClassName1()
382
        {
383
            return $this->class_name1;
384
        }
385
386
        /**
387
         * Set className2.
388
         *
389
         * @param string|null $className2
390
         *
391
         * @return OrderItem
392
         */
393
        public function setClassName2($className2 = null)
394
        {
395
            $this->class_name2 = $className2;
396
397
            return $this;
398
        }
399
400
        /**
401
         * Get className2.
402
         *
403
         * @return string|null
404
         */
405
        public function getClassName2()
406
        {
407
            return $this->class_name2;
408
        }
409
410
        /**
411
         * Set classCategoryName1.
412
         *
413
         * @param string|null $classCategoryName1
414
         *
415
         * @return OrderItem
416
         */
417
        public function setClassCategoryName1($classCategoryName1 = null)
418
        {
419
            $this->class_category_name1 = $classCategoryName1;
420
421
            return $this;
422
        }
423
424
        /**
425
         * Get classCategoryName1.
426
         *
427
         * @return string|null
428
         */
429
        public function getClassCategoryName1()
430
        {
431
            return $this->class_category_name1;
432
        }
433
434
        /**
435
         * Set classCategoryName2.
436
         *
437
         * @param string|null $classCategoryName2
438
         *
439
         * @return OrderItem
440
         */
441
        public function setClassCategoryName2($classCategoryName2 = null)
442
        {
443
            $this->class_category_name2 = $classCategoryName2;
444
445
            return $this;
446
        }
447
448
        /**
449
         * Get classCategoryName2.
450
         *
451
         * @return string|null
452
         */
453
        public function getClassCategoryName2()
454
        {
455
            return $this->class_category_name2;
456
        }
457
458
        /**
459
         * Set price.
460
         *
461
         * @param string $price
462
         *
463
         * @return OrderItem
464
         */
465
        public function setPrice($price)
466
        {
467
            $this->price = $price;
468
469
            return $this;
470
        }
471
472
        /**
473
         * Get price.
474
         *
475
         * @return string
476
         */
477
        public function getPrice()
478
        {
479
            return $this->price;
480
        }
481
482
        /**
483
         * Set quantity.
484
         *
485
         * @param string $quantity
486
         *
487
         * @return OrderItem
488
         */
489
        public function setQuantity($quantity)
490
        {
491
            $this->quantity = $quantity;
492
493
            return $this;
494
        }
495
496
        /**
497
         * Get quantity.
498
         *
499
         * @return string
500
         */
501
        public function getQuantity()
502
        {
503
            return $this->quantity;
504
        }
505
506
        /**
507
         * @return string
508
         */
509
        public function getTax()
510
        {
511
            return $this->tax;
512
        }
513
514
        /**
515
         * @param string $tax
516
         *
517
         * @return $this
518
         */
519
        public function setTax($tax)
520
        {
521
            $this->tax = $tax;
522
523
            return $this;
524
        }
525
526
        /**
527
         * Set taxRate.
528
         *
529
         * @param string $taxRate
530
         *
531
         * @return OrderItem
532
         */
533
        public function setTaxRate($taxRate)
534
        {
535
            $this->tax_rate = $taxRate;
536
537
            return $this;
538
        }
539
540
        /**
541
         * Get taxRate.
542
         *
543
         * @return string
544
         */
545
        public function getTaxRate()
546
        {
547
            return $this->tax_rate;
548
        }
549
550
        /**
551
         * Set taxRuleId.
552
         *
553
         * @param int|null $taxRuleId
554
         *
555
         * @return OrderItem
556
         */
557
        public function setTaxRuleId($taxRuleId = null)
558
        {
559
            $this->tax_rule_id = $taxRuleId;
560
561
            return $this;
562
        }
563
564
        /**
565
         * Get taxRuleId.
566
         *
567
         * @return int|null
568
         */
569
        public function getTaxRuleId()
570
        {
571
            return $this->tax_rule_id;
572
        }
573
574
        /**
575
         * Get currencyCode.
576
         *
577
         * @return string
578
         */
579
        public function getCurrencyCode()
580
        {
581
            return $this->currency_code;
582
        }
583
584
        /**
585
         * Set currencyCode.
586
         *
587
         * @param string|null $currencyCode
588
         *
589
         * @return OrderItem
590
         */
591
        public function setCurrencyCode($currencyCode = null)
592
        {
593
            $this->currency_code = $currencyCode;
594
595
            return $this;
596
        }
597
598
        /**
599
         * Set order.
600
         *
601
         * @param \Eccube\Entity\Order|null $order
602
         *
603
         * @return OrderItem
604
         */
605
        public function setOrder(\Eccube\Entity\Order $order = null)
606
        {
607
            $this->Order = $order;
608
609
            return $this;
610
        }
611
612
        /**
613
         * Get order.
614
         *
615
         * @return \Eccube\Entity\Order|null
616
         */
617
        public function getOrder()
618
        {
619
            return $this->Order;
620
        }
621
622
        public function getOrderId()
623
        {
624
            if (is_object($this->getOrder())) {
625
                return $this->getOrder()->getId();
626
            }
627
628
            return null;
629
        }
630
631
        /**
632
         * Set product.
633
         *
634
         * @param \Eccube\Entity\Product|null $product
635
         *
636
         * @return OrderItem
637
         */
638
        public function setProduct(\Eccube\Entity\Product $product = null)
639
        {
640
            $this->Product = $product;
641
642
            return $this;
643
        }
644
645
        /**
646
         * Get product.
647
         *
648
         * @return \Eccube\Entity\Product|null
649
         */
650
        public function getProduct()
651
        {
652
            return $this->Product;
653
        }
654
655
        /**
656
         * Set productClass.
657
         *
658
         * @param \Eccube\Entity\ProductClass|null $productClass
659
         *
660
         * @return OrderItem
661
         */
662
        public function setProductClass(\Eccube\Entity\ProductClass $productClass = null)
663
        {
664
            $this->ProductClass = $productClass;
665
666
            return $this;
667
        }
668
669
        /**
670
         * Get productClass.
671
         *
672
         * @return \Eccube\Entity\ProductClass|null
673
         */
674
        public function getProductClass()
675
        {
676
            return $this->ProductClass;
677
        }
678
679
        /**
680
         * Set shipping.
681
         *
682
         * @param \Eccube\Entity\Shipping|null $shipping
683
         *
684
         * @return OrderItem
685
         */
686
        public function setShipping(\Eccube\Entity\Shipping $shipping = null)
687
        {
688
            $this->Shipping = $shipping;
689
690
            return $this;
691
        }
692
693
        /**
694
         * Get shipping.
695
         *
696
         * @return \Eccube\Entity\Shipping|null
697
         */
698
        public function getShipping()
699
        {
700
            return $this->Shipping;
701
        }
702
703
        /**
704
         * @return RoundingType
705
         */
706
        public function getRoundingType()
707
        {
708
            return $this->RoundingType;
709
        }
710
711
        /**
712
         * @param RoundingType $RoundingType
713
         */
714
        public function setRoundingType(RoundingType $RoundingType = null)
715
        {
716
            $this->RoundingType = $RoundingType;
717
718
            return $this;
719
        }
720
721
        /**
722
         * Set taxType
723
         *
724
         * @param \Eccube\Entity\Master\TaxType $taxType
725
         *
726
         * @return OrderItem
727
         */
728
        public function setTaxType(\Eccube\Entity\Master\TaxType $taxType = null)
729
        {
730
            $this->TaxType = $taxType;
731
732
            return $this;
733
        }
734
735
        /**
736
         * Get taxType
737
         *
738
         * @return \Eccube\Entity\Master\TaxType
739
         */
740
        public function getTaxType()
741
        {
742
            return $this->TaxType;
743
        }
744
745
        /**
746
         * Set taxDisplayType
747
         *
748
         * @param \Eccube\Entity\Master\TaxDisplayType $taxDisplayType
749
         *
750
         * @return OrderItem
751
         */
752
        public function setTaxDisplayType(\Eccube\Entity\Master\TaxDisplayType $taxDisplayType = null)
753
        {
754
            $this->TaxDisplayType = $taxDisplayType;
755
756
            return $this;
757
        }
758
759
        /**
760
         * Get taxDisplayType
761
         *
762
         * @return \Eccube\Entity\Master\TaxDisplayType
763
         */
764
        public function getTaxDisplayType()
765
        {
766
            return $this->TaxDisplayType;
767
        }
768
769
        /**
770
         * Set orderItemType
771
         *
772
         * @param \Eccube\Entity\Master\OrderItemType $orderItemType
773
         *
774
         * @return OrderItem
775
         */
776
        public function setOrderItemType(\Eccube\Entity\Master\OrderItemType $orderItemType = null)
777
        {
778
            $this->OrderItemType = $orderItemType;
779
780
            return $this;
781
        }
782
783
        /**
784
         * Get orderItemType
785
         *
786
         * @return \Eccube\Entity\Master\OrderItemType
787
         */
788
        public function getOrderItemType()
789
        {
790
            return $this->OrderItemType;
791
        }
792
    }
793
}
794