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

ItemValidator::execute()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 5
nop 2
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
ccs 7
cts 7
cp 1
crap 3
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;
15
16
use Eccube\Entity\CartItem;
17
use Eccube\Entity\ItemInterface;
18
19
/**
20
 * 明細単位の妥当性検証.
21
 */
22
abstract class ItemValidator
0 ignored issues
show
introduced by
Abstract class name is not prefixed with "Abstract"
Loading history...
23
{
24
    use ValidatorTrait;
25
26
    /**
27
     * @param ItemInterface   $item
28
     * @param PurchaseContext $context
29
     *
30
     * @return ProcessResult
31
     */
32 224
    final public function execute(ItemInterface $item, PurchaseContext $context)
33
    {
34
        try {
35 224
            $this->validate($item, $context);
36
37 217
            return ProcessResult::success();
38 68
        } catch (InvalidItemException $e) {
39 68
            if ($item instanceof CartItem) {
40 39
                $this->handle($item, $context);
41
            }
42
43 68
            return ProcessResult::warn($e->getMessage());
44
        }
45
    }
46
47
    /**
48
     * 妥当性検証を行う.
49
     *
50
     * @param ItemInterface $item
51
     * @param PurchaseContext $context
52
     */
53
    abstract protected function validate(ItemInterface $item, PurchaseContext $context);
54
55
    /**
56
     * 検証エラー時に後処理を行う.
57
     *
58
     * @param ItemInterface $item
59
     * @param PurchaseContext $context
60
     */
61
    protected function handle(ItemInterface $item, PurchaseContext $context)
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63
    }
64
}
65