ListWishlistProductsAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A __invoke() 0 15 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\Context\WishlistContextInterface;
14
use BitBag\SyliusWishlistPlugin\Form\Type\WishlistCollectionType;
15
use BitBag\SyliusWishlistPlugin\Processor\WishlistCommandProcessorInterface;
16
use Sylius\Component\Order\Context\CartContextInterface;
17
use Symfony\Component\Form\FormFactoryInterface;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpFoundation\Response;
20
use Twig\Environment;
21
22
final class ListWishlistProductsAction
23
{
24
    private WishlistContextInterface $wishlistContext;
25
26
    private CartContextInterface $cartContext;
27
28
    private FormFactoryInterface $formFactory;
29
30
    private Environment $twigEnvironment;
31
32
    private WishlistCommandProcessorInterface $wishlistCommandProcessor;
33
34
    public function __construct(
35
        WishlistContextInterface $wishlistContext,
36
        CartContextInterface $cartContext,
37
        FormFactoryInterface $formFactory,
38
        Environment $twigEnvironment,
39
        WishlistCommandProcessorInterface $wishlistCommandProcessor
40
    ) {
41
        $this->wishlistContext = $wishlistContext;
42
        $this->cartContext = $cartContext;
43
        $this->formFactory = $formFactory;
44
        $this->twigEnvironment = $twigEnvironment;
45
        $this->wishlistCommandProcessor = $wishlistCommandProcessor;
46
    }
47
48
    public function __invoke(Request $request): Response
49
    {
50
        $wishlist = $this->wishlistContext->getWishlist($request);
51
        $cart = $this->cartContext->getCart();
52
53
        $commandsArray = $this->wishlistCommandProcessor->createAddCommandCollectionFromWishlistProducts($wishlist->getWishlistProducts());
54
55
        $form = $this->formFactory->create(WishlistCollectionType::class, ['items' => $commandsArray], [
56
            'cart' => $cart,
57
        ]);
58
59
        return new Response(
60
            $this->twigEnvironment->render('@BitBagSyliusWishlistPlugin/WishlistDetails/index.html.twig', [
61
                'wishlist' => $wishlist,
62
                'form' => $form->createView(),
63
            ])
64
        );
65
    }
66
}
67