EmailAddressConfirmAction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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