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

EmailConfirmationRepository::persist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
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
}