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

ItemValidator::__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;
15
16
use Eccube\Entity\ItemInterface;
17
18
/**
19
 * 明細単位の妥当性検証.
20
 */
21
abstract class ItemValidator
22
{
23
    use ValidatorTrait;
24
25
    /**
26
     * @param ItemInterface $item
27
     * @param PurchaseContext $context
28
     *
29
     * @return ProcessResult
30
     */
31
    final public function execute(ItemInterface $item, PurchaseContext $context)
32 93
    {
33
        try {
34
            $this->validate($item, $context);
35 93
36
            return ProcessResult::success(null, static::class);
37 86
        } catch (InvalidItemException $e) {
38 42
            $this->handle($item, $context);
39 42
40 39
            return ProcessResult::warn($e->getMessage(), static::class);
41
        }
42
    }
43 42
44
    /**
45
     * 妥当性検証を行う.
46
     *
47
     * @param ItemInterface $item
48
     * @param PurchaseContext $context
49
     */
50
    abstract protected function validate(ItemInterface $item, PurchaseContext $context);
51
52
    /**
53
     * 検証エラー時に後処理を行う.
54
     *
55
     * @param ItemInterface $item
56
     * @param PurchaseContext $context
57
     */
58
    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...
59
    {
60
    }
61
62
    public function __toString()
63
    {
64
        return get_class($this);
65
    }
66
}
67