Completed
Push — queries ( 816141...e1f79b )
by Kamil
49:08 queued 26:57
created

Sender   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 67
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B send() 0 23 4
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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
namespace Sylius\Component\Mailer\Sender;
13
14
use Sylius\Component\Mailer\Provider\DefaultSettingsProviderInterface;
15
use Sylius\Component\Mailer\Provider\EmailProviderInterface;
16
use Sylius\Component\Mailer\Renderer\Adapter\AdapterInterface as RendererAdapterInterface;
17
use Sylius\Component\Mailer\Sender\Adapter\AdapterInterface as SenderAdapterInterface;
18
19
/**
20
 * @author Paweł Jędrzejewski <[email protected]>
21
 * @author Jérémy Leherpeur <[email protected]>
22
 * @author Gonzalo Vilaseca <[email protected]>
23
 */
24
final class Sender implements SenderInterface
25
{
26
    /**
27
     * @var RendererAdapterInterface
28
     */
29
    protected $rendererAdapter;
30
31
    /**
32
     * @var SenderAdapterInterface
33
     */
34
    protected $senderAdapter;
35
36
    /**
37
     * @var EmailProviderInterface
38
     */
39
    protected $provider;
40
41
    /**
42
     * @var DefaultSettingsProviderInterface
43
     */
44
    protected $defaultSettingsProvider;
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $defaultSettingsProvider exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
45
46
    /**
47
     * @param RendererAdapterInterface $rendererAdapter
48
     * @param SenderAdapterInterface $senderAdapter
49
     * @param EmailProviderInterface $provider
50
     * @param DefaultSettingsProviderInterface $defaultSettingsProvider
51
     */
52
    public function __construct(
53
        RendererAdapterInterface $rendererAdapter,
54
        SenderAdapterInterface $senderAdapter,
55
        EmailProviderInterface $provider,
56
        DefaultSettingsProviderInterface $defaultSettingsProvider
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $defaultSettingsProvider exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
57
    ) {
58
        $this->senderAdapter = $senderAdapter;
59
        $this->rendererAdapter = $rendererAdapter;
60
        $this->provider = $provider;
61
        $this->defaultSettingsProvider = $defaultSettingsProvider;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function send($code, array $recipients, array $data = [], array $attachments = [])
68
    {
69
        $email = $this->provider->getEmail($code);
70
71
        if (!$email->isEnabled()) {
72
            return;
73
        }
74
75
        $senderAddress = $email->getSenderAddress() ?: $this->defaultSettingsProvider->getSenderAddress();
76
        $senderName = $email->getSenderName() ?: $this->defaultSettingsProvider->getSenderName();
77
78
        $renderedEmail = $this->rendererAdapter->render($email, $data);
79
80
        $this->senderAdapter->send(
81
            $recipients,
82
            $senderAddress,
83
            $senderName,
84
            $renderedEmail,
85
            $email,
86
            $data,
87
            $attachments
88
        );
89
    }
90
}
91