Completed
Push — master ( febf2b...b3372e )
by Valery
13:12 queued 13:12
created

EmailVerifier   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 22
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleEmailConfirmation() 0 8 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service\Auth;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\Security\Core\User\UserInterface;
10
use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
11
use SymfonyCasts\Bundle\VerifyEmail\VerifyEmailHelperInterface;
12
13
final class EmailVerifier
14
{
15
    private VerifyEmailHelperInterface $verifyEmailHelper;
16
    private EntityManagerInterface $entityManager;
17
18
    public function __construct(VerifyEmailHelperInterface $helper, EntityManagerInterface $manager)
19
    {
20
        $this->verifyEmailHelper = $helper;
21
        $this->entityManager = $manager;
22
    }
23
24
    /**
25
     * @throws VerifyEmailExceptionInterface
26
     */
27
    public function handleEmailConfirmation(Request $request, UserInterface $user): void
28
    {
29
        $this->verifyEmailHelper->validateEmailConfirmation($request->getUri(), (string) $user->getId(), $user->getEmail());
30
31
        $user->setEmailVerifiedAt(new \DateTime('now'));
32
33
        $this->entityManager->persist($user);
34
        $this->entityManager->flush();
35
    }
36
}
37