<commit_before><?php
declare(strict_types = 1);
/**
 * /src/Security/SecurityUserFactory.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace App\Security;

use App\Entity\User;
use App\Repository\UserRepository;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Throwable;
use function get_class;

/**
 * Class SecurityUserFactory
 *
 * @package App\Security
 * @author  TLe, <NAME> <<EMAIL>>
 */
class SecurityUserFactory implements UserProviderInterface
{
    /**
     * @var UserRepository
     */
    private $userRepository;

    /**
     * @var RolesService
     */
    private $rolesService;

    /**
     * SecurityUserFactory constructor.
     *
     * @param UserRepository $userRepository
     * @param RolesService   $rolesService
     */
    public function __construct(UserRepository $userRepository, RolesService $rolesService)
    {
        $this->userRepository = $userRepository;
        $this->rolesService = $rolesService;
    }

    /**
     * Loads the user for the given username.
     *
     * This method must return null if the user is not found.
     *
     * @param string $username The username
     *
     * @return UserInterface|null
     *
     * @throws Throwable
     */
    public function loadUserByUsername($username): ?UserInterface
    {
        $user = $this->userRepository->loadUserByUsername($username);

        if (!($user instanceof User)) {
            throw new UsernameNotFoundException(sprintf('User not found for UUID: "%s".', $username));
        }

        return (new SecurityUser($user))->setRoles($this->rolesService->getInheritedRoles($user->getRoles()));
    }

    /**
     * @inheritDoc
     */
    public function supportsClass($class): bool<commit_msg>tests: Fixed psalm errors<commit_after><?php
declare(strict_types = 1);
/**
 * /src/Security/SecurityUserFactory.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace App\Security;

use App\Entity\User;
use App\Repository\UserRepository;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Throwable;
use function get_class;

/**
 * Class SecurityUserFactory
 *
 * @package App\Security
 * @author  TLe, <NAME> <<EMAIL>>
 */
class SecurityUserFactory implements UserProviderInterface
{
    /**
     * @var UserRepository
     */
    private $userRepository;

    /**
     * @var RolesService
     */
    private $rolesService;

    /**
     * SecurityUserFactory constructor.
     *
     * @param UserRepository $userRepository
     * @param RolesService   $rolesService
     */
    public function __construct(UserRepository $userRepository, RolesService $rolesService)
    {
        $this->userRepository = $userRepository;
        $this->rolesService = $rolesService;
    }

    /**
     * Loads the user for the given username.
     *
     * This method must return null if the user is not found.
     *
     * @param string $username The username
     *
     * @return UserInterface
     *
     * @throws Throwable
     */
    public function loadUserByUsername($username): UserInterface
    {
        $user = $this->userRepository->loadUserByUsername($username);

        if (!($user instanceof User)) {
            throw new UsernameNotFoundException(sprintf('User not found for UUID: "%s".', $username));
        }

        return (new SecurityUser($user))->setRoles($this->rolesService->getInheritedRoles($user->getRoles()));
    }

    /**
     * @inheritDoc
     */
    public function supportsClass($class): bool
{'fraction_non_alphanumeric': 0.11732851985559567, 'fraction_numerical': 0.0005157297576070139, 'mean_word_length': 3.162017167381974, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 31, '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': '2747720', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1086, 'n_words': 240}