Total Complexity | 5 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
23 | final class PasswordResetEmailFactory extends AbstractUserEmailFactory |
||
24 | { |
||
25 | public const MESSAGE_ID_PREFIX = 'pre'; |
||
26 | |||
27 | 3 | public function create(AbstractUser $user, array $context = []): ?RawMessage |
|
28 | { |
||
29 | 3 | if (!$this->enabled) { |
|
30 | 1 | return null; |
|
31 | } |
||
32 | |||
33 | 2 | $this->initUser($user); |
|
34 | |||
35 | 2 | $token = $user->plainNewPasswordConfirmationToken; |
|
36 | 2 | $user->plainNewPasswordConfirmationToken = null; |
|
37 | 2 | if (!$token) { |
|
38 | 1 | throw new InvalidArgumentException('A new password confirmation token must be set to send the `password reset` email'); |
|
39 | } |
||
40 | |||
41 | 1 | $context['redirect_url'] = $this->getTokenUrl($token, $user->getUsername()); |
|
|
|||
42 | |||
43 | 1 | return $this->createEmailMessage($context); |
|
44 | } |
||
45 | |||
46 | 1 | protected static function getContextKeys(): ?array |
|
47 | { |
||
48 | 1 | return array_merge(parent::getContextKeys(), [ |
|
49 | 1 | 'redirect_url', |
|
50 | ]); |
||
51 | } |
||
52 | |||
53 | 1 | protected function getTemplate(): string |
|
56 | } |
||
57 | } |
||
58 |