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

TaxRuleEventSubscriber::postLoad()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 1
dl 12
loc 12
ccs 6
cts 7
cp 0.8571
crap 3.0261
rs 9.4285
c 0
b 0
f 0
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