Completed
Push — support-coverage ( 9b57a3...b5dae6 )
by Kentaro
41:38
created

UsePointToCustomerPurchaseProcessor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 3
1
<?php
2
3
namespace Eccube\Service\PurchaseFlow\Processor;
4
5
use Eccube\Entity\ItemHolderInterface;
6
use Eccube\Service\PurchaseFlow\PurchaseContext;
7
use Eccube\Service\PurchaseFlow\PurchaseProcessor;
8
use Eccube\Service\PurchaseFlow\ProcessResult;
9
10
/**
11
 * 利用ポイントの減算処理
12
 */
13
class UsePointToCustomerPurchaseProcessor implements PurchaseProcessor
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 4
    public function process(ItemHolderInterface $itemHolder, PurchaseContext $context)
19
    {
20 4
        $Order = $itemHolder;
21 4
        $Customer = $context->getUser();
22 4
        if (!$Customer) {
23 1
            return ProcessResult::success();
24
        }
25 3
        if ($Customer->getPoint() < $Order->getUsePoint()) {
26 1
            return ProcessResult::error('利用ポイントが所有ポイントを上回っています.');
27
        }
28 2
        $Customer->setPoint($Customer->getPoint() + $Order->getUsePoint() * -1);
29
30 2
        return ProcessResult::success();
31
    }
32
}
33