-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEmailVerificationTokenRepository.php
More file actions
34 lines (28 loc) · 1.06 KB
/
EmailVerificationTokenRepository.php
File metadata and controls
34 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace MatchBot\Domain;
use Doctrine\ORM\EntityManagerInterface;
class EmailVerificationTokenRepository
{
/**
* @psalm-suppress PossiblyUnusedMethod - called by DI container.
*/
public function __construct(private EntityManagerInterface $em)
{
}
public function findRecentTokenForEmailAddress(EmailAddress $emailAddress, \DateTimeImmutable $at): ?EmailVerificationToken
{
$emailVerificationToken = $this->em->createQuery(
dql: <<<'DQL'
SELECT t FROM MatchBot\Domain\EmailVerificationToken t
WHERE t.emailAddress = :email
AND t.createdAt > :created_since
ORDER BY t.createdAt DESC
DQL
)->setParameters([
'email' => $emailAddress->email,
'created_since' => $at->sub(new \DateInterval('PT8H')),
])->setMaxResults(1)->getOneOrNullResult();
\assert(is_null($emailVerificationToken) || $emailVerificationToken instanceof EmailVerificationToken);
return $emailVerificationToken;
}
}