ClearCookieWishlistItemsListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onInteractiveLogin() 0 9 2
A __construct() 0 4 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\EventListener;
12
13
use Sylius\Component\Core\Model\ShopUserInterface;
14
use Sylius\Component\Resource\Storage\StorageInterface;
15
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
16
17
final class ClearCookieWishlistItemsListener
18
{
19
    private StorageInterface $cookieStorage;
20
21
    private string $wishlistCookieToken;
22
23
    public function __construct(StorageInterface $cookieStorage, string $wishlistCookieToken)
24
    {
25
        $this->cookieStorage = $cookieStorage;
26
        $this->wishlistCookieToken = $wishlistCookieToken;
27
    }
28
29
    public function onInteractiveLogin(InteractiveLoginEvent $interactiveLoginEvent): void
30
    {
31
        $user = $interactiveLoginEvent->getAuthenticationToken()->getUser();
32
33
        if (!$user instanceof ShopUserInterface) {
34
            return;
35
        }
36
37
        $this->cookieStorage->set($this->wishlistCookieToken, null);
38
    }
39
}
40