EmailAddressConfirmAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 27
ccs 0
cts 15
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 18 3
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components 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\ApiComponentsBundle\Action\User;
15
16
use Silverback\ApiComponentsBundle\Exception\InvalidArgumentException;
17
use Silverback\ApiComponentsBundle\Exception\UnexpectedValueException;
18
use Silverback\ApiComponentsBundle\Helper\User\EmailAddressManager;
19
use Symfony\Component\HttpFoundation\Response;
20
21
/**
22
 * @author Daniel West <[email protected]>
23
 */
24
class EmailAddressConfirmAction
25
{
26
    private EmailAddressManager $emailAddressManager;
27
28
    public function __construct(EmailAddressManager $emailAddressManager)
29
    {
30
        $this->emailAddressManager = $emailAddressManager;
31
    }
32
33
    public function __invoke(string $username, string $emailAddress, string $token): Response
34
    {
35
        try {
36
            $this->emailAddressManager->confirmNewEmailAddress($username, $emailAddress, $token);
37
        } catch (InvalidArgumentException $exception) {
38
            return new Response(null, Response::HTTP_NOT_FOUND);
39
        } catch (UnexpectedValueException $exception) {
40
            return new Response(null, Response::HTTP_UNAUTHORIZED);
41
        }
42
43
        $response = new Response(null, Response::HTTP_OK);
44
        $response->setCache([
45
            'private' => true,
46
            's_maxage' => 0,
47
            'max_age' => 0,
48
        ]);
49
50
        return $response;
51
    }
52
}
53