Failed Conditions
Pull Request — experimental/sf (#29)
by Kentaro
50:12 queued 39:05
created

OrderItem   B

Complexity

Total Complexity 52

Size/Duplication

Total Lines 722
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Test Coverage

Coverage 97.62%

Importance

Changes 0
Metric Value
dl 0
loc 722
rs 7.318
c 0
b 0
f 0
ccs 123
cts 126
cp 0.9762
wmc 52
lcom 3
cbo 5

47 Methods

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