Completed
Branch master (9d8d38)
by Łukasz
03:25
created

AddCouponAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A __invoke() 9 9 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\Controller\Cart;
4
5
use FOS\RestBundle\View\View;
6
use FOS\RestBundle\View\ViewHandlerInterface;
7
use League\Tactician\CommandBus;
8
use Sylius\ShopApiPlugin\Command\AddCoupon;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12 View Code Duplication
final class AddCouponAction
13
{
14
    /**
15
     * @var ViewHandlerInterface
16
     */
17
    private $viewHandler;
18
19
    /**
20
     * @var CommandBus
21
     */
22
    private $bus;
23
24
    /**
25
     * @param ViewHandlerInterface $viewHandler
26
     * @param CommandBus $bus
27
     */
28
    public function __construct(ViewHandlerInterface $viewHandler, CommandBus $bus)
29
    {
30
        $this->viewHandler = $viewHandler;
31
        $this->bus = $bus;
32
    }
33
34
    /**
35
     * @param Request $request
36
     *
37
     * @return Response
38
     */
39
    public function __invoke(Request $request)
40
    {
41
        $this->bus->handle(new AddCoupon(
42
            $request->attributes->get('token'),
43
            $request->request->get('coupon')
44
        ));
45
46
        return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT));
47
    }
48
}
49