Completed
Pull Request — master (#5)
by Valentyn
02:55
created

UserRepository::findUserByUsername()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
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
//    /**
25
//     * @return User[] Returns an array of User objects
26
//     */
27
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
    public function findByExampleField($value)
29
    {
30
        return $this->createQueryBuilder('u')
31
            ->andWhere('u.exampleField = :val')
32
            ->setParameter('val', $value)
33
            ->orderBy('u.id', 'ASC')
34
            ->setMaxResults(10)
35
            ->getQuery()
36
            ->getResult()
37
        ;
38
    }
39
    */
40
41
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
    public function findOneBySomeField($value): ?User
43
    {
44
        return $this->createQueryBuilder('u')
45
            ->andWhere('u.exampleField = :val')
46
            ->setParameter('val', $value)
47
            ->getQuery()
48
            ->getOneOrNullResult()
49
        ;
50
    }
51
    */
52
53
    public function findUserByUsername($username)
54
    {
55
        return $this->createQueryBuilder('u')
56
            ->where('u.username = :username OR u.email = :email')
57
            ->setParameter('username', $username)
58
            ->setParameter('email', $username)
59
            ->getQuery()
60
            ->getOneOrNullResult();
61
    }
62
63
    public function loadUserByUsername($username)
64
    {
65
        return $this->createQueryBuilder('u')
66
            ->where('u.username = :username OR u.email = :email')
67
            ->setParameter('username', $username)
68
            ->setParameter('email', $username)
69
            ->getQuery()
70
            ->getOneOrNullResult();
71
    }
72
73
    public function loadUserByToken(string $token)
74
    {
75
        return $this->createQueryBuilder('u')
76
            ->where('u.apiKey = :token')
77
            ->setParameter('token', $token)
78
            ->getQuery()
79
            ->getOneOrNullResult();
80
    }
81
}
82