Completed
Pull Request — master (#97)
by Paweł
03:09
created

CompleteOrderAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
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 38
loc 38
rs 10

2 Methods

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