Passed
Pull Request — master (#80)
by
unknown
07:43 queued 03:32
created

RemoveWishlistAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 1
A __construct() 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\Entity\WishlistInterface;
14
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface;
15
use Doctrine\ORM\EntityManagerInterface;
16
use Symfony\Component\HttpFoundation\RedirectResponse;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
20
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
21
use Symfony\Contracts\Translation\TranslatorInterface;
22
23
final class RemoveWishlistAction
24
{
25
26
    private WishlistRepositoryInterface $wishlistRepository;
27
28
    private EntityManagerInterface $wishlistManager;
29
30
    private FlashBagInterface $flashBag;
31
32
    private TranslatorInterface $translator;
33
34
    private UrlGeneratorInterface $urlGenerator;
35
36
    public function __construct(
37
        WishlistRepositoryInterface $wishlistRepository,
38
        EntityManagerInterface $wishlistManager,
39
        FlashBagInterface $flashBag,
40
        TranslatorInterface $translator,
41
        UrlGeneratorInterface $urlGenerator
42
    ) {
43
        $this->wishlistRepository = $wishlistRepository;
44
        $this->wishlistManager = $wishlistManager;
45
        $this->urlGenerator = $urlGenerator;
46
        $this->flashBag = $flashBag;
47
        $this->translator = $translator;
48
    }
49
50
    public function __invoke(int $wishlistId, Request $request): Response
51
    {
52
        /** @var WishlistInterface $wishlist */
53
        $wishlist = $this->wishlistRepository->find($wishlistId);
54
55
        $this->wishlistManager->remove($wishlist);
56
        $this->wishlistManager->flush();
57
58
        $this->flashBag->add('success', $this->translator->trans('bitbag_sylius_wishlist_plugin.ui.remove_wishlist'));
59
60
        return new RedirectResponse($this->urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_wishlist_list_wishlists'));
61
    }
62
}