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

NewFileUpload   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 27.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 40
ccs 5
cts 18
cp 0.2778
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toMail() 0 9 1
A toArray() 0 9 1
A __construct() 0 3 1
A via() 0 3 1
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