Passed
Push — dev5 ( 1d5fd3...2b65af )
by Ron
08:51
created

NewFileUpload::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Notifications;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Contracts\Queue\ShouldQueue;
8
use Illuminate\Notifications\Messages\MailMessage;
9
10
class NewFileUpload extends Notification implements ShouldQueue
11
{
12
    use Queueable;
13
    protected $details;
14
15
    //  Constructor receives the file link details
16 2
    public function __construct($details)
17
    {
18 2
        $this->details = $details;
19 2
    }
20
21
    //  Notification is sent via email and dashboard notification
22 2
    public function via($notifiable)
23
    {
24 2
        return ['mail', 'database'];
25
    }
26
27
    //  Email notification
28
    public function toMail($notifiable)
29
    {
30
        return (new MailMessage)
31
            ->line('A new file has been uploaded to the file link - '.$this->details->link_name)
32
            ->action('Click to View Link',
33
                url(route('links.details',
34
                [
35
                        'id' => $this->details->link_id,
36
                        'name' => urlencode($this->details->link_name)
37
                ])));
38
    }
39
40
    //  Dashboard notification
41
    public function toArray($notifiable)
42
    {
43
        return [
44
            'type'    => 'warning',
45
            'message' => 'New File(s) Uploaded to link - '.$this->details->link_name,
46
            'link'    => url(route('links.details',
47
                            [
48
                            'id' => $this->details->link_id,
49
                                'name' => urlencode($this->details->link_name)
50
                            ]))
51
        ];
52
    }
53
}
54