Completed
Push — master ( 9f5cd7...5bc6c3 )
by Mikołaj
01:50
created

ClearCookieWishlistItemsListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onInteractiveLogin() 0 10 2
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusWishlistPlugin\EventListener;
14
15
use Sylius\Component\Core\Model\ShopUserInterface;
16
use Sylius\Component\Resource\Storage\StorageInterface;
17
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
18
19
final class ClearCookieWishlistItemsListener
20
{
21
    /** @var StorageInterface */
22
    private $cookieStorage;
23
24
    /** @var string */
25
    private $wishlistCookieToken;
26
27
    public function __construct(StorageInterface $cookieStorage, string $wishlistCookieToken)
28
    {
29
        $this->cookieStorage = $cookieStorage;
30
        $this->wishlistCookieToken = $wishlistCookieToken;
31
    }
32
33
    public function onInteractiveLogin(InteractiveLoginEvent $interactiveLoginEvent): void
34
    {
35
        $user = $interactiveLoginEvent->getAuthenticationToken()->getUser();
36
37
        if (!$user instanceof ShopUserInterface) {
38
            return;
39
        }
40
41
        $this->cookieStorage->set($this->wishlistCookieToken, null);
42
    }
43
}
44