Completed
Pull Request — master (#97)
by Paweł
03:09
created

CompleteOrderAction::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
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\ChoosePaymentMethod;
9
use Sylius\ShopApiPlugin\Command\ChooseShippingMethod;
10
use Sylius\ShopApiPlugin\Command\CompleteOrder;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
14 View Code Duplication
final class CompleteOrderAction
15
{
16
    /**
17
     * @var ViewHandlerInterface
18
     */
19
    private $viewHandler;
20
21
    /**
22
     * @var CommandBus
23
     */
24
    private $bus;
25
26
    /**
27
     * @param ViewHandlerInterface $viewHandler
28
     * @param CommandBus $bus
29
     */
30
    public function __construct(ViewHandlerInterface $viewHandler, CommandBus $bus)
31
    {
32
        $this->viewHandler = $viewHandler;
33
        $this->bus = $bus;
34
    }
35
36
    /**
37
     * @param Request $request
38
     *
39
     * @return Response
40
     */
41
    public function __invoke(Request $request)
42
    {
43
        $this->bus->handle(new CompleteOrder(
44
            $request->attributes->get('token'),
45
            $request->request->get('email'),
46
            $request->request->get('notes')
47
        ));
48
49
        return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT));
50
    }
51
}
52