GeneralNotification   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 81
c 1
b 0
f 0
dl 0
loc 152
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 32 1
A toArray() 0 3 1
A toMail() 0 7 1
A via() 0 3 1
1
<?php
2
3
namespace App\Notifications;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Notifications\Messages\MailMessage;
7
use Illuminate\Notifications\Notification;
8
9
class GeneralNotification extends Notification
10
{
11
    // use Queueable;
12
13
    // Constants
14
15
    // Actions
16
    const BROWSE = 'Browse';
17
    const READ = 'Read';
18
    const EDIT = 'Edit';
19
    const ADD = 'Add';
20
    const DELETE = 'Delete';
21
22
    // Severity
23
    const INSIGNIFICANT = 0;
24
    const LOW = 1;
25
    const MID = 2;
26
    const HIGH = 3;
27
    const VERYHIGH = 4;
28
29
    // From
30
    const FROM_SYSTEM = 1;
31
    const FROM_USER = 2;
32
33
    // Type
34
    const INFO = 1;
35
    const ALERT = 2;
36
    const REMINDER = 3;
37
    const MESSAGE = 4;
38
    const WARNING = 5;
39
    const NEWS = 6;
40
    const REPORT = 7;
41
42
    public $title;
43
44
    public $message;
45
46
    public $action;
47
48
    public $url;
49
50
    public $subject;
51
52
    public $color;
53
54
    public $type;
55
56
    public $category;
57
58
    public $severity;
59
60
    public $from;
61
62
    public $icon = 'fa fa-bell';
63
64
    public $is_snoozed = false;
65
66
    public $alram = null;
67
68
    public $body;
69
70
    public $channels;
71
72
    public $audiance;
73
74
    // Notification Display Setting
75
    public $allow_dismiss = true;
76
    public $newest_on_top = true;
77
    public $mouse_over = false;
78
    public $showProgressbar = false;
79
    public $spacing = 10;
80
    public $timer = 8000;
81
    public $placement_from = 'bottom';
82
    public $placement_align = 'right';
83
    public $delay = 1000;
84
    public $animate_enter = 'bounceIn';
85
    public $animate_exit = 'rubberBand';
86
87
    /**
88
     * Create a new notification instance.
89
     *
90
     * @return void
91
     */
92
    public function __construct($data)
93
    {
94
        $this->body = $data;
95
        $this->title = $data['title'] ?? 'System Notification';
96
        $this->message = $data['message'] ?? 'Message not found.';
97
        $this->action = $data['action'] ?? null;
98
        $this->color = $data['color'] ?? 'primary';
99
        $this->url = $data['url'] ?? null;
100
        $this->category = $data['category'] ?? 'General';
101
        $this->type = $data['type'] ?? 1;
102
        $this->severity = $data['severity'] ?? 1;
103
        $this->from = $data['from'] ?? 1;
104
        $this->icon = $data['icon'] ?? 'fa fa-bell';
105
        $this->is_snoozed = $data['is_snoozed'] ?? false;
106
        $this->alram = $data['alram'] ?? null;
107
        $this->channels = $data['channels'] ?? null;
108
        $this->audiance = $data['audiance'] ?? null;
109
110
        // Notification Display Setting
111
        $this->allow_dismiss = $data['allow_dismiss'] ?? true;
112
        $this->newest_on_top = $data['newest_on_top'] ?? true;
113
        $this->mouse_over = $data['mouse_over'] ?? false;
114
        $this->showProgressbar = $data['showProgressbar'] ?? false;
115
        $this->spacing = $data['spacing'] ?? 10;
116
        $this->timer = $data['timer'] ?? 8000;
117
        $this->placement_from = $data['placement_from'] ?? 'bottom';
118
        $this->placement_align = $data['placement_align'] ?? 'right';
119
        $this->delay = $data['delay'] ?? 1000;
120
        $this->animate_enter = $data['animate_enter'] ?? 'bounceIn';
121
        $this->animate_exit = $data['animate_exit'] ?? 'rubberBand';
122
123
        $this->subject = $data['subject'] ?? (($this->action ?? 'General').' Notification : '.$this->title);
124
    }
125
126
    /**
127
     * Get the notification's delivery channels.
128
     *
129
     * @param  mixed  $notifiable
130
     * @return array
131
     */
132
    public function via($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

132
    public function via(/** @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...
133
    {
134
        return $this->body['channels'] ?? general_notification_mediums();
0 ignored issues
show
Bug introduced by
The function general_notification_mediums was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

134
        return $this->body['channels'] ?? /** @scrutinizer ignore-call */ general_notification_mediums();
Loading history...
135
    }
136
137
    /**
138
     * Get the mail representation of the notification.
139
     *
140
     * @param  mixed  $notifiable
141
     * @return \Illuminate\Notifications\Messages\MailMessage
142
     */
143
    public function toMail($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

143
    public function toMail(/** @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...
144
    {
145
        return (new MailMessage)
146
            ->subject($this->subject)
147
            ->line($this->subject)
148
            ->line($this->message)
149
            ->line('From '.title());
150
    }
151
152
    /**
153
     * Get the array representation of the notification.
154
     *
155
     * @param  mixed  $notifiable
156
     * @return array
157
     */
158
    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

158
    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...
159
    {
160
        return $this->body;
161
    }
162
}
163