Failed Conditions
Pull Request — experimental/sf (#3247)
by Kiyotaka
114:07 queued 103:28
created

CustomerPurchaseInfoProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 24
rs 10
c 1
b 0
f 0
ccs 12
cts 13
cp 0.9231
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A commit() 0 21 4
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 Eccube\Entity\ItemHolderInterface;
17
use Eccube\Entity\Order;
18
use Eccube\Service\PurchaseFlow\PurchaseContext;
19
20
/**
21
 * 会員の購入情報更新.
22
 */
23
class CustomerPurchaseInfoProcessor extends AbstractPurchaseProcessor
24
{
25 7
    public function commit(ItemHolderInterface $target, PurchaseContext $context)
26
    {
27 7
        if (!$target instanceof Order) {
28
            return;
29
        }
30
31 7
        $Customer = $target->getCustomer();
32 7
        if (!$Customer) {
33 3
            return;
34
        }
35
36 4
        $now = new \DateTime();
37 4
        $firstBuyDate = $Customer->getFirstBuyDate();
38 4
        if (empty($firstBuyDate)) {
39 4
            $Customer->setFirstBuyDate($now);
40
        }
41 4
        $Customer->setLastBuyDate($now);
42
43 4
        $Customer->setBuyTimes($Customer->getBuyTimes() + 1);
44 4
        $Customer->setBuyTotal($Customer->getBuyTotal() + $target->getTotal());
45
    }
46
}
47