Completed
Push — master ( 6eeca4...99902c )
by Lucas Pires
02:02
created

MailDriver::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
3
namespace FlyingLuscas\BugNotifier\Drivers;
4
5
use Illuminate\Support\Facades\Mail;
6
use FlyingLuscas\BugNotifier\Message;
7
8
class MailDriver implements DriverContract
9
{
10
    /**
11
     * Send e-mail message.
12
     *
13
     * @param \FlyingLuscas\BugNotifier\Message $message
14
     *
15
     * @return void
16
     */
17
    public function handle(Message $message)
18
    {
19
        $view = $this->getMailViewLink();
20
21
        $name = $this->getMailDestinationName();
22
        $address = $this->getMailDestinationAddress();
23
        $subject = $message->getTitle();
24
        $body = $message->getBody();
25
26
        Mail::send($view, [
27
            'body' => $body,
28
            'subject' => $subject,
29
        ], function ($mail) use ($subject, $address, $name) {
30
            $mail->subject($subject)->to($address, $name);
31
        });
32
    }
33
34
    /**
35
     * Get e-mail destination name.
36
     *
37
     * @return string
38
     */
39
    protected function getMailDestinationName()
40
    {
41
        return config('bugnotifier.drivers.mail.to.name');
42
    }
43
44
    /**
45
     * Get e-mail destination address.
46
     *
47
     * @return string
48
     */
49
    protected function getMailDestinationAddress()
50
    {
51
        return config('bugnotifier.drivers.mail.to.address');
52
    }
53
54
    /**
55
     * Get the view link for the e-mail message.
56
     *
57
     * @return string
58
     */
59
    protected function getMailViewLink()
60
    {
61
        return config('bugnotifier.drivers.mail.view');
62
    }
63
}
64