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

AddPointProcessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 59
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A process() 0 14 3
A priceToAddPoint() 0 4 1
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\Service\PurchaseFlow\Processor;
15
16
use Doctrine\ORM\EntityManagerInterface;
17
use Eccube\Entity\BaseInfo;
18
use Eccube\Entity\ItemHolderInterface;
19
use Eccube\Service\PurchaseFlow\ItemHolderProcessor;
20
use Eccube\Service\PurchaseFlow\ProcessResult;
21
use Eccube\Service\PurchaseFlow\PurchaseContext;
22
23
/**
24
 * 加算ポイント.
25
 */
26
class AddPointProcessor implements ItemHolderProcessor
27
{
28
    /**
29
     * @var EntityManagerInterface
30
     */
31
    protected $entityManager;
32
33
    /**
34
     * @var BaseInfo
35
     */
36
    protected $BaseInfo;
37
38
    /**
39
     * AddPointProcessor constructor.
40
     *
41
     * @param EntityManagerInterface $entityManager
42
     * @param BaseInfo $BaseInfo
43
     */
44
    public function __construct(EntityManagerInterface $entityManager, BaseInfo $BaseInfo)
45
    {
46
        $this->entityManager = $entityManager;
47
        $this->BaseInfo = $BaseInfo;
48
    }
49
50
    /**
51
     * @param ItemHolderInterface $itemHolder
52
     * @param PurchaseContext     $context
53
     *
54
     * @return ProcessResult
55
     */
56
    public function process(ItemHolderInterface $itemHolder, PurchaseContext $context)
57
    {
58
        $addPoint = 0;
59
        foreach ($itemHolder->getItems() as $item) {
60
            $rate = $item->getPointRate();
61
            if ($rate === null) {
62
                $rate = $this->BaseInfo->getBasicPointRate();
63
            }
64
            $addPoint += $this->priceToAddPoint($rate, $item->getPriceIncTax(), $item->getQuantity());
0 ignored issues
show
Bug introduced by
The method getPriceIncTax() does not exist on Eccube\Entity\ItemInterface. Did you maybe mean getPrice()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
65
        }
66
        $itemHolder->setAddPoint($addPoint);
67
68
        return ProcessResult::success();
69
    }
70
71
    /**
72
     * 単価と数量から加算ポイントに換算する.
73
     *
74
     * @param integer $pointRate ポイント付与率(%)
75
     * @param integer $price 単価
76
     * @param integer $quantity 数量
77
     *
78
     * @return double additional point
79
     */
80
    protected function priceToAddPoint($pointRate, $price, $quantity)
81
    {
82
        return round($price * ($pointRate / 100)) * $quantity;
83
    }
84
}
85