Completed
Push — master ( 15ec76...bc0d17 )
by Kamil
15s
created

CartViewRepository::getOneByToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sylius\ShopApiPlugin\ViewRepository;
6
7
use Sylius\Component\Core\Model\OrderInterface;
8
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
9
use Sylius\ShopApiPlugin\Factory\CartViewFactoryInterface;
10
use Sylius\ShopApiPlugin\View\CartSummaryView;
11
use Webmozart\Assert\Assert;
12
13
final class CartViewRepository implements CartViewRepositoryInterface
14
{
15
    /**
16
     * @var OrderRepositoryInterface
17
     */
18
    private $cartRepository;
19
20
    /**
21
     * @var CartViewFactoryInterface
22
     */
23
    private $cartViewFactory;
24
25
    /**
26
     * @param OrderRepositoryInterface $cartRepository
27
     * @param CartViewFactoryInterface $cartViewFactory
28
     */
29
    public function __construct(
30
        OrderRepositoryInterface $cartRepository,
31
        CartViewFactoryInterface $cartViewFactory
32
    ) {
33
        $this->cartRepository = $cartRepository;
34
        $this->cartViewFactory = $cartViewFactory;
35
    }
36
37
    public function getOneByToken(string $orderToken): CartSummaryView
38
    {
39
        /** @var OrderInterface $cart */
40
        $cart = $this->cartRepository->findOneBy(['tokenValue' => $orderToken]);
41
42
        Assert::notNull($cart, 'Cart with given id does not exists');
43
44
        return $this->cartViewFactory->create($cart, $cart->getLocaleCode());
45
    }
46
}
47