Passed
Pull Request — master (#72)
by Daniel
05:33
created

WelcomeEmailFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 2
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 3
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\Factory\User\Mailer;
15
16
use Silverback\ApiComponentsBundle\Entity\User\AbstractUser;
17
use Symfony\Component\Mime\RawMessage;
18
19
/**
20
 * @author Daniel West <[email protected]>
21
 */
22
final class WelcomeEmailFactory extends AbstractUserEmailFactory
23
{
24
    public const MESSAGE_ID_PREFIX = 'wef';
25
26 3
    public function create(AbstractUser $user, array $context = []): ?RawMessage
27
    {
28 3
        if (!$this->enabled) {
29 1
            return null;
30
        }
31
32 2
        $this->initUser($user);
33
34 2
        $token = $user->plainEmailAddressVerifyToken;
35 2
        $user->plainEmailAddressVerifyToken = null;
36 2
        if ($token) {
37 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\ApiComponents...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

37
            $context['redirect_url'] = $this->getTokenUrl($token, /** @scrutinizer ignore-type */ $user->getUsername());
Loading history...
38
        }
39
40 2
        return $this->createEmailMessage($context);
41
    }
42
43 2
    protected function getTemplate(): string
44
    {
45 2
        return 'user_welcome.html.twig';
46
    }
47
}
48