Completed
Push — master ( 10a92d...cbdd73 )
by Łukasz
25:09 queued 19:28
created

RemoveCouponHandler::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 11
loc 11
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\Component\Order\Processor\OrderProcessorInterface;
8
use Sylius\ShopApiPlugin\Command\RemoveCoupon;
9
use Webmozart\Assert\Assert;
10
11 View Code Duplication
final class RemoveCouponHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * @var OrderRepositoryInterface
15
     */
16
    private $orderRepository;
17
18
    /**
19
     * @var OrderProcessorInterface
20
     */
21
    private $orderProcessor;
22
23
    /**
24
     * @param OrderRepositoryInterface $orderRepository
25
     * @param OrderProcessorInterface $orderProcessor
26
     */
27
    public function __construct(
28
        OrderRepositoryInterface $orderRepository,
29
        OrderProcessorInterface $orderProcessor
30
    ) {
31
        $this->orderRepository = $orderRepository;
32
        $this->orderProcessor = $orderProcessor;
33
    }
34
35
    /**
36
     * @param RemoveCoupon $removeCoupon
37
     */
38
    public function handle(RemoveCoupon $removeCoupon)
39
    {
40
        /** @var OrderInterface $cart */
41
        $cart = $this->orderRepository->findOneBy(['tokenValue' => $removeCoupon->orderToken()]);
42
43
        Assert::notNull($cart, sprintf('Cart with token %s has not been found.', $removeCoupon->orderToken()));
44
45
        $cart->setPromotionCoupon(null);
46
47
        $this->orderProcessor->process($cart);
48
    }
49
}
50