Completed
Push — master ( 15189e...f90573 )
by Valentyn
13s
created

UserRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace App\Users\Repository;
5
6
use App\Users\Entity\User;
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Symfony\Bridge\Doctrine\RegistryInterface;
9
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
10
use Symfony\Component\Security\Core\User\UserInterface;
11
12
/**
13
 * @method User|null find($id, $lockMode = null, $lockVersion = null)
14
 * @method User|null findOneBy(array $criteria, array $orderBy = null)
15
 * @method User[]    findAll()
16
 * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
17
 */
18
class UserRepository extends ServiceEntityRepository implements UserLoaderInterface
19
{
20 26
    public function __construct(RegistryInterface $registry)
21
    {
22 26
        parent::__construct($registry, User::class);
23 26
    }
24
25 7
    public function loadUserByUsername($username): ?User
26
    {
27 7
        return $this->createQueryBuilder('u')
28 7
            ->where('u.username = :username OR u.email = :email')
29 7
            ->setParameter('username', $username)
30 7
            ->setParameter('email', $username)
31 7
            ->getQuery()
32 7
            ->getOneOrNullResult();
33
    }
34
}
35