Passed
Push — v2 ( 5fd3b3...d6a970 )
by Daniel
06:00 queued 44s
created

EmailAddressManager::verifyNewEmailAddress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 3
dl 0
loc 16
ccs 0
cts 9
cp 0
crap 6
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentBundle\Manager\User;
15
16
use Doctrine\ORM\EntityManagerInterface;
17
use Silverback\ApiComponentBundle\Repository\User\UserRepository;
18
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
19
20
/**
21
 * @author Daniel West <[email protected]>
22
 */
23
class EmailAddressManager
24
{
25
    private EntityManagerInterface $entityManager;
26
    private UserRepository $userRepository;
27
28
    public function __construct(EntityManagerInterface $entityManager, UserRepository $userRepository)
29
    {
30
        $this->entityManager = $entityManager;
31
        $this->userRepository = $userRepository;
32
    }
33
34
    public function verifyNewEmailAddress(string $username, string $email, string $token): void
35
    {
36
        $user = $this->userRepository->findOneByEmailVerificationToken(
37
            $username,
38
            $email,
39
            $token
40
        );
41
        if (!$user) {
42
            throw new NotFoundHttpException();
43
        }
44
45
        $user
46
            ->setEmailAddress($user->getNewEmailAddress())
47
            ->setNewEmailAddress(null)
48
            ->setEmailAddressVerified(true);
49
        $this->entityManager->flush();
50
    }
51
}
52