Passed
Push — master ( 588c31...9953d3 )
by Stephen
02:33
created

AbstractMailable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 16
rs 10
cc 1
nc 1
nop 6
1
<?php
2
3
4
namespace Sfneal\PostOffice\Mailables;
5
6
use Illuminate\Bus\Queueable;
7
use Illuminate\Mail\Mailable as BaseMailable;
8
use Illuminate\Queue\SerializesModels;
9
10
11
abstract class AbstractMailable extends BaseMailable
12
{
13
    use Queueable, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by Sfneal\PostOffice\Mailables\AbstractMailable: $id, $relations, $class, $keyBy
Loading history...
14
15
    /**
16
     * @var string View blade to use for mailable content
17
     */
18
    public $view;
19
20
    /**
21
     * @var string First line of the email body
22
     */
23
    public $greeting = '';
24
25
    /**
26
     * @var string Recipient email address
27
     */
28
    public $email = '';
29
30
    /**
31
     * @var string Subject of the email
32
     */
33
    public $title = '';
34
35
    /**
36
     * @var array|string Array of strings to be displayed as paragraphs
37
     */
38
    public $messages;
39
40
    /**
41
     * @var array Action button url and text
42
     */
43
    public $call_to_action;
44
45
    /**
46
     * Mailable constructor.
47
     *
48
     * @param string|null $greeting
49
     * @param string|null $email
50
     * @param string|null $title
51
     * @param null $messages
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $messages is correct as it would always require null to be passed?
Loading history...
52
     * @param array|null $call_to_action
53
     * @param string|null $view
54
     */
55
    public function __construct(string $greeting = null,
56
                                string $email = null,
57
                                string $title = null,
58
                                $messages = null,
59
                                array $call_to_action = null,
60
                                string $view = null)
61
    {
62
        $this->greeting = $greeting ?? $this->greeting;
63
        $this->email = $email ?? $this->email;
64
        $this->title = $title ?? $this->title;
65
        $this->messages = $messages ?? $this->messages;
66
        $this->call_to_action = $call_to_action ?? $this->call_to_action;
67
        $this->view = $view ?? $this->view;
68
69
        $this->onQueue('mail');
70
        $this->onConnection('database');
71
    }
72
73
    /**
74
     * Build the message.
75
     *
76
     * @return $this
77
     */
78
    public function build()
79
    {
80
        return $this->subject($this->title)
81
            ->view($this->view, [
82
                'greeting' => $this->greeting,
83
                'email' => $this->email,
84
                'title' => $this->title,
85
                'messages' => $this->messages,
86
                'call_to_action' => $this->call_to_action,
87
            ]);
88
    }
89
}
90