Completed
Push — master ( b6acfe...4d9bc8 )
by Paweł
03:29
created

DropCartHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 10 1
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Handler;
4
5
use Sylius\Component\Core\Model\OrderInterface;
6
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
7
use Sylius\ShopApiPlugin\Command\DropCart;
8
use Webmozart\Assert\Assert;
9
10
final class DropCartHandler
11
{
12
    /**
13
     * @var OrderRepositoryInterface
14
     */
15
    private $cartRepository;
16
17
    /**
18
     * @param OrderRepositoryInterface $cartRepository
19
     */
20
    public function __construct(OrderRepositoryInterface $cartRepository)
21
    {
22
        $this->cartRepository = $cartRepository;
23
    }
24
25
    public function handle(DropCart $dropCart)
26
    {
27
        /** @var OrderInterface $cart */
28
        $cart = $this->cartRepository->findOneBy(['tokenValue' => $dropCart->orderToken()]);
29
30
        Assert::notNull($cart, sprintf('Order with %s token has not been found.', $dropCart->orderToken()));
31
        Assert::same(OrderInterface::STATE_CART, $cart->getState());
32
33
        $this->cartRepository->remove($cart);
34
    }
35
}
36