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/ModelChanged.php (17 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\LarametricsModel;
11
12
class ModelChanged extends Notification implements ShouldQueue
13
{
14
    use Queueable;
15
16
    private $larametricsModel;
17
18
    /**
19
     * Create a new notification instance.
20
     *
21
     * @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...
22
     */
23
    public function __construct(LarametricsModel $larametricsModel)
24
    {
25
        $this->larametricsModel = $larametricsModel;
26
    }
27
28
    /**
29
     * Get the notification's delivery channels.
30
     *
31
     * @param  mixed $notifiable
32
     * @return array
33
     */
34 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...
35
    {
36
        switch($notifiable->notify_by) {
37
        case 'email':
38
            return ['mail'];
39
            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...
40
        case 'slack':
41
            return ['slack'];
42
            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...
43
        case 'email_slack':
44
            return ['mail', 'slack'];
45
            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...
46
        }
47
    }
48
49
    /**
50
     * Get the mail representation of the notification.
51
     *
52
     * @param  mixed $notifiable
53
     * @return \Illuminate\Notifications\Messages\MailMessage
54
     */
55
    public function toMail($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...
56
    {
57
        $modelInfo = array(
58
            'id' => $this->larametricsModel->id,
59
            'model' => $this->larametricsModel->model,
60
            'method' => $this->larametricsModel->method,
61
            'original' => json_decode($this->larametricsModel->original, true),
0 ignored issues
show
The property $original is declared protected in Illuminate\Database\Eloq...\Concerns\HasAttributes. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
            'changes' => json_decode($this->larametricsModel->changes, true)
0 ignored issues
show
The property $changes is declared protected in Illuminate\Database\Eloq...\Concerns\HasAttributes. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
63
        );
64
        $alertColor = '#ff9f00';
65
        switch($this->larametricsModel->method) {
66
        case 'created':
67
            $alertColor = '#00B945';
68
            break;
69
        case 'deleted':
70
            $alertColor = '#BC001A';
71
            break;
72
        }
73
74
        return (new MailMessage)
75
            ->subject(env('LARAMETRICS_MODEL_SUBJECT', '[Larametrics Alert] A model has been ' . $modelInfo['method']))
76
            ->from(env('LARAMETRICS_FROM_EMAIL', '[email protected]'), env('LARAMETRICS_FROM_NAME', 'Larametrics Alerts'))
77
            ->view(
78
                'rica.larametrics::emails.model-changed', [
79
                'modelInfo' => $modelInfo,
80
                'alertColor' => $alertColor
81
                ]
82
            );
83
    }
84
85
    public function toSlack($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...
86
    {
87
        $modelInfo = array(
88
            'id' => $this->larametricsModel->id,
89
            'model' => $this->larametricsModel->model,
90
            'original' => json_decode($this->larametricsModel->original, true),
0 ignored issues
show
The property $original is declared protected in Illuminate\Database\Eloq...\Concerns\HasAttributes. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
91
            'changes' => json_decode($this->larametricsModel->changes, true)
0 ignored issues
show
The property $changes is declared protected in Illuminate\Database\Eloq...\Concerns\HasAttributes. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
92
        );
93
        
94
        switch($this->larametricsModel->method) {
95
        case 'updated':
96
            return (new SlackMessage)
97
                ->warning()
98
                ->attachment(
99
                    function ($attachment) use ($modelInfo) {
100
                        $columnsChanged = '';
101
                        foreach(array_keys($modelInfo['changes']) as $changedColumn) {
102
                            $columnsChanged .= '    • ' . $changedColumn . "\r\n";
103
                        }
104
                        $attachment->title($modelInfo['model'] . ' #' . $modelInfo['original']['id'], route('rica.larametrics::models.show', $modelInfo['id']))
105
                            ->content('A model on ' . url('/') . ' has been updated. The following columns have changed:' . "\r\n" . $columnsChanged)
106
                            ->markdown(['text']);
107
                    }
108
                );
109
            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...
110 View Code Duplication
        case 'created':
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...
111
            return (new SlackMessage)
112
                ->success()
113
                ->attachment(
114
                    function ($attachment) use ($modelInfo) {
115
                        $attachment->title($modelInfo['model'] . ' #' . $modelInfo['original']['id'], route('rica.larametrics::models.show', $modelInfo['id']))
116
                            ->content('A model on ' . url('/') . ' has been created.');
117
                    }
118
                );
119
            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...
120 View Code Duplication
        case 'deleted':
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...
121
            return (new SlackMessage)
122
                ->error()
123
                ->attachment(
124
                    function ($attachment) use ($modelInfo) {
125
                        $attachment->title($modelInfo['model'] . ' #' . $modelInfo['original']['id'], route('rica.larametrics::models.show', $modelInfo['id']))
126
                            ->content('A model on ' . url('/') . ' has been deleted.');
127
                    }
128
                );
129
            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...
130
        }
131
    }
132
133
    /**
134
     * Get the array representation of the notification.
135
     *
136
     * @param  mixed $notifiable
137
     * @return array
138
     */
139
    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...
140
    {
141
        return [
142
            //
143
        ];
144
    }
145
}
146