NewTechTipCommentNotification   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 26
c 2
b 0
f 0
dl 0
loc 59
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toMail() 0 9 1
A via() 0 11 2
A __construct() 0 5 1
A toArray() 0 8 1
1
<?php
2
3
namespace App\Notifications;
4
5
use App\Models\TechTip;
6
use App\Models\TechTipComment;
7
use App\Models\User;
8
use App\Models\UserSettingType;
9
use Illuminate\Bus\Queueable;
10
use Illuminate\Contracts\Queue\ShouldQueue;
11
use Illuminate\Notifications\Messages\MailMessage;
12
use Illuminate\Notifications\Notification;
13
14
class NewTechTipCommentNotification extends Notification implements ShouldQueue
15
{
16
    use Queueable;
17
18
    protected $comment;
19
    protected $user;
20
    protected $tip;
21
22
    /**
23
     * Create a new notification instance
24
     */
25
    public function __construct(TechTipComment $comment, User $user)
26
    {
27
        $this->comment = $comment;
28
        $this->user    = $user;
29
        $this->tip     = TechTip::find($comment->tip_id);
30
    }
31
32
    /**
33
     * Get the notification's delivery channels
34
     */
35
    public function via($notifiable)
36
    {
37
        $settingId = UserSettingType::where('name', 'Receive Email Notifications')->first()->setting_type_id;
38
        $allow     = $notifiable->UserSetting->where('setting_type_id', $settingId)->first()->value;
39
40
        if($allow)
41
        {
42
            return ['mail', 'database'];
43
        }
44
45
        return ['database'];
46
    }
47
48
    /**
49
     * Get the mail representation of the notification
50
     */
51
    public function toMail($notifiable)
52
    {
53
        return (new MailMessage)
54
                    ->subject('Someone Commented On A Tech Tip')
55
                    ->greeting('Hello '.$notifiable->full_name)
56
                    ->line($this->user->full_name.' has commented on Tech Tip - .'.$this->tip->subject)
57
                    ->line('The comment is: ')
58
                    ->line($this->comment->comment)
59
                    ->action('Click Here to review the comment', url(route('tech-tips.show', $this->tip->slug)));
60
    }
61
62
    /**
63
     * Get the array representation of the notification
64
     */
65
    public function toArray($notifiable)
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

65
    public function toArray(/** @scrutinizer ignore-unused */ $notifiable)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
    {
67
        return [
68
            'subject' => 'New Tech Tip Comment',
69
            'data'    => [
70
                'tip'     => $this->tip,
71
                'comment' => $this->comment,
72
                'user'    => $this->user,
73
            ],
74
        ];
75
    }
76
}
77