Completed
Pull Request — master (#290)
by
unknown
36:49 queued 34:03
created

AddressAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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