Passed
Pull Request — master (#81)
by
unknown
03:58
created

CreateNewWishlistAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 15
c 3
b 0
f 0
dl 0
loc 32
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A __invoke() 0 10 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 BitBag\SyliusWishlistPlugin\Factory\WishlistFactoryInterface;
15
use Symfony\Component\Form\FormFactoryInterface;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\Messenger\MessageBusInterface;
19
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
20
21
final class CreateNewWishlistAction
22
{
23
    private TokenStorageInterface $tokenStorage;
24
25
    private WishlistFactoryInterface $wishlistFactory;
26
27
    private FormFactoryInterface $formFactory;
28
29
    private MessageBusInterface $commandBus;
30
31
    public function __construct(
32
        TokenStorageInterface $tokenStorage,
33
        WishlistFactoryInterface $wishlistFactory,
34
        FormFactoryInterface $formFactory,
35
        MessageBusInterface $commandBus
36
    ) {
37
        $this->tokenStorage = $tokenStorage;
38
        $this->wishlistFactory = $wishlistFactory;
39
        $this->formFactory = $formFactory;
40
        $this->commandBus = $commandBus;
41
    }
42
43
    public function __invoke(Request $request): Response
44
    {
45
        $token = $this->tokenStorage;
46
        $wishlist = $this->wishlistFactory;
47
        $form = $this->formFactory;
48
49
        $createNewWishlist = new CreateNewWishlist($token, $wishlist, $form);
50
        $this->commandBus->dispatch($createNewWishlist);
51
52
        return new Response('success');
53
    }
54
}
55