Completed
Pull Request — master (#133)
by Łukasz
03:33
created

DropCartHandler::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 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