Completed
Push — master ( f92548...5447f3 )
by Marcel
03:46
created

EmailConfirmationRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 43
ccs 0
cts 28
cp 0
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 3 1
A findOneByUser() 0 5 1
A findOneByToken() 0 5 1
A removeExpired() 0 7 1
A __construct() 0 2 1
A persist() 0 3 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\EmailConfirmation;
6
use App\Entity\User;
7
use DateTime;
8
use Doctrine\ORM\EntityManagerInterface;
9
10
class EmailConfirmationRepository implements EmailConfirmationRepositoryInterface {
11
    private $em;
12
13
    public function __construct(EntityManagerInterface $em) {
14
        $this->em = $em;
15
    }
16
17
    public function findOneByToken(string $token): ?EmailConfirmation {
18
        return $this->em
19
            ->getRepository(EmailConfirmation::class)
20
            ->findOneBy([
21
                'token' => $token
22
            ]);
23
    }
24
25
    public function findOneByUser(User $user): ?EmailConfirmation {
26
        return $this->em
27
            ->getRepository(EmailConfirmation::class)
28
            ->findOneBy([
29
                'user' => $user
30
            ]);
31
    }
32
33
    public function persist(EmailConfirmation $confirmation): void {
34
        $this->em->persist($confirmation);
35
        $this->em->flush();
36
    }
37
38
    public function remove(EmailConfirmation $confirmation): void {
39
        $this->em->remove($confirmation);
40
        $this->em->flush();
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    public function removeExpired(DateTime $dateTime): int {
47
        return $this->em->createQueryBuilder()
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->em->create...->getQuery()->execute() could return the type array which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
48
            ->delete(EmailConfirmation::class, 'c')
49
            ->where('c.validUntil < :threshold')
50
            ->setParameter('threshold', $dateTime)
51
            ->getQuery()
52
            ->execute();
53
    }
54
}