Passed
Pull Request — feature/unit-tests (#37)
by Daniel
05:46
created

ChangeEmailVerificationEmailFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequiredContextKeys() 0 4 1
A getTemplate() 0 3 1
A create() 0 16 3
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
class ChangeEmailVerificationEmailFactory extends AbstractUserEmailFactory
24
{
25
    public function create(AbstractUser $user, array $context = []): ?RawMessage
26
    {
27
        if (!$this->enabled) {
28
            return null;
29
        }
30
31
        $this->initUser($user);
32
33
        $token = $user->getNewEmailVerificationToken();
34
        if (!$token) {
35
            throw new InvalidArgumentException('A new email address verification token must be set to send the verification email');
36
        }
37
38
        $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
        return $this->createEmailMessage($context);
41
    }
42
43
    protected static function getRequiredContextKeys(): ?array
44
    {
45
        return array_merge(parent::getRequiredContextKeys(), [
46
            'redirect_url',
47
        ]);
48
    }
49
50
    protected function getTemplate(): string
51
    {
52
        return 'user_change_email_verification.html.twig';
53
    }
54
}
55