Completed
Pull Request — 4.0 (#4223)
by Kentaro
04:57
created

PaymentTotalLimitValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 7 2
A __toString() 0 4 1
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\Service\PurchaseFlow\Processor;
15
16
use Eccube\Common\EccubeConfig;
17
use Eccube\Entity\ItemHolderInterface;
18
use Eccube\Service\PurchaseFlow\ItemHolderPostValidator;
19
use Eccube\Service\PurchaseFlow\PurchaseContext;
20
21
/**
22
 * 購入金額上限チェック.
23
 */
24
class PaymentTotalLimitValidator extends ItemHolderPostValidator
25
{
26
    /**
27
     * @var int
28
     */
29
    private $maxTotalFee;
30
31
    /**
32
     * PaymentTotalLimitValidator constructor.
33
     *
34
     * @param EccubeConfig $eccubeConfig
35
     */
36 757
    public function __construct(EccubeConfig $eccubeConfig)
37
    {
38 757
        $this->maxTotalFee = $eccubeConfig['eccube_max_total_fee'];
39
    }
40
41
    /**
42
     * @param ItemHolderInterface $itemHolder
43
     * @param PurchaseContext $context
44
     *
45
     * @throws \Eccube\Service\PurchaseFlow\InvalidItemException
46
     */
47 238
    protected function validate(ItemHolderInterface $itemHolder, PurchaseContext $context)
48
    {
49 238
        $totalPrice = $itemHolder->getTotal();
50 238
        if ($totalPrice > $this->maxTotalFee) {
51 2
            $this->throwInvalidItemException('front.shopping.over_price_limit');
52
        }
53
    }
54
55
    public function __toString()
56
    {
57
        return get_class($this);
58
    }
59
}
60