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

CleanWishlistAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A __invoke() 0 13 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 CleanWishlistAction
24
{
25
    private WishlistRepositoryInterface $wishlistRepository;
26
27
    private EntityManagerInterface $wishlistManager;
28
29
    private FlashBagInterface $flashBag;
30
31
    private TranslatorInterface $translator;
32
33
    private UrlGeneratorInterface $urlGenerator;
34
35
    public function __construct(
36
        WishlistRepositoryInterface $wishlistRepository,
37
        EntityManagerInterface $wishlistManager,
38
        FlashBagInterface $flashBag,
39
        TranslatorInterface $translator,
40
        UrlGeneratorInterface $urlGenerator
41
    ) {
42
        $this->wishlistRepository = $wishlistRepository;
43
        $this->wishlistManager = $wishlistManager;
44
        $this->urlGenerator = $urlGenerator;
45
        $this->flashBag = $flashBag;
46
        $this->translator = $translator;
47
    }
48
49
    public function __invoke(int $wishlistId, Request $request): Response
50
    {
51
        /** @var WishlistInterface $wishlist */
52
        $wishlist = $this->wishlistRepository->find($wishlistId);
53
54
        $wishlist->clear();
0 ignored issues
show
Bug introduced by
The method clear() does not exist on BitBag\SyliusWishlistPlu...ntity\WishlistInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to BitBag\SyliusWishlistPlu...ntity\WishlistInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $wishlist->/** @scrutinizer ignore-call */ 
55
                   clear();
Loading history...
55
        $this->wishlistManager->flush();
56
57
        $this->flashBag->add('success', $this->translator->trans('bitbag_sylius_wishlist_plugin.ui.clear_wishlist'));
58
59
        return new RedirectResponse(
60
            $this->urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_wishlist_show_chosen_wishlist', [
61
                'wishlistId' => $wishlistId,
62
            ])
63
        );
64
    }
65
}
66