Test Failed
Pull Request — feature/unit-tests (#37)
by Daniel
05:24
created

WelcomeEmailFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

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
class WelcomeEmailFactory extends AbstractUserEmailFactory
23
{
24
    public function create(AbstractUser $user, array $context = []): ?RawMessage
25
    {
26
        if (!$this->enabled) {
27
            return null;
28
        }
29
30
        $this->initUser($user);
31
32
        $token = $user->getNewEmailVerificationToken();
33
        if ($token) {
34
            $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
        return $this->createEmailMessage($context);
38
    }
39
40
    protected function getTemplate(): string
41
    {
42
        return 'user_welcome.html.twig';
43
    }
44
}
45