Completed
Push — sf/improvement-coverage ( b3937e...01a837 )
by Kiyotaka
51:20 queued 45:08
created

DeliverySettingValidator::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 13
rs 9.8333
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\Processor;
15
16
use Eccube\Entity\ItemInterface;
17
use Eccube\Repository\DeliveryRepository;
18
use Eccube\Service\PurchaseFlow\InvalidItemException;
19
use Eccube\Service\PurchaseFlow\PurchaseContext;
20
use Eccube\Service\PurchaseFlow\ItemValidator;
21
22
/**
23
 * 販売種別に配送業者が設定されているかどうか.
24
 */
25
class DeliverySettingValidator extends ItemValidator
26
{
27
    /**
28
     * @var DeliveryRepository
29
     */
30
    protected $deliveryRepository;
31
32
    /**
33
     * DeliverySettingValidator constructor.
34
     *
35
     * @param DeliveryRepository $deliveryRepository
36
     */
37 161
    public function __construct(DeliveryRepository $deliveryRepository)
38
    {
39 161
        $this->deliveryRepository = $deliveryRepository;
40
    }
41
42
    /**
43
     * validate
44
     *
45
     * @param ItemInterface $item
46
     * @param PurchaseContext $context
47
     *
48
     * @throws InvalidItemException
49
     */
50
51
    /**
52
     * @param ItemInterface $item
53
     * @param PurchaseContext $context
54
     *
55
     * @throws InvalidItemException
56
     */
57 80
    protected function validate(ItemInterface $item, PurchaseContext $context)
58
    {
59 80
        if (!$item->isProduct()) {
60 51
            return;
61
        }
62
63 80
        $SaleType = $item->getProductClass()->getSaleType();
64 80
        $Deliveries = $this->deliveryRepository->findBy(['SaleType' => $SaleType, 'visible' => true]);
65
66 80
        if (empty($Deliveries)) {
67 1
            $this->throwInvalidItemException('cart.product.not.saletype', $item->getProductClass());
68
        }
69
    }
70
71
    /**
72
     * handle
73
     *
74
     * @param ItemInterface $item
75
     * @param PurchaseContext $context
76
     */
77 1
    protected function handle(ItemInterface $item, PurchaseContext $context)
78
    {
79 1
        $item->setQuantity(0);
80
    }
81
}
82