Passed
Pull Request — master (#81)
by
unknown
04:43
created

CreateNewWishlistAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 20
c 5
b 0
f 0
dl 0
loc 42
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A __invoke() 0 12 1
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusWishlistPlugin\Controller\Action;
12
13
use BitBag\SyliusWishlistPlugin\Command\Wishlist\CreateNewWishlist;
14
use Symfony\Component\Form\FormFactoryInterface;
15
use Symfony\Component\HttpFoundation\JsonResponse;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
19
use Symfony\Component\Messenger\MessageBusInterface;
20
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
21
use Symfony\Contracts\Translation\TranslatorInterface;
22
use Twig\Environment;
23
24
final class CreateNewWishlistAction
25
{
26
    private FormFactoryInterface $formFactory;
27
28
    private MessageBusInterface $commandBus;
29
30
    private Environment $twigEnvironment;
31
32
    private FlashBagInterface $flashBag;
33
34
    private TranslatorInterface $translator;
35
36
    private UrlGeneratorInterface $urlGenerator;
37
38
    public function __construct(
39
        FormFactoryInterface $formFactory,
40
        MessageBusInterface $commandBus,
41
        Environment $twigEnvironment,
42
        FlashBagInterface $flashBag,
43
        TranslatorInterface $translator,
44
        UrlGeneratorInterface $urlGenerator
45
    ) {
46
        $this->formFactory = $formFactory;
47
        $this->commandBus = $commandBus;
48
        $this->twigEnvironment = $twigEnvironment;
49
        $this->flashBag = $flashBag;
50
        $this->translator = $translator;
51
        $this->urlGenerator = $urlGenerator;
52
    }
53
54
    public function __invoke(Request $request): Response
55
    {
56
        $wishlistName = $request->request->get('create_new_wishlist')['name'];
57
        $createNewWishlist = new CreateNewWishlist($wishlistName);
58
        $this->commandBus->dispatch($createNewWishlist);
59
60
        $this->flashBag->add(
61
            'success',
62
            $this->translator->trans('bitbag_sylius_wishlist_plugin.ui.create_new_wishlist')
63
        );
64
65
        return new JsonResponse();
66
    }
67
}
68