Completed
Push — master ( 8d10db...a4c05f )
by Łukasz
10s
created

SummarizeAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 8
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A __invoke() 0 13 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\Component\Core\Model\OrderInterface;
9
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
10
use Sylius\ShopApiPlugin\Factory\AddressViewFactoryInterface;
11
use Sylius\ShopApiPlugin\Factory\CartViewFactoryInterface;
12
use Sylius\ShopApiPlugin\Command\AddressOrder;
13
use Sylius\ShopApiPlugin\Model\Address;
14
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
18
19
final class SummarizeAction
20
{
21
    /**
22
     * @var OrderRepositoryInterface
23
     */
24
    private $cartRepository;
25
26
    /**
27
     * @var ViewHandlerInterface
28
     */
29
    private $viewHandler;
30
31
    /**
32
     * @var CartViewFactoryInterface
33
     */
34
    private $cartViewFactory;
35
36
    /**
37
     * @param OrderRepositoryInterface $cartRepository
38
     * @param ViewHandlerInterface $viewHandler
39
     * @param CartViewFactoryInterface $cartViewFactory
40
     */
41
    public function __construct(
42
        OrderRepositoryInterface $cartRepository,
43
        ViewHandlerInterface $viewHandler,
44
        CartViewFactoryInterface $cartViewFactory
45
    ) {
46
        $this->cartRepository = $cartRepository;
47
        $this->viewHandler = $viewHandler;
48
        $this->cartViewFactory = $cartViewFactory;
49
    }
50
51
    /**
52
     * @param Request $request
53
     *
54
     * @return Response
55
     */
56
    public function __invoke(Request $request)
57
    {
58
        /** @var OrderInterface $cart */
59
        $cart = $this->cartRepository->findOneBy(['tokenValue' => $request->attributes->get('token')]);
60
61
        if (null === $cart) {
62
            throw new NotFoundHttpException('Cart with given id does not exists');
63
        }
64
65
        return $this->viewHandler->handle(
66
            View::create($this->cartViewFactory->create($cart, $cart->getLocaleCode()), Response::HTTP_OK)
67
        );
68
    }
69
}
70