Completed
Pull Request — master (#79)
by Valery
09:07 queued 09:07
created

EmailVerifier::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
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());
2 ignored issues
show
Bug introduced by
The method getEmail() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as App\Entity\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $this->verifyEmailHelper->validateEmailConfirmation($request->getUri(), (string) $user->getId(), $user->/** @scrutinizer ignore-call */ getEmail());
Loading history...
Bug introduced by
The method getId() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as App\Entity\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $this->verifyEmailHelper->validateEmailConfirmation($request->getUri(), (string) $user->/** @scrutinizer ignore-call */ getId(), $user->getEmail());
Loading history...
30
31
        $user->setEmailVerifiedAt(new \DateTime('now'));
1 ignored issue
show
Bug introduced by
The method setEmailVerifiedAt() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as App\Entity\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        $user->/** @scrutinizer ignore-call */ 
32
               setEmailVerifiedAt(new \DateTime('now'));
Loading history...
32
33
        $this->entityManager->persist($user);
34
        $this->entityManager->flush();
35
    }
36
}
37