Completed
Pull Request — master (#133)
by Łukasz
04:32
created

DropCartHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 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(
21
        OrderRepositoryInterface $cartRepository
22
    ) {
23
        $this->cartRepository = $cartRepository;
24
    }
25
26
    public function handle(DropCart $dropCart)
27
    {
28
        /** @var OrderInterface $cart */
29
        $cart = $this->cartRepository->findOneBy(['tokenValue' => $dropCart->orderToken()]);
30
31
        Assert::notNull($cart, sprintf('Order with %s token has not been found.', $dropCart->orderToken()));
32
        Assert::same(OrderInterface::STATE_CART, $cart->getState());
33
34
        $this->cartRepository->remove($cart);
35
    }
36
}
37