Completed
Push — master ( affb41...f007be )
by Rafał
09:54
created

TenantAwareMailer::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 2
nc 2
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher User Bundle.
7
 *
8
 * Copyright 2021 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @Copyright 2021 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\UserBundle\Mailer;
18
19
use SWP\Bundle\SettingsBundle\Manager\SettingsManagerInterface;
20
use SWP\Bundle\SettingsBundle\Model\SettingsOwnerInterface;
21
use SWP\Component\MultiTenancy\Context\TenantContextInterface;
22
use Symfony\Component\Mailer\MailerInterface as BaseMailerInterface;
23
24
class TenantAwareMailer extends Mailer
25
{
26
    public function __construct(
27
        BaseMailerInterface $mailer,
28
        array $parameters,
29
        SettingsManagerInterface $settingsManager,
30
        TenantContextInterface $tenantContext = null
31
    ) {
32
        $this->mailer = $mailer;
33
        $this->parameters = $parameters;
34
        $tenant = $tenantContext->getTenant();
0 ignored issues
show
Bug introduced by
It seems like $tenantContext is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
35
36
        if ($tenant instanceof SettingsOwnerInterface) {
37
            $fromEmail = ['contact@'.$tenant->getDomainName() => 'contact'];
38
39
            $this->parameters['confirmation.template'] =
40
                $settingsManager->get('registration_confirmation.template', 'tenant', $tenant);
41
            $this->parameters['from_email']['confirmation'] =
42
                $settingsManager->get('registration_from_email.confirmation', 'tenant', $tenant, $fromEmail);
43
            $this->parameters['resetting.template'] =
44
                $settingsManager->get('registration_resetting.template', 'tenant', $tenant);
45
            $this->parameters['from_email']['resetting'] =
46
                $settingsManager->get('registration_from_email.resetting', 'tenant', $tenant, $fromEmail);
47
        }
48
    }
49
}
50