<commit_before><?php

namespace DoS\UserBundle\OAuth;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use DoS\UserBundle\Model\UserInterface;

class Security
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * @return TokenStorageInterface
     */
    private function getStorage()
    {
        return $this->container->get('security.token_storage');
    }

    /**
     * @return AuthorizationCheckerInterface
     */
    private function getAuthenChecker()
    {
        return $this->container->get('security.authorization_checker');
    }

    /**
     * @return null|TokenInterface
     */
    public function getToken()
    {
        return $this->getStorage()->getToken();
    }

    /**
     * @return string|void
     */
    public function getUsername()
    {
        $token = $this->getToken();

        if ($token instanceof TokenInterface) {
            return $token->getUsername();
        }

        return;
    }

    /**
     * @return UserInterface|void
     */
    public function getUser()
    {
        $token = $this->getToken();

        if ($token instanceof TokenInterface) {
            return $token->getUser();
        }

        return;
    }

    /**
     * @param      $attributes
     * @param null $object
     *
     * @return bool
     */
    public function isGranted($attributes, $object = null)
    {
        return $this->getAuthenChecker()->isGranted($attributes, $object);
    }
}
<commit_msg>fixbug: return only logged user.<commit_after><?php

namespace DoS\UserBundle\OAuth;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use DoS\UserBundle\Model\UserInterface;

class Security
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * @return TokenStorageInterface
     */
    private function getStorage()
    {
        return $this->container->get('security.token_storage');
    }

    /**
     * @return AuthorizationCheckerInterface
     */
    private function getAuthenChecker()
    {
        return $this->container->get('security.authorization_checker');
    }

    /**
     * @return null|TokenInterface
     */
    public function getToken()
    {
        return $this->getStorage()->getToken();
    }

    /**
     * @return string|void
     */
    public function getUsername()
    {
        $token = $this->getToken();

        if ($token instanceof TokenInterface) {
            return $token->getUsername();
        }

        return;
    }

    /**
     * @return UserInterface|void
     */
    public function getUser()
    {
        $token = $this->getToken();

        if ($token instanceof TokenInterface && $token->isAuthenticated()) {
            return $token->getUser();
        }

        return;
    }

    /**
     * @param      $attributes
     * @param null $object
     *
     * @return bool
     */
    public function isGranted($attributes, $object = null)
    {
        return $this->getAuthenChecker()->isGranted($attributes, $object);
    }
}

{'fraction_non_alphanumeric': 0.12212720470336719, 'fraction_numerical': 0.0, 'mean_word_length': 2.4370982552800733, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7512780', 'n_tokens_mistral': 1027, 'n_tokens_neox': 1014, 'n_words': 183}