Issues (16)

Security Analysis    no request data  

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/MessageService.php (2 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
 * Created by PhpStorm.
4
 * User: alive
5
 * Date: 4/28/18
6
 * Time: 7:17 AM
7
 */
8
9
namespace Alive2212\LaravelMessageService;
10
11
12
use App\Jobs\MessageServiceEmailJob;
13
use App\Jobs\MessageServiceNotificationJob;
14
use App\Jobs\MessageServiceScopeJob;
15
use App\Jobs\MessageServiceSmsJob;
16
use App\Jobs\MessageServiceSocialJob;
17
use Carbon\Carbon;
18
19
class MessageService
20
{
21
    public function handle($model, $eventType)
22
    {
23
        // get model class name
24
        $modelClassName = get_class($model);
25
        $event = new AliveMessageEvent();
26
        $event = $event->where([
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Alive2212\Laravel...vice\AliveMessageEvent>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
27
            ['model', '=', $modelClassName],
28
        ])->with('messageProcesses');
29
        $eventParams = $event->get()->toArray();
30
        if (count($eventParams)) {
31
            foreach ($eventParams as $eventParam) {
32
                // handle available_at update and delete record
33
                $dirty = $model->getDirty();
34
                if (isset($dirty['available_at'])) {
35
                    switch ($eventType) {
36
                        // TODO more performance need
37
38
                        case 'Updating':
39
                            $this->deleteJobByModel($model);
40
                            break;
41
                        case 'Deleting':
42
                            $this->deleteJobByModel($model);
43
                            break;
44
                    }
45
                }
46
47
48
                if ($eventParam['type'] == $eventType) {
49
                    $eventRules = json_decode($eventParam['rules'], true);
50
                    $whereParams = $this->eventRulesParser($eventRules, $model->id);
51
                    if (count($whereParams)) {
52
                        $currentModel = (new $modelClassName())
53
                            ->where($whereParams);
54
                        $currentModelParams = $currentModel->get()->toArray()[0];
55
                    } else {
56
                        $currentModelParams = $model->toArray();
57
                    }
58
                    if (count($currentModelParams)) {
59
                        // this place is where process must be done
60
                        $processes = $eventParam['message_processes'];
61
                        $this->jobDispatcher($processes, $currentModelParams);
62
                    }
63
                }
64
            }
65
        }
66
    }
67
68
    /**
69
     * @param $processes
70
     * @param $currentModelParams
71
     */
72
    public function jobDispatcher($processes, $currentModelParams)
73
    {
74
        foreach ($processes as $process) {
75
            switch ($process['type']) {
76
                case "Sms":
77
                    dispatch(new MessageServiceSmsJob($process, $currentModelParams));
78
                    break;
79
80
                case "Notification":
81
                    $launchTimeKey = $process['launch_time'];
82
                    if (!is_null($launchTimeKey)) {
83
                        $launchDateTimeTimeStamp = $currentModelParams[$launchTimeKey];
84
                        $launchDateTime = Carbon::createFromTimestamp($launchDateTimeTimeStamp);
85
                        dispatch((new MessageServiceNotificationJob($process, $currentModelParams))->delay($launchDateTime));
86
                    } else {
87
                        dispatch(new MessageServiceNotificationJob($process, $currentModelParams));
88
                    }
89
                    break;
90
91
                case "Social":
92
                    dispatch(new MessageServiceSocialJob($process, $currentModelParams));
93
                    break;
94
95
                case "Email":
96
                    dispatch(new MessageServiceEmailJob($process, $currentModelParams));
97
                    break;
98
99
                default:
100
                    dispatch(new MessageServiceScopeJob($process, $currentModelParams));
101
            }
102
        }
103
    }
104
105
    /**
106
     * @param $eventRules
107
     * @param $modelId
108
     * @return mixed
109
     */
110
    public function eventRulesParser($eventRules, $modelId)
111
    {
112
        $whereParams = [];
113
114
        // add id after created variable
115
        if (!is_null($modelId)) {
116
            array_push($whereParams, ['id', '=', $modelId]);
117
        }
118
119
120
        if (is_array($eventRules)) {
121
            foreach ($eventRules as $eventRule) {
122
                // TODO create multiple deep where
123
                array_push($whereParams, [$eventRule[0], $eventRule[1], $eventRule[2]]);
124
            }
125
        }
126
        return $whereParams;
127
    }
128
129
    /**
130
     * @param $model
131
     */
132
    public function deleteJobByModel($model)
133
    {
134
        $job = \DB::table('jobs')->where('available_at', $model->getOriginal('available_at'))->delete();
0 ignored issues
show
$job is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
135
    }
136
}