Failed Conditions
Pull Request — experimental/3.1 (#2532)
by Kentaro
34:08 queued 17:05
created

TaxRuleEventSubscriber   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 74
Duplicated Lines 64.86 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 97.14%

Importance

Changes 0
Metric Value
dl 48
loc 74
ccs 34
cts 35
cp 0.9714
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 9 1
A prePersist() 12 12 3
A postLoad() 12 12 3
A postPersist() 12 12 3
A postUpdate() 12 12 3

How to fix   Duplicated Code   

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:

1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Doctrine\EventSubscriber;
26
27
use Doctrine\Common\EventSubscriber;
28
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
29
use Doctrine\ORM\Events;
30
use Eccube\Entity\ProductClass;
31
use Eccube\Entity\OrderItem;
32
33
class TaxRuleEventSubscriber implements EventSubscriber
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
34
{
35
    /**
36
     * @var \Eccube\Service\TaxRuleService
37
     */
38
    private $taxRateService;
39
40 1067
    public function __construct(\Eccube\Service\TaxRuleService $taxRateService)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
41
    {
42 1067
        $this->taxRateService = $taxRateService;
43
    }
44
45 1067
    public function getSubscribedEvents()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
46
    {
47
        return array(
48 1067
            Events::prePersist,
49 1067
            Events::postLoad,
50 1067
            Events::postPersist,
51 1067
            Events::postUpdate,
52
        );
53
    }
54
55 541 View Code Duplication
    public function prePersist(LifecycleEventArgs $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
introduced by
Missing function doc comment
Loading history...
56
    {
57 541
        $entity = $args->getObject();
58
59 541
        if ($entity instanceof ProductClass) {
60 216
            $entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity));
61 216
            $entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity));
62
        }
63 541
        if ($entity instanceof OrderItem) {
64 116
            $entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass()));
65
        }
66
    }
67
68 771 View Code Duplication
    public function postLoad(LifecycleEventArgs $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
introduced by
Missing function doc comment
Loading history...
69
    {
70 771
        $entity = $args->getObject();
71
72 771
        if ($entity instanceof ProductClass) {
73 66
            $entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity));
74 66
            $entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity));
75
        }
76 771
        if ($entity instanceof OrderItem) {
77
            $entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass()));
78
        }
79
    }
80
81 541 View Code Duplication
    public function postPersist(LifecycleEventArgs $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
introduced by
Missing function doc comment
Loading history...
82
    {
83 541
        $entity = $args->getObject();
84
85 541
        if ($entity instanceof ProductClass) {
86 216
            $entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity));
87 216
            $entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity));
88
        }
89 541
        if ($entity instanceof OrderItem) {
90 116
            $entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass()));
91
        }
92
    }
93
94 318 View Code Duplication
    public function postUpdate(LifecycleEventArgs $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
introduced by
Missing function doc comment
Loading history...
95
    {
96 318
        $entity = $args->getObject();
97
98 318
        if ($entity instanceof ProductClass) {
99 42
            $entity->setPrice01IncTax($this->taxRateService->getPriceIncTax($entity->getPrice01(), $entity->getProduct(), $entity));
100 42
            $entity->setPrice02IncTax($this->taxRateService->getPriceIncTax($entity->getPrice02(), $entity->getProduct(), $entity));
101
        }
102 318
        if ($entity instanceof OrderItem) {
103 3
            $entity->setPriceIncTax($this->taxRateService->getPriceIncTax($entity->getPrice(), $entity->getProduct(), $entity->getProductClass()));
104
        }
105
    }
106
}
107