Passed
Push — feature/unit-tests ( e0ee05...a1a6df )
by Daniel
06:55 queued 34s
created

PasswordResetEmailFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 30
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getContextKeys() 0 4 1
A create() 0 16 3
A getTemplate() 0 3 1
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\Factory\Mailer\User;
15
16
use Silverback\ApiComponentBundle\Entity\User\AbstractUser;
17
use Silverback\ApiComponentBundle\Exception\InvalidArgumentException;
18
use Symfony\Component\Mime\RawMessage;
19
20
/**
21
 * @author Daniel West <[email protected]>
22
 */
23
final class PasswordResetEmailFactory extends AbstractUserEmailFactory
24
{
25 3
    public function create(AbstractUser $user, array $context = []): ?RawMessage
26
    {
27 3
        if (!$this->enabled) {
28 1
            return null;
29
        }
30
31 2
        $this->initUser($user);
32
33 2
        $token = $user->getNewPasswordConfirmationToken();
34 2
        if (!$token) {
35 1
            throw new InvalidArgumentException('A new password confirmation token must be set to send the `password reset` email');
36
        }
37
38 1
        $context['redirect_url'] = $this->getTokenUrl($token, $user->getUsername());
0 ignored issues
show
Bug introduced by
It seems like $user->getUsername() can also be of type null; however, parameter $username of Silverback\ApiComponentB...lFactory::getTokenUrl() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        $context['redirect_url'] = $this->getTokenUrl($token, /** @scrutinizer ignore-type */ $user->getUsername());
Loading history...
39
40 1
        return $this->createEmailMessage($context);
41
    }
42
43 1
    protected static function getContextKeys(): ?array
44
    {
45 1
        return array_merge(parent::getContextKeys(), [
46 1
            'redirect_url',
47
        ]);
48
    }
49
50 1
    protected function getTemplate(): string
51
    {
52 1
        return 'user_password_reset.html.twig';
53
    }
54
}
55