Completed
Pull Request — master (#290)
by
unknown
41:51
created

ChooseShippingMethodAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 1
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
declare(strict_types=1);
4
5
namespace Sylius\SyliusShopApiPlugin\Controller\Checkout;
6
7
use FOS\RestBundle\View\View;
8
use FOS\RestBundle\View\ViewHandlerInterface;
9
use League\Tactician\CommandBus;
10
use Sylius\ShopApiPlugin\Command\ChooseShippingMethod;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\Response;
13
14 View Code Duplication
final class ChooseShippingMethodAction
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 ChooseShippingMethod(
44
            $request->attributes->get('token'),
45
            $request->attributes->get('shippingId'),
46
            $request->request->get('method')
47
        ));
48
49
        return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT));
50
    }
51
}
52