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

WelcomeEmailFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTemplate() 0 3 1
A create() 0 14 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