Issues (81)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Notifications/Metrics/LogWritten.php (8 issues)

Upgrade to new PHP Analysis Engine

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
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

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.

Loading history...
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.

Loading history...
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.

Loading history...
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.

Loading history...
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.

Loading history...
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.

Loading history...
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.

Loading history...
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
The parameter $notifiable is not used and could be removed.

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

Loading history...
176
    {
177
        return [
178
            //
179
        ];
180
    }
181
}
182