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/RouteRequested.php (10 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\LarametricsRequest;
11
12
class RouteRequested extends Notification implements ShouldQueue
13
{
14
    use Queueable;
15
16
    private $larametricsRequest;
17
18
    private $requestInfo;
19
20
    /**
21
     * Create a new notification instance.
22
     *
23
     * @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...
24
     */
25
    public function __construct(LarametricsRequest $larametricsRequest)
26
    {
27
        $this->larametricsRequest = $larametricsRequest;
28
29
        $this->requestInfo = array(
30
            'id' => $larametricsRequest->id,
31
            'method' => $larametricsRequest->method,
32
            'uri' => $larametricsRequest->uri,
33
            'ip' => $larametricsRequest->ip,
34
            'execution_time' => floor(($larametricsRequest->end_time - $larametricsRequest->start_time) * 1000)
35
        );
36
    }
37
38
    /**
39
     * Get the notification's delivery channels.
40
     *
41
     * @param  mixed $notifiable
42
     * @return array
43
     */
44 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...
45
    {
46
        switch($notifiable->notify_by) {
47
        case 'email':
48
            return ['mail'];
49
            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...
50
        case 'slack':
51
            return ['slack'];
52
            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...
53
        case 'email_slack':
54
            return ['mail', 'slack'];
55
            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...
56
        }
57
    }
58
59
    /**
60
     * Get the mail representation of the notification.
61
     *
62
     * @param  mixed $notifiable
63
     * @return \Illuminate\Notifications\Messages\MailMessage
64
     */
65
    public function toMail($notifiable)
66
    {
67
        $content = 'A route on ' . url('/') . ' was requested.';
68 View Code Duplication
        if($notifiable->filter !== '*' && !is_numeric($notifiable->filter)) {
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...
69
            $content .= " You're being notified because the route contains `" . $notifiable->filter . "`";
70
        }
71
72
        if(is_numeric($notifiable->filter)) {
73
            $content .= " You're being notified because the execution time exceeded your limit of " . $notifiable->filter . "ms.";
74
        }
75
76
        $alertColor = '#00B945';
77 View Code Duplication
        if(is_numeric($notifiable->filter) && $this->requestInfo['execution_time'] > intval($notifiable->filter)) {
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...
78
            $alertColor = '#BC001A';
79
        }
80
81
        return (new MailMessage)
82
            ->subject(env('LARAMETRICS_ROUTE_SUBJECT', '[Larametrics Alert] A route has been requested'))
83
            ->from(env('LARAMETRICS_FROM_EMAIL', '[email protected]'), env('LARAMETRICS_FROM_NAME', 'Larametrics Alerts'))
84
            ->view(
85
                'rica.larametrics::emails.route-requested', [
86
                'requestInfo' => $this->requestInfo,
87
                'content' => $content,
88
                'alertColor' => $alertColor
89
                ]
90
            );
91
    }
92
93
    public function toSlack($notifiable)
94
    {
95
        $content = 'A route on ' . url('/') . ' was requested.';
96 View Code Duplication
        if($notifiable->filter !== '*' && !is_numeric($notifiable->filter)) {
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...
97
            $content .= " You're being notified because the route contains `" . $notifiable->filter . "`";
98
        }
99
100
        if(is_numeric($notifiable->filter)) {
101
            $content .= " You're being notified because the execution time exceeded your limit of " . $notifiable->filter . "ms.";
102
        }
103
104
        $status = 'success';
105 View Code Duplication
        if(is_numeric($notifiable->filter) && $this->requestInfo['execution_time'] > intval($notifiable->filter)) {
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...
106
            $status = 'error';
107
        }
108
109
        $requestInfo = $this->requestInfo;
110
111
        return (new SlackMessage)
112
            ->{ $status }()
113
            ->attachment(
114
                function ($attachment) use ($requestInfo, $content) {
115
                    $attachment->title('Request #' . $requestInfo['id'], route('rica.larametrics::requests.show', $requestInfo['id']))
116
                        ->content($content)
117
                        ->fields(
118
                            [
119
                            'Method' => $requestInfo['method'],
120
                            'From IP' => $requestInfo['ip'],
121
                            'Requested URI' => $requestInfo['uri'],
122
                            'Execution Time' => $requestInfo['execution_time'] . 'ms'
123
                            ]
124
                        );
125
                }
126
            );
127
    }
128
129
    /**
130
     * Get the array representation of the notification.
131
     *
132
     * @param  mixed $notifiable
133
     * @return array
134
     */
135
    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...
136
    {
137
        return [
138
            //
139
        ];
140
    }
141
}
142