Completed
Push — master ( 1cfd7b...f34219 )
by Yaro
9s
created

LogEmail::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
namespace Yaro\LogEnvelope\Mail;
3
4
use Illuminate\Bus\Queueable;
5
use Illuminate\Mail\Mailable;
6
use Illuminate\Queue\SerializesModels;
7
use Illuminate\Contracts\Queue\ShouldQueue;
8
9
class LogEmail extends Mailable implements ShouldQueue
10
{
11
    use Queueable, SerializesModels;
12
    
13
    public $data;
14
    public $config;
15
    
16
    public function __construct($data, $config)
17
    {
18
        $this->data = $data;
19
        $this->config = $config;
20
    }
21
    
22
    /**
23
     * Build the message.
24
     *
25
     * @return $this
26
     */
27
    public function build()
28
    {
29
        $subject = sprintf('[%s] @ %s: %s', $this->data['class'], $this->data['host'], $this->data['exception']);
30
    
31
        // to protect from gmail's anchors automatic generating
32
        $this->withSwiftMessage(function ($message) {
33
            $message->setBody(
34
                preg_replace(
35
                    ['~\.~', '~http~'],
36
                    ['<span>.</span>', '<span>http</span>'],
37
                    $message->getBody()
38
                )
39
            );
40
        });
41
        
42
        return $this->view('log-envelope::main')
43
            ->with($this->data)
44
            ->to($this->config['to'])
45
            ->from($this->config['from_email'], $this->config['from_name'])
46
            ->subject($subject);
47
    }
48
}
49