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

onInteractiveLogin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
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