Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ConfirmEmailChangeAction
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Auth;
6
7use App\Domain\Auth\Service\EmailChangeService;
8use App\Renderer\JsonRenderer;
9use App\Support\Row;
10use Psr\Http\Message\ResponseInterface;
11use Psr\Http\Message\ServerRequestInterface;
12
13/**
14 * POST /api/auth/change-email/confirm
15 *
16 * FSC-86: consumes the verification token emailed to the new address and
17 * applies the change to both the login and profile records. Public (token is
18 * the credential) — the link may be opened in any browser session.
19 *
20 * Body: { token }
21 */
22final readonly class ConfirmEmailChangeAction
23{
24    public function __construct(
25        private EmailChangeService $emailChangeService,
26        private JsonRenderer $renderer,
27    ) {}
28
29    public function __invoke(
30        ServerRequestInterface $request,
31        ResponseInterface $response,
32    ): ResponseInterface {
33        $data = (array)$request->getParsedBody();
34        $token = Row::nullableString($data, 'token') ?? '';
35
36        $this->emailChangeService->confirmChange($token);
37
38        return $this->renderer->json($response, [
39            'success' => true,
40            'message' => 'Your email address has been updated.',
41        ]);
42    }
43}