Passed
Push — feature/publishable ( 54a3e3...e9b8e1 )
by Daniel
23:16 queued 13:16
created

WelcomeEmailFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 10
cc 3
nc 3
nop 2
crap 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 Symfony\Component\Mime\RawMessage;
18
19
/**
20
 * @author Daniel West <[email protected]>
21
 */
22
final class WelcomeEmailFactory extends AbstractUserEmailFactory
23
{
24 8
    public function create(AbstractUser $user, array $context = []): ?RawMessage
25
    {
26 8
        if (!$this->enabled) {
27 1
            return null;
28
        }
29
30 7
        $this->initUser($user);
31
32 7
        $token = $user->getNewEmailVerificationToken();
33 7
        if ($token) {
34 2
            $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

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