src/UserProvider/SymfonyTokenStorageUserProvider.php
public function getUser(): UserInterface
    {
        $token = $this->tokenStorage->getToken();

        if (!$token) {
            throw new AccessDeniedException('The token was not found.');
        }

        $user = $token->getUser();

        if (!$user || !$user instanceof UserInterface) {
            throw new AccessDeniedException('The user is invalid.');
        }

        return $user;
    }
public function getUser(): UserInterface
    {
        $token = $this->tokenStorage->getToken();

        if (!$token) {
            throw new AccessDeniedException('The token was not found.');
        }

        $user = $token->getUser();

        if (!$user || !$user instanceof UserInterface) {
            throw new AccessDeniedException('The user is invalid.');
        }

        return $user;
    }
{@inheritdoc}