Completed
Pull Request — master (#5)
by Valentyn
07:26
created

UserRepository::loadUserByToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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