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

ProductClass   D

Complexity

Total Complexity 57

Size/Duplication

Total Lines 797
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 85.29%

Importance

Changes 0
Metric Value
dl 0
loc 797
ccs 116
cts 136
cp 0.8529
rs 4.843
c 0
b 0
f 0
wmc 57
lcom 2
cbo 1

53 Methods

Rating   Name   Duplication   Size   Complexity  
A isEnable() 0 4 1
A setPrice01IncTax() 0 6 1
A getPrice01IncTax() 0 4 1
A setPrice02IncTax() 0 6 1
A getPrice02IncTax() 0 4 1
A getStockFind() 0 8 3
A setTaxRate() 0 6 1
A getTaxRate() 0 4 1
A hasClassCategory1() 0 4 1
A hasClassCategory2() 0 4 1
A __clone() 0 4 1
A getId() 0 4 1
A setCode() 0 6 1
A getCode() 0 4 1
A setStock() 0 6 1
A getStock() 0 4 1
A setStockUnlimited() 0 6 1
A isStockUnlimited() 0 4 1
A setSaleLimit() 0 6 1
A getSaleLimit() 0 4 1
A setPrice01() 0 6 1
A getPrice01() 0 4 1
A setPrice02() 0 6 1
A getPrice02() 0 4 1
A setDeliveryFee() 0 6 1
A getDeliveryFee() 0 4 1
A isVisible() 0 4 1
A setVisible() 0 6 1
A setCreateDate() 0 6 1
A getCreateDate() 0 4 1
A setUpdateDate() 0 6 1
A getUpdateDate() 0 4 1
A getCurrencyCode() 0 4 1
A setCurrencyCode() 0 6 1
A setProductStock() 0 6 1
A getProductStock() 0 4 1
A setTaxRule() 0 6 1
A getTaxRule() 0 4 1
A setProduct() 0 6 1
A getProduct() 0 4 1
A setSaleType() 0 6 1
A getSaleType() 0 4 1
A setClassCategory1() 0 6 1
A getClassCategory1() 0 4 1
A setClassCategory2() 0 6 1
A getClassCategory2() 0 4 1
A setDeliveryDuration() 0 6 1
A getDeliveryDuration() 0 4 1
A setCreator() 0 6 1
A getCreator() 0 4 1
A setPointRate() 0 6 1
A getPointRate() 0 4 1
A formatedProductName() 0 12 3

How to fix   Complexity   

Complex Class

Complex classes like ProductClass 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 ProductClass, 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
18
/**
19
 * ProductClass
20
 *
21
 * @ORM\Table(name="dtb_product_class", indexes={@ORM\Index(name="dtb_product_class_price02_idx", columns={"price02"}), @ORM\Index(name="dtb_product_class_stock_stock_unlimited_idx", columns={"stock", "stock_unlimited"})})
22
 * @ORM\InheritanceType("SINGLE_TABLE")
23
 * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
24
 * @ORM\HasLifecycleCallbacks()
25
 * @ORM\Entity(repositoryClass="Eccube\Repository\ProductClassRepository")
26
 */
27
class ProductClass extends \Eccube\Entity\AbstractEntity
28
{
29
    private $price01_inc_tax = null;
30
    private $price02_inc_tax = null;
31
    private $tax_rate = false;
32
33
    /**
34
     * 商品規格名を含めた商品名を返す.
35
     *
36
     * @return string
37
     */
38
    public function formatedProductName()
39
    {
40
        $productName = $this->getProduct()->getName();
41
        if ($this->hasClassCategory1()) {
42
            $productName .= ' - '.$this->getClassCategory1()->getName();
43
        }
44
        if ($this->hasClassCategory2()) {
45
            $productName .= ' - '.$this->getClassCategory2()->getName();
46
        }
47
48
        return $productName;
49
    }
50
51
    /**
52
     * Is Enable
53
     *
54
     * @return bool
55
     */
56 80
    public function isEnable()
57
    {
58 80
        return $this->getProduct()->isEnable();
59
    }
60
61
    /**
62
     * Set price01 IncTax
63
     *
64
     * @param  string       $price01_inc_tax
65
     *
66
     * @return ProductClass
67
     */
68 421
    public function setPrice01IncTax($price01_inc_tax)
69
    {
70 421
        $this->price01_inc_tax = $price01_inc_tax;
71
72 421
        return $this;
73
    }
74
75
    /**
76
     * Get price01 IncTax
77
     *
78
     * @return string
79
     */
80 7
    public function getPrice01IncTax()
81
    {
82 7
        return $this->price01_inc_tax;
83
    }
84
85
    /**
86
     * Set price02 IncTax
87
     *
88
     *
89
     * @return ProductClass
90
     */
91 421
    public function setPrice02IncTax($price02_inc_tax)
92
    {
93 421
        $this->price02_inc_tax = $price02_inc_tax;
94
95 421
        return $this;
96
    }
97
98
    /**
99
     * Get price02 IncTax
100
     *
101
     * @return string
102
     */
103 101
    public function getPrice02IncTax()
104
    {
105 101
        return $this->price02_inc_tax;
106
    }
107
108
    /**
109
     * Get StockFind
110
     *
111
     * @return bool
112
     */
113 48
    public function getStockFind()
114
    {
115 48
        if ($this->getStock() > 0 || $this->isStockUnlimited()) {
116 48
            return true;
117
        } else {
118 3
            return false;
119
        }
120
    }
121
122
    /**
123
     * Set tax_rate
124
     *
125
     * @param  string $tax_rate
126
     *
127
     * @return ProductClass
128
     */
129 41
    public function setTaxRate($tax_rate)
130
    {
131 41
        $this->tax_rate = $tax_rate;
0 ignored issues
show
Documentation Bug introduced by
The property $tax_rate was declared of type boolean, but $tax_rate is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
132
133 41
        return $this;
134
    }
135
136
    /**
137
     * Get tax_rate
138
     *
139
     * @return boolean
140
     */
141 46
    public function getTaxRate()
142
    {
143 46
        return $this->tax_rate;
144
    }
145
146
    /**
147
     * Has ClassCategory1
148
     *
149
     * @return boolean
150
     */
151 202
    public function hasClassCategory1()
152
    {
153 202
        return isset($this->ClassCategory1);
154
    }
155
156
    /**
157
     * Has ClassCategory1
158
     *
159
     * @return boolean
160
     */
161 202
    public function hasClassCategory2()
162
    {
163 202
        return isset($this->ClassCategory2);
164
    }
165
166
    /**
167
     * @var int
168
     *
169
     * @ORM\Column(name="id", type="integer", options={"unsigned":true})
170
     * @ORM\Id
171
     * @ORM\GeneratedValue(strategy="IDENTITY")
172
     */
173
    private $id;
174
175
    /**
176
     * @var string|null
177
     *
178
     * @ORM\Column(name="product_code", type="string", length=255, nullable=true)
179
     */
180
    private $code;
181
182
    /**
183
     * @var string|null
184
     *
185
     * @ORM\Column(name="stock", type="decimal", precision=10, scale=0, nullable=true)
186
     */
187
    private $stock;
188
189
    /**
190
     * @var boolean
191
     *
192
     * @ORM\Column(name="stock_unlimited", type="boolean", options={"default":false})
193
     */
194
    private $stock_unlimited = false;
195
196
    /**
197
     * @var string|null
198
     *
199
     * @ORM\Column(name="sale_limit", type="decimal", precision=10, scale=0, nullable=true, options={"unsigned":true})
200
     */
201
    private $sale_limit;
202
203
    /**
204
     * @var string|null
205
     *
206
     * @ORM\Column(name="price01", type="decimal", precision=12, scale=2, nullable=true, options={"unsigned":true})
207
     */
208
    private $price01;
209
210
    /**
211
     * @var string
212
     *
213
     * @ORM\Column(name="price02", type="decimal", precision=12, scale=2, options={"unsigned":true})
214
     */
215
    private $price02;
216
217
    /**
218
     * @var string|null
219
     *
220
     * @ORM\Column(name="delivery_fee", type="decimal", precision=12, scale=2, nullable=true, options={"unsigned":true})
221
     */
222
    private $delivery_fee;
223
224
    /**
225
     * @var boolean
226
     *
227
     * @ORM\Column(name="visible", type="boolean", options={"default":true})
228
     */
229
    private $visible;
230
231
    /**
232
     * @var \DateTime
233
     *
234
     * @ORM\Column(name="create_date", type="datetimetz")
235
     */
236
    private $create_date;
237
238
    /**
239
     * @var \DateTime
240
     *
241
     * @ORM\Column(name="update_date", type="datetimetz")
242
     */
243
    private $update_date;
244
245
    /**
246
     * @var string|null
247
     *
248
     * @ORM\Column(name="currency_code", type="string", nullable=true)
249
     */
250
    private $currency_code;
251
252
    /**
253
     * @var string
254
     *
255
     * @ORM\Column(name="point_rate", type="decimal", precision=10, scale=0, options={"unsigned":true}, nullable=true)
256
     */
257
    private $point_rate;
258
259
    /**
260
     * @var \Eccube\Entity\ProductStock
261
     *
262
     * @ORM\OneToOne(targetEntity="Eccube\Entity\ProductStock", mappedBy="ProductClass", cascade={"persist","remove"})
263
     */
264
    private $ProductStock;
265
266
    /**
267
     * @var \Eccube\Entity\TaxRule
268
     *
269
     * @ORM\OneToOne(targetEntity="Eccube\Entity\TaxRule", mappedBy="ProductClass", cascade={"persist","remove"})
270
     */
271
    private $TaxRule;
272
273
    /**
274
     * @var \Eccube\Entity\Product
275
     *
276
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Product", inversedBy="ProductClasses")
277
     * @ORM\JoinColumns({
278
     *   @ORM\JoinColumn(name="product_id", referencedColumnName="id")
279
     * })
280
     */
281
    private $Product;
282
283
    /**
284
     * @var \Eccube\Entity\Master\SaleType
285
     *
286
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\SaleType")
287
     * @ORM\JoinColumns({
288
     *   @ORM\JoinColumn(name="sale_type_id", referencedColumnName="id")
289
     * })
290
     */
291
    private $SaleType;
292
293
    /**
294
     * @var \Eccube\Entity\ClassCategory
295
     *
296
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\ClassCategory")
297
     * @ORM\JoinColumns({
298
     *   @ORM\JoinColumn(name="class_category_id1", referencedColumnName="id", nullable=true)
299
     * })
300
     */
301
    private $ClassCategory1;
302
303
    /**
304
     * @var \Eccube\Entity\ClassCategory
305
     *
306
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\ClassCategory")
307
     * @ORM\JoinColumns({
308
     *   @ORM\JoinColumn(name="class_category_id2", referencedColumnName="id", nullable=true)
309
     * })
310
     */
311
    private $ClassCategory2;
312
313
    /**
314
     * @var \Eccube\Entity\DeliveryDuration
315
     *
316
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\DeliveryDuration")
317
     * @ORM\JoinColumns({
318
     *   @ORM\JoinColumn(name="delivery_duration_id", referencedColumnName="id")
319
     * })
320
     */
321
    private $DeliveryDuration;
322
323
    /**
324
     * @var \Eccube\Entity\Member
325
     *
326
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Member")
327
     * @ORM\JoinColumns({
328
     *   @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
329
     * })
330
     */
331
    private $Creator;
332
333 3
    public function __clone()
334
    {
335 3
        $this->id = null;
336
    }
337
338
    /**
339
     * Get id.
340
     *
341
     * @return int
342
     */
343 392
    public function getId()
344
    {
345 392
        return $this->id;
346
    }
347
348
    /**
349
     * Set code.
350
     *
351
     * @param string|null $code
352
     *
353
     * @return ProductClass
354
     */
355 364
    public function setCode($code = null)
356
    {
357 364
        $this->code = $code;
358
359 364
        return $this;
360
    }
361
362
    /**
363
     * Get code.
364
     *
365
     * @return string|null
366
     */
367 303
    public function getCode()
368
    {
369 303
        return $this->code;
370
    }
371
372
    /**
373
     * Set stock.
374
     *
375
     * @param string|null $stock
376
     *
377
     * @return ProductClass
378
     */
379 385
    public function setStock($stock = null)
380
    {
381 385
        $this->stock = $stock;
382
383 385
        return $this;
384
    }
385
386
    /**
387
     * Get stock.
388
     *
389
     * @return string|null
390
     */
391 280
    public function getStock()
392
    {
393 280
        return $this->stock;
394
    }
395
396
    /**
397
     * Set stockUnlimited.
398
     *
399
     * @param boolean $stockUnlimited
400
     *
401
     * @return ProductClass
402
     */
403 367
    public function setStockUnlimited($stockUnlimited)
404
    {
405 367
        $this->stock_unlimited = $stockUnlimited;
406
407 367
        return $this;
408
    }
409
410
    /**
411
     * Get stockUnlimited.
412
     *
413
     * @return boolean
414
     */
415 312
    public function isStockUnlimited()
416
    {
417 312
        return $this->stock_unlimited;
418
    }
419
420
    /**
421
     * Set saleLimit.
422
     *
423
     * @param string|null $saleLimit
424
     *
425
     * @return ProductClass
426
     */
427 33
    public function setSaleLimit($saleLimit = null)
428
    {
429 33
        $this->sale_limit = $saleLimit;
430
431 33
        return $this;
432
    }
433
434
    /**
435
     * Get saleLimit.
436
     *
437
     * @return string|null
438
     */
439 126
    public function getSaleLimit()
440
    {
441 126
        return $this->sale_limit;
442
    }
443
444
    /**
445
     * Set price01.
446
     *
447
     * @param string|null $price01
448
     *
449
     * @return ProductClass
450
     */
451 44
    public function setPrice01($price01 = null)
452
    {
453 44
        $this->price01 = $price01;
454
455 44
        return $this;
456
    }
457
458
    /**
459
     * Get price01.
460
     *
461
     * @return string|null
462
     */
463 439
    public function getPrice01()
464
    {
465 439
        return $this->price01;
466
    }
467
468
    /**
469
     * Set price02.
470
     *
471
     * @param string $price02
472
     *
473
     * @return ProductClass
474
     */
475 387
    public function setPrice02($price02)
476
    {
477 387
        $this->price02 = $price02;
478
479 387
        return $this;
480
    }
481
482
    /**
483
     * Get price02.
484
     *
485
     * @return string
486
     */
487 439
    public function getPrice02()
488
    {
489 439
        return $this->price02;
490
    }
491
492
    /**
493
     * Set deliveryFee.
494
     *
495
     * @param string|null $deliveryFee
496
     *
497
     * @return ProductClass
498
     */
499 25
    public function setDeliveryFee($deliveryFee = null)
500
    {
501 25
        $this->delivery_fee = $deliveryFee;
502
503 25
        return $this;
504
    }
505
506
    /**
507
     * Get deliveryFee.
508
     *
509
     * @return string|null
510
     */
511 45
    public function getDeliveryFee()
512
    {
513 45
        return $this->delivery_fee;
514
    }
515
516
    /**
517
     * @return boolean
518
     */
519 233
    public function isVisible()
520
    {
521 233
        return $this->visible;
522
    }
523
524
    /**
525
     * @param boolean $visible
526
     *
527
     * @return ProductClass
528
     */
529 372
    public function setVisible($visible)
530
    {
531 372
        $this->visible = $visible;
532
533 372
        return $this;
534
    }
535
536
    /**
537
     * Set createDate.
538
     *
539
     * @param \DateTime $createDate
540
     *
541
     * @return ProductClass
542
     */
543 366
    public function setCreateDate($createDate)
544
    {
545 366
        $this->create_date = $createDate;
546
547 366
        return $this;
548
    }
549
550
    /**
551
     * Get createDate.
552
     *
553
     * @return \DateTime
554
     */
555
    public function getCreateDate()
556
    {
557
        return $this->create_date;
558
    }
559
560
    /**
561
     * Set updateDate.
562
     *
563
     * @param \DateTime $updateDate
564
     *
565
     * @return ProductClass
566
     */
567 370
    public function setUpdateDate($updateDate)
568
    {
569 370
        $this->update_date = $updateDate;
570
571 370
        return $this;
572
    }
573
574
    /**
575
     * Get updateDate.
576
     *
577
     * @return \DateTime
578
     */
579
    public function getUpdateDate()
580
    {
581
        return $this->update_date;
582
    }
583
584
    /**
585
     * Get currencyCode.
586
     *
587
     * @return string
588
     */
589
    public function getCurrencyCode()
590
    {
591
        return $this->currency_code;
592
    }
593
594
    /**
595
     * Set currencyCode.
596
     *
597
     * @param string|null $currencyCode
598
     *
599
     * @return $this
600
     */
601 366
    public function setCurrencyCode($currencyCode = null)
602
    {
603 366
        $this->currency_code = $currencyCode;
604
605 366
        return $this;
606
    }
607
608
    /**
609
     * Set productStock.
610
     *
611
     * @param \Eccube\Entity\ProductStock|null $productStock
612
     *
613
     * @return ProductClass
614
     */
615 367
    public function setProductStock(\Eccube\Entity\ProductStock $productStock = null)
616
    {
617 367
        $this->ProductStock = $productStock;
618
619 367
        return $this;
620
    }
621
622
    /**
623
     * Get productStock.
624
     *
625
     * @return \Eccube\Entity\ProductStock|null
626
     */
627 35
    public function getProductStock()
628
    {
629 35
        return $this->ProductStock;
630
    }
631
632
    /**
633
     * Set taxRule.
634
     *
635
     * @param \Eccube\Entity\TaxRule|null $taxRule
636
     *
637
     * @return ProductClass
638
     */
639 10
    public function setTaxRule(\Eccube\Entity\TaxRule $taxRule = null)
640
    {
641 10
        $this->TaxRule = $taxRule;
642
643 10
        return $this;
644
    }
645
646
    /**
647
     * Get taxRule.
648
     *
649
     * @return \Eccube\Entity\TaxRule|null
650
     */
651 22
    public function getTaxRule()
652
    {
653 22
        return $this->TaxRule;
654
    }
655
656
    /**
657
     * Set product.
658
     *
659
     * @param \Eccube\Entity\Product|null $product
660
     *
661
     * @return ProductClass
662
     */
663 371
    public function setProduct(\Eccube\Entity\Product $product = null)
664
    {
665 371
        $this->Product = $product;
666
667 371
        return $this;
668
    }
669
670
    /**
671
     * Get product.
672
     *
673
     * @return \Eccube\Entity\Product|null
674
     */
675 421
    public function getProduct()
676
    {
677 421
        return $this->Product;
678
    }
679
680
    /**
681
     * Set saleType.
682
     *
683
     * @param \Eccube\Entity\Master\SaleType|null $saleType
684
     *
685
     * @return ProductClass
686
     */
687 366
    public function setSaleType(\Eccube\Entity\Master\SaleType $saleType = null)
688
    {
689 366
        $this->SaleType = $saleType;
690
691 366
        return $this;
692
    }
693
694
    /**
695
     * Get saleType.
696
     *
697
     * @return \Eccube\Entity\Master\SaleType|null
698
     */
699 148
    public function getSaleType()
700
    {
701 148
        return $this->SaleType;
702
    }
703
704
    /**
705
     * Set classCategory1.
706
     *
707
     * @param \Eccube\Entity\ClassCategory|null $classCategory1
708
     *
709
     * @return ProductClass
710
     */
711 369
    public function setClassCategory1(\Eccube\Entity\ClassCategory $classCategory1 = null)
712
    {
713 369
        $this->ClassCategory1 = $classCategory1;
714
715 369
        return $this;
716
    }
717
718
    /**
719
     * Get classCategory1.
720
     *
721
     * @return \Eccube\Entity\ClassCategory|null
722
     */
723 327
    public function getClassCategory1()
724
    {
725 327
        return $this->ClassCategory1;
726
    }
727
728
    /**
729
     * Set classCategory2.
730
     *
731
     * @param \Eccube\Entity\ClassCategory|null $classCategory2
732
     *
733
     * @return ProductClass
734
     */
735 244
    public function setClassCategory2(\Eccube\Entity\ClassCategory $classCategory2 = null)
736
    {
737 244
        $this->ClassCategory2 = $classCategory2;
738
739 244
        return $this;
740
    }
741
742
    /**
743
     * Get classCategory2.
744
     *
745
     * @return \Eccube\Entity\ClassCategory|null
746
     */
747 269
    public function getClassCategory2()
748
    {
749 269
        return $this->ClassCategory2;
750
    }
751
752
    /**
753
     * Set deliveryDuration.
754
     *
755
     * @param \Eccube\Entity\DeliveryDuration|null $deliveryDuration
756
     *
757
     * @return ProductClass
758
     */
759 355
    public function setDeliveryDuration(\Eccube\Entity\DeliveryDuration $deliveryDuration = null)
760
    {
761 355
        $this->DeliveryDuration = $deliveryDuration;
762
763 355
        return $this;
764
    }
765
766
    /**
767
     * Get deliveryDuration.
768
     *
769
     * @return \Eccube\Entity\DeliveryDuration|null
770
     */
771 96
    public function getDeliveryDuration()
772
    {
773 96
        return $this->DeliveryDuration;
774
    }
775
776
    /**
777
     * Set creator.
778
     *
779
     * @param \Eccube\Entity\Member|null $creator
780
     *
781
     * @return ProductClass
782
     */
783 370
    public function setCreator(\Eccube\Entity\Member $creator = null)
784
    {
785 370
        $this->Creator = $creator;
786
787 370
        return $this;
788
    }
789
790
    /**
791
     * Get creator.
792
     *
793
     * @return \Eccube\Entity\Member|null
794
     */
795
    public function getCreator()
796
    {
797
        return $this->Creator;
798
    }
799
800
    /**
801
     * Set pointRate
802
     *
803
     * @param string $pointRate
804
     *
805
     * @return ProductClass
806
     */
807
    public function setPointRate($pointRate)
808
    {
809
        $this->point_rate = $pointRate;
810
811
        return $this;
812
    }
813
814
    /**
815
     * Get pointRate
816
     *
817
     * @return string
818
     */
819
    public function getPointRate()
820
    {
821
        return $this->point_rate;
822
    }
823
}
824