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

use App\Entity\User as Entity;
use Doctrine\ORM\QueryBuilder;
use function array_key_exists;
use function getenv;

/**
 * Trait LoadUserByUserNameTrait
 *
 * @package App\Repository\Traits
 * @author  TLe, <NAME> <<EMAIL>>
 *
 * @method QueryBuilder createQueryBuilder(string $alias = null, string $indexBy = null): QueryBuilder
 */
trait LoadUserByUserNameTrait
{
    /**
     * Loads the user for the given username.
     *
     * This method must throw UsernameNotFoundException if the user is not found.
     *
     * Method is override for performance reasons see link below.
     *
     * @link http://symfony2-document.readthedocs.org/en/latest/cookbook/security/entity_provider.html
     *       #managing-roles-in-the-database
     *
     * @psalm-suppress ImplementedReturnTypeMismatch
     *
     * @param string $username The username
     *
     * @return Entity|null
     *
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function loadUserByUsername($username): ?Entity
    {
        static $cache = [];

        if (!array_key_exists($username, $cache) && getenv('APP_ENV') !== 'test') {
            // Build query
            $query = $this
                ->createQueryBuilder('u')
                ->select('u, g, r')
                ->leftJoin('u.userGroups', 'g')
                ->leftJoin('g.role', 'r')
                ->where('u.username = :username OR u.email = :email')
                ->setParameter('username', $username)
                ->setParameter('email', $username)
                ->getQuery();
<commit_msg>refactor: Fixed logic error<commit_after><?php
declare(strict_types = 1);
/**
 * /src/Repository/Traits/LoadUserByUserNameTrait.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace App\Repository\Traits;

use App\Entity\User as Entity;
use Doctrine\ORM\QueryBuilder;
use function array_key_exists;
use function getenv;

/**
 * Trait LoadUserByUserNameTrait
 *
 * @package App\Repository\Traits
 * @author  TLe, <NAME> <<EMAIL>>
 *
 * @method QueryBuilder createQueryBuilder(string $alias = null, string $indexBy = null): QueryBuilder
 */
trait LoadUserByUserNameTrait
{
    /**
     * Loads the user for the given username.
     *
     * This method must throw UsernameNotFoundException if the user is not found.
     *
     * Method is override for performance reasons see link below.
     *
     * @link http://symfony2-document.readthedocs.org/en/latest/cookbook/security/entity_provider.html
     *       #managing-roles-in-the-database
     *
     * @psalm-suppress ImplementedReturnTypeMismatch
     *
     * @param string $username The username
     *
     * @return Entity|null
     *
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function loadUserByUsername($username): ?Entity
    {
        static $cache = [];

        if (!array_key_exists($username, $cache) || getenv('APP_ENV') === 'test') {
            // Build query
            $query = $this
                ->createQueryBuilder('u')
                ->select('u, g, r')
                ->leftJoin('u.userGroups', 'g')
                ->leftJoin('g.role', 'r')
                ->where('u.username = :username OR u.email = :email')
                ->setParameter('username', $username)
                ->setParameter('email', $username)
                ->getQuery();

{'fraction_non_alphanumeric': 0.1301994301994302, 'fraction_numerical': 0.0011396011396011395, 'mean_word_length': 2.4831349206349205, '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': '1454552', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1031, 'n_words': 233}