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

RemoveCouponHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A handle() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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