This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Siravel\Notifications\Metrics; |
||
4 | |||
5 | use Illuminate\Bus\Queueable; |
||
6 | use Illuminate\Notifications\Notification; |
||
7 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
8 | use Illuminate\Notifications\Messages\MailMessage; |
||
9 | use Illuminate\Notifications\Messages\SlackMessage; |
||
10 | use Tracking\Models\Metrics\LarametricsLog; |
||
11 | |||
12 | class LogWritten extends Notification implements ShouldQueue |
||
13 | { |
||
14 | use Queueable; |
||
15 | |||
16 | private $larametricsLog; |
||
17 | |||
18 | private $requestInfo; |
||
19 | |||
20 | private $notificationLevels; |
||
21 | |||
22 | /** |
||
23 | * Create a new notification instance. |
||
24 | * |
||
25 | * @return void |
||
0 ignored issues
–
show
|
|||
26 | */ |
||
27 | public function __construct(LarametricsLog $larametricsLog) |
||
28 | { |
||
29 | $this->larametricsLog = $larametricsLog; |
||
30 | |||
31 | $this->requestInfo = array( |
||
32 | 'id' => $larametricsLog->id, |
||
33 | 'level' => $larametricsLog->level, |
||
34 | 'message' => $larametricsLog->message, |
||
35 | 'user_id' => $larametricsLog->user_id ? $larametricsLog->user_id : null, |
||
36 | 'email' => $larametricsLog->email ? $larametricsLog->email : null |
||
37 | ); |
||
38 | |||
39 | $this->notificationLevels = array( |
||
40 | 'error' => [ |
||
41 | 'emergency', |
||
42 | 'alert', |
||
43 | 'critical', |
||
44 | 'error' |
||
45 | ], |
||
46 | 'warning' => [ |
||
47 | 'warning', |
||
48 | 'notice' |
||
49 | ], |
||
50 | 'success' => [ |
||
51 | 'info', |
||
52 | 'debug' |
||
53 | ] |
||
54 | ); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Get the notification's delivery channels. |
||
59 | * |
||
60 | * @param mixed $notifiable |
||
61 | * @return array |
||
62 | */ |
||
63 | View Code Duplication | public function via($notifiable) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
64 | { |
||
65 | switch($notifiable->notify_by) { |
||
66 | case 'email': |
||
67 | return ['mail']; |
||
68 | break; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
69 | case 'slack': |
||
70 | return ['slack']; |
||
71 | break; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
72 | case 'email_slack': |
||
73 | return ['mail', 'slack']; |
||
74 | break; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
75 | } |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Get the mail representation of the notification. |
||
80 | * |
||
81 | * @param mixed $notifiable |
||
82 | * @return \Illuminate\Notifications\Messages\MailMessage |
||
83 | */ |
||
84 | public function toMail($notifiable) |
||
85 | { |
||
86 | $content = 'A log on ' . url('/') . ' has been written to.'; |
||
87 | if($notifiable->filter !== '*') { |
||
88 | $content .= " You're being notified because the log contains `" . $notifiable->filter . "`"; |
||
89 | } |
||
90 | |||
91 | $status = 'success'; |
||
92 | View Code Duplication | foreach($this->notificationLevels as $triggerLevel => $childLevels) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
93 | if(in_array($this->requestInfo['level'], $childLevels)) { |
||
94 | $status = $triggerLevel; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | $fields = array( |
||
99 | 'Level' => $this->requestInfo['level'], |
||
100 | 'Message' => $this->requestInfo['message'] |
||
101 | ); |
||
102 | |||
103 | if($this->requestInfo['user_id']) { |
||
104 | $fields['User ID'] = $this->requestInfo['user_id']; |
||
105 | } |
||
106 | |||
107 | if($this->requestInfo['email']) { |
||
108 | $fields['Associated Email'] = $this->requestInfo['email']; |
||
109 | } |
||
110 | |||
111 | $statusColors = array( |
||
112 | 'success' => '#00B945', |
||
113 | 'warning' => '#ff9f00', |
||
114 | 'error' => '#BC001A' |
||
115 | ); |
||
116 | |||
117 | return (new MailMessage) |
||
118 | ->subject(env('LARAMETRICS_LOG_SUBJECT', '[Larametrics Alert] The application log has been written to')) |
||
119 | ->from(env('LARAMETRICS_FROM_EMAIL', '[email protected]'), env('LARAMETRICS_FROM_NAME', 'Larametrics Alerts')) |
||
120 | ->view( |
||
121 | 'rica.larametrics::emails.log-written', [ |
||
122 | 'requestInfo' => $this->requestInfo, |
||
123 | 'content' => $content, |
||
124 | 'alertColor' => $statusColors[$status] |
||
125 | ] |
||
126 | ); |
||
127 | } |
||
128 | |||
129 | public function toSlack($notifiable) |
||
130 | { |
||
131 | $content = 'A log on ' . url('/') . ' has been written to.'; |
||
132 | if($notifiable->filter !== '*') { |
||
133 | $content .= " You're being notified because the log contains `" . $notifiable->filter . "`"; |
||
134 | } |
||
135 | |||
136 | $status = 'success'; |
||
137 | View Code Duplication | foreach($this->notificationLevels as $triggerLevel => $childLevels) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
138 | if(in_array($this->requestInfo['level'], $childLevels)) { |
||
139 | $status = $triggerLevel; |
||
140 | } |
||
141 | } |
||
142 | |||
143 | $fields = array( |
||
144 | 'Level' => $this->requestInfo['level'], |
||
145 | 'Message' => $this->requestInfo['message'] |
||
146 | ); |
||
147 | |||
148 | if($this->requestInfo['user_id']) { |
||
149 | $fields['User ID'] = $this->requestInfo['user_id']; |
||
150 | } |
||
151 | |||
152 | if($this->requestInfo['email']) { |
||
153 | $fields['Associated Email'] = $this->requestInfo['email']; |
||
154 | } |
||
155 | |||
156 | $requestInfo = $this->requestInfo; |
||
157 | |||
158 | return (new SlackMessage) |
||
159 | ->{ $status }() |
||
160 | ->attachment( |
||
161 | function ($attachment) use ($requestInfo, $fields, $content) { |
||
162 | $attachment->title('Log #' . $requestInfo['id'], route('rica.larametrics::logs.show', $requestInfo['id'])) |
||
163 | ->content($content) |
||
164 | ->fields($fields); |
||
165 | } |
||
166 | ); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * Get the array representation of the notification. |
||
171 | * |
||
172 | * @param mixed $notifiable |
||
173 | * @return array |
||
174 | */ |
||
175 | public function toArray($notifiable) |
||
0 ignored issues
–
show
|
|||
176 | { |
||
177 | return [ |
||
178 | // |
||
179 | ]; |
||
180 | } |
||
181 | } |
||
182 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.