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

AddCouponAction::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
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