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

CartViewRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getOneByToken() 0 9 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