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

EmailAddressManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 27
ccs 0
cts 13
cp 0
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A verifyNewEmailAddress() 0 16 2
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