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

PaymentTotalLimitValidator::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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