Completed
Push — master ( 41948a...5bb6bb )
by Łukasz
17:08 queued 13:33
created

ChooseShippingMethodAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Controller\Checkout;
4
5
use FOS\RestBundle\View\View;
6
use FOS\RestBundle\View\ViewHandlerInterface;
7
use League\Tactician\CommandBus;
8
use Sylius\ShopApiPlugin\Command\ChooseShippingMethod;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12
final class ChooseShippingMethodAction
13
{
14
    /**
15
     * @var ViewHandlerInterface
16
     */
17
    private $viewHandler;
18
19
    /**
20
     * @var CommandBus
21
     */
22
    private $bus;
23
24
    /**
25
     * @param ViewHandlerInterface $viewHandler
26
     * @param CommandBus $bus
27
     */
28
    public function __construct(ViewHandlerInterface $viewHandler, CommandBus $bus)
29
    {
30
        $this->viewHandler = $viewHandler;
31
        $this->bus = $bus;
32
    }
33
34
    /**
35
     * @param Request $request
36
     *
37
     * @return Response
38
     */
39
    public function __invoke(Request $request)
40
    {
41
        $this->bus->handle(new ChooseShippingMethod(
42
            $request->attributes->get('token'),
43
            $request->attributes->get('shippingId'),
44
            $request->request->get('method')
45
        ));
46
47
        return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT));
48
    }
49
}
50