MandrillUserMailer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorUser\MandrillBridge\Infrastructure\Mailing;
14
15
use BenGorUser\User\Domain\Model\UserEmail;
16
use BenGorUser\User\Domain\Model\UserMailable;
17
use BenGorUser\User\Domain\Model\UserMailer;
18
19
/**
20
 * Mandrill user mailer class.
21
 *
22
 * @author Beñat Espiña <[email protected]>
23
 * @author Gorka Laucirica <[email protected]>
24
 */
25
final class MandrillUserMailer implements UserMailer
26
{
27
    /**
28
     * The mandrill instance.
29
     *
30
     * @var \Mandrill
31
     */
32
    private $mandrill;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param \Mandrill $mandrill The mandrill instance
38
     */
39
    public function __construct(\Mandrill $mandrill)
40
    {
41
        $this->mandrill = $mandrill;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function mail(UserMailable $mail)
48
    {
49
        if (is_array($mail->to())) {
50
            $to = array_map(function (UserEmail $receiver) {
51
                return $receiver->email();
52
            }, $mail->to());
53
        } else {
54
            $to = $mail->to()->email();
55
        }
56
57
        $message = [
58
            'subject'             => $mail->subject(),
59
            'from_email'          => $mail->from()->email(),
60
            'from_name'           => $mail->from()->email(),
61
            'to'                  => $to,
62
            'headers'             => ['Reply-To' => $mail->from()->email()],
63
            'important'           => true,
64
            'track_opens'         => true,
65
            'track_clicks'        => null,
66
            'auto_text'           => $mail->bodyText(),
67
            'auto_html'           => $mail->bodyHtml(),
68
            'inline_css'          => null,
69
            'url_strip_qs'        => null,
70
            'preserve_recipients' => false,
71
            'view_content_link'   => false,
72
            'tracking_domain'     => null,
73
            'signing_domain'      => null,
74
            'return_path_domain'  => null,
75
            'merge'               => true,
76
            'tags'                => [],
77
            'global_merge_vars'   => [$to],
78
        ];
79
80
        $this->mandrill->messages->send($message);
0 ignored issues
show
Bug introduced by
The property messages does not seem to exist in Mandrill.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
81
    }
82
}
83