Passed
Pull Request — feature/unit-tests (#37)
by Daniel
06: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 7
CRAP Score 3.0175

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 14
ccs 7
cts 8
cp 0.875
rs 10
c 1
b 0
f 0
cc 3
nc 3
nop 2
crap 3.0175
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 5
    public function create(AbstractUser $user, array $context = []): ?RawMessage
25
    {
26 5
        if (!$this->enabled) {
27
            return null;
28
        }
29
30 5
        $this->initUser($user);
31
32 5
        $token = $user->getNewEmailVerificationToken();
33 5
        if ($token) {
34 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\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 5
        return $this->createEmailMessage($context);
38
    }
39
40 5
    protected function getTemplate(): string
41
    {
42 5
        return 'user_welcome.html.twig';
43
    }
44
}
45