Failed Conditions
Pull Request — 4.0 (#3650)
by chihiro
08:02
created

AbstractShoppingController::dispatchEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Controller;
15
16
use Eccube\Entity\ItemHolderInterface;
17
use Eccube\Event\EventArgs;
18
use Eccube\Service\PurchaseFlow\PurchaseContext;
19
use Eccube\Service\PurchaseFlow\PurchaseFlow;
20
use Eccube\Service\PurchaseFlow\PurchaseFlowResult;
21
22
class AbstractShoppingController extends AbstractController
23
{
24
    /**
25
     * @var PurchaseFlow
26
     */
27
    protected $purchaseFlow;
28
29
    /**
30
     * @param PurchaseFlow $shoppingPurchaseFlow
31
     * @required
32
     */
33
    public function setPurchaseFlow(PurchaseFlow $shoppingPurchaseFlow)
34
    {
35
        $this->purchaseFlow = $shoppingPurchaseFlow;
36
    }
37
38
    /**
39
     * @param ItemHolderInterface $itemHolder
40
     *
41
     * @return PurchaseFlowResult
42
     */
43
    protected function validatePurchaseFlow(ItemHolderInterface $itemHolder)
44
    {
45
        /** @var PurchaseFlowResult $flowResult */
46
        $flowResult = $this->purchaseFlow->validate($itemHolder, new PurchaseContext($itemHolder, $itemHolder->getCustomer()));
47
        foreach ($flowResult->getWarning() as $warning) {
48
            $this->addRequestError($warning);
49
        }
50
        foreach ($flowResult->getErrors() as $error) {
51
            $this->addRequestError($error);
52 59
        }
53
54 59
        return $flowResult;
55
    }
56
57
    /**
58
     * @param $eventName
59
     * @param EventArgs $event
60
     *
61
     * @return EventArgs
62 51
     */
63
    protected function dispatchEvent($eventName, EventArgs $event)
64
    {
65 51
        $this->eventDispatcher->dispatch($eventName, $event);
66 51
67 4
        return $event;
68
    }
69
}
70