AuthenticationSuccessHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleAuthenticationSuccess() 0 21 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.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusVueStorefrontPlugin\Authentication;
14
15
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
16
use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationSuccessResponse;
17
use Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler as BaseAuthenticationSuccessHandler;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\Security\Core\User\UserInterface;
20
21
final class AuthenticationSuccessHandler extends BaseAuthenticationSuccessHandler
22
{
23
    public function handleAuthenticationSuccess(UserInterface $user, $jwt = null): JWTAuthenticationSuccessResponse
24
    {
25
        if (null === $jwt) {
26
            $jwt = $this->jwtManager->create($user);
27
        }
28
29
        $response = new JWTAuthenticationSuccessResponse($jwt);
30
31
        $event = new AuthenticationSuccessEvent(
32
            [
33
                'result' => $jwt,
34
                'code' => Response::HTTP_OK,
35
            ],
36
            $user,
37
            $response
38
        );
39
40
        $this->dispatcher->dispatch($event);
41
42
        return $response->setData($event->getData());
43
    }
44
}
45