ManualReminderEmail::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace App\Mail;
4
5
use App\Loan;
6
use Illuminate\Bus\Queueable;
7
use Illuminate\Mail\Mailable;
8
use Illuminate\Queue\SerializesModels;
9
use Illuminate\Contracts\Queue\ShouldQueue;
10
11
class ManualReminderEmail extends Mailable
12
{
13
    use Queueable, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Mail\ManualReminderEmail: $id, $relations, $class, $keyBy
Loading history...
14
15
    /**
16
     * Create a new message instance.
17
     *
18
     * @param Loan $loan
19
     * @param $subject
20
     * @param $body
21
     */
22
    public function __construct(Loan $loan, $subject, $body)
23
    {
24
        $sender = $loan->library;
25
        $lang = $loan->user->lang;
26
27
        switch ($lang) {
28
            case 'eng':
29
                $sender_name = $sender->name_eng;
30
                break;
31
            default:
32
                $sender_name = $sender->name;
33
                break;
34
        }
35
36
        $this->data = [
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
            'sender_name' => $sender_name,
38
            'sender_mail' => $sender->email,
39
            'receiver_name' => $loan->user->firstname . ' ' . $loan->user->lastname,
40
            'receiver_mail' => $loan->user->email,
41
            'subject' => (string) $subject,
42
            'body' => (string) $body,
43
        ];
44
    }
45
46
    public function toArray()
47
    {
48
        return $this->data;
49
    }
50
51
    /**
52
     * Build the message.
53
     *
54
     * @return $this
55
     */
56
    public function build()
57
    {
58
        return $this
59
            ->from($this->data['sender_mail'], $this->data['sender_name'])
60
            ->to($this->data['receiver_mail'], $this->data['receiver_name'])
61
            ->subject($this->data['subject'])
62
            ->text('emails.generic')
63
            ->with([
64
                'content' => $this->data['body'],
65
            ]);
66
    }
67
}
68