Completed
Push — 4.0 ( 87d096...bcc1be )
by Kiyotaka
05:44 queued 11s
created

EventSubscriber/TaxRuleEventSubscriber.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.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\Doctrine\EventSubscriber;
15
16
use Doctrine\Common\EventSubscriber;
17
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
18
use Doctrine\ORM\Events;
19
use Eccube\Entity\ProductClass;
20
use Eccube\Service\TaxRuleService;
21
use Symfony\Component\DependencyInjection\ContainerInterface;
22
23
class TaxRuleEventSubscriber implements EventSubscriber
24
{
25
    /**
26
     * @var TaxRuleService
27
     */
28
    protected $container;
29
30
    /**
31
     * TaxRuleEventSubscriber constructor.
32
     */
33 1332
    public function __construct(ContainerInterface $container)
34
    {
35 1332
        $this->container = $container;
36
    }
37
38 463
    public function getTaxRuleService()
39
    {
40 463
        return $this->container->get(TaxRuleService::class);
41
    }
42
43 1332
    public function getSubscribedEvents()
44
    {
45
        return [
46 1332
            Events::prePersist,
47 1332
            Events::postLoad,
48 1332
            Events::postPersist,
49 1332
            Events::postUpdate,
50
        ];
51
    }
52
53 772 View Code Duplication
    public function prePersist(LifecycleEventArgs $args)
54
    {
55 772
        $entity = $args->getObject();
56
57 772
        if ($entity instanceof ProductClass) {
58 408
            $entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01(),
59 408
                $entity->getProduct(), $entity));
60 408
            $entity->setPrice02IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice02(),
61 408
                $entity->getProduct(), $entity));
62
        }
63
    }
64
65 1020 View Code Duplication
    public function postLoad(LifecycleEventArgs $args)
0 ignored issues
show
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...
66
    {
67 1020
        $entity = $args->getObject();
68
69 1020
        if ($entity instanceof ProductClass) {
70 135
            $entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01(),
71 135
                $entity->getProduct(), $entity));
72 135
            $entity->setPrice02IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice02(),
73 135
                $entity->getProduct(), $entity));
74
        }
75
    }
76
77 772 View Code Duplication
    public function postPersist(LifecycleEventArgs $args)
0 ignored issues
show
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...
78
    {
79 772
        $entity = $args->getObject();
80
81 772
        if ($entity instanceof ProductClass) {
82 405
            $entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01(),
83 405
                $entity->getProduct(), $entity));
84 405
            $entity->setPrice02IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice02(),
85 405
                $entity->getProduct(), $entity));
86
        }
87
    }
88
89 523 View Code Duplication
    public function postUpdate(LifecycleEventArgs $args)
0 ignored issues
show
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...
90
    {
91 523
        $entity = $args->getObject();
92
93 523
        if ($entity instanceof ProductClass) {
94 102
            $entity->setPrice01IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice01(),
95 102
                $entity->getProduct(), $entity));
96 102
            $entity->setPrice02IncTax($this->getTaxRuleService()->getPriceIncTax($entity->getPrice02(),
97 102
                $entity->getProduct(), $entity));
98
        }
99
    }
100
}
101