Completed
Push — master ( 98b142...a3a13d )
by Paweł
02:49
created

ChoosePaymentMethodAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
dl 5
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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 Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
13 View Code Duplication
final class ChoosePaymentMethodAction
1 ignored issue
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...
14
{
15
    /**
16
     * @var ViewHandlerInterface
17
     */
18
    private $viewHandler;
19
20
    /**
21
     * @var CommandBus
22
     */
23
    private $bus;
24
25
    /**
26
     * @param ViewHandlerInterface $viewHandler
27
     * @param CommandBus $bus
28
     */
29
    public function __construct(ViewHandlerInterface $viewHandler, CommandBus $bus)
30
    {
31
        $this->viewHandler = $viewHandler;
32
        $this->bus = $bus;
33
    }
34
35
    /**
36
     * @param Request $request
37
     *
38
     * @return Response
39
     */
40
    public function __invoke(Request $request)
41
    {
42
        $this->bus->handle(new ChoosePaymentMethod(
43
            $request->attributes->get('token'),
44
            $request->attributes->get('paymentId'),
45
            $request->request->get('method')
46
        ));
47
48
        return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT));
49
    }
50
}
51