ConfirmationTokenRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 45
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findByToken() 0 10 1
A findByUserAndType() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Users\Repository;
6
7
use App\Users\Entity\ConfirmationToken;
8
use App\Users\Entity\User;
9
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
10
use Symfony\Bridge\Doctrine\RegistryInterface;
11
12
/**
13
 * @method ConfirmationToken|null find($id, $lockMode = null, $lockVersion = null)
14
 * @method ConfirmationToken|null findOneBy(array $criteria, array $orderBy = null)
15
 * @method ConfirmationToken[]    findAll()
16
 * @method ConfirmationToken[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
17
 */
18
class ConfirmationTokenRepository extends ServiceEntityRepository
19
{
20 10
    public function __construct(RegistryInterface $registry)
21
    {
22 10
        parent::__construct($registry, ConfirmationToken::class);
23 10
    }
24
25
    /**
26
     * @param string $token
27
     *
28
     * @throws \Doctrine\ORM\NonUniqueResultException
29
     *
30
     * @return ConfirmationToken|null
31
     */
32 5
    public function findByToken(string $token): ?ConfirmationToken
33
    {
34 5
        return $this->createQueryBuilder('t')
35 5
            ->select('t')
36 5
            ->where('t.token = :token AND t.expires_at >= :now')
37 5
            ->setParameter('token', $token)
38 5
            ->setParameter('now', new \DateTime())
39 5
            ->getQuery()
40 5
            ->getOneOrNullResult();
41
    }
42
43
    /**
44
     * @param User   $user
45
     * @param string $type
46
     *
47
     * @throws \Doctrine\ORM\NonUniqueResultException
48
     *
49
     * @return ConfirmationToken|null
50
     */
51 1
    public function findByUserAndType(User $user, string $type): ?ConfirmationToken
52
    {
53 1
        return $this->createQueryBuilder('t')
54 1
            ->select('t')
55 1
            ->where('t.user = :user AND t.type = :type AND t.expires_at >= :now')
56 1
            ->setParameter('user', $user->getId())
57 1
            ->setParameter('type', $type)
58 1
            ->setParameter('now', new \DateTime())
59 1
            ->getQuery()
60 1
            ->getOneOrNullResult();
61
    }
62
}
63