Issues (27)

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/Sms/Worker.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
namespace Messenger\Sms;
4
5
use Cronario\AbstractJob;
6
use Cronario\AbstractWorker;
7
use Cronario\Exception\WorkerException;
8
9
class Worker extends AbstractWorker
10
{
11
12
    //region Config ***********************************************************
13
14
    protected static $config
15
        = [
16
            AbstractWorker::CONFIG_P_MANAGERS_LIMIT         => 3,
17
            AbstractWorker::CONFIG_P_MANAGER_POOL_SIZE      => 5,
18
            AbstractWorker::CONFIG_P_MANAGER_IDLE_DIE_DELAY => 5,
19
            self::GATEWAY_CLASS_SET                         => [
20
                '\Messenger\Sms\Alpha\Worker' => [
21
                    self::GATEWAY_CLASS_P_REGEX_RECIPIENT => '/^(38)/'
22
                ],
23
                '\Messenger\Sms\Test\Worker' => [
24
                    self::GATEWAY_CLASS_P_REGEX_RECIPIENT => '/^(38)/'
25
                ],
26
            ],
27
        ];
28
29
    //endregion ****************************************************************
30
31
    //region GATEWAY ***********************************************************
32
33
    const GATEWAY_DISPATCH_CLASS = 'gatewayDispatchClass';
34
    const GATEWAY_CLASS_SET = 'gatewayClassSet';
35
    const GATEWAY_CLASS_P_REGEX_RECIPIENT = 'regexRecipient';
36
37
    /**
38
     * @param Job $job
39
     *
40
     * @return array
41
     * @throws WorkerException
42
     */
43 3
    protected function analiseGateway(Job $job)
44
    {
45 3
        $gatewayClassSet = self::getConfig(self::GATEWAY_CLASS_SET);
46
47 3
        if (count($gatewayClassSet) === 0) {
48
            throw new WorkerException('Empty gateway class set!');
49
        }
50
51 3
        $gatewayClassScore = [];
52 3
        foreach ($gatewayClassSet as $gatewayClass => $gatewayOptions) {
53 3
            $gatewayClassScore[$gatewayClass] = 0;
54
55 3
            if (preg_match($gatewayOptions[self::GATEWAY_CLASS_P_REGEX_RECIPIENT],
56 3
                $job->getRecipient())) {
57 3
                $gatewayClassScore[$gatewayClass]++;
58 3
            }
59
60
            // ......
61 3
        }
62
63 3
        $maxClass = array_keys($gatewayClassScore, max($gatewayClassScore))[0];
64
65 3
        if ($gatewayClassScore[$maxClass] === 0) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
66
            // Transport is bad : $maxClass = 0 , and we have no ideas what return :(
67
        }
68
69 3
        return $maxClass;
70
    }
71
72
    //endregion ***************************************************************
73
74
    // region Default Result Data**************************************************************
75
76
    const P_RESULT_DATA_VENDOR_NAME = 'vendor';
77
    const P_RESULT_DATA_VENDOR_ID = 'vendor_id';
78
    const P_RESULT_DATA_SUCCESS = 'success';
79
    const P_RESULT_DATA_ERRORS = 'errors';
80
81
    /**
82
     * @param null $vendor_name
83
     * @param null $vendor_id
84
     * @param null $success
85
     * @param null $errors
86
     *
87
     * @return array
88
     */
89 5
    public static function buildResultDataDefault(
90
        $vendor_name = null,
91
        $vendor_id = null,
92
        $success = null,
93
        $errors = null
94
    ) {
95
        return [
96 5
            self::P_RESULT_DATA_VENDOR_NAME => $vendor_name,
97 5
            self::P_RESULT_DATA_VENDOR_ID   => $vendor_id,
98 5
            self::P_RESULT_DATA_SUCCESS     => $success,
99 5
            self::P_RESULT_DATA_ERRORS      => $errors,
100 5
        ];
101
    }
102
103
    //endregion ***************************************************************
104
105
    /**
106
     * if job is sync then we get worker and try execute job
107
     * else if job is Async then redirect to other queue
108
     *
109
     * REMEMBER: Queue name is equal to Worker class name (through all "Cronario")
110
     *
111
     * @param AbstractJob|Job $job
112
     *
113
     * @throws ResultException
114
     * @throws WorkerException
115
     */
116 3
    protected function doJob(AbstractJob $job)
117
    {
118 3
        $gatewayClass = $this->analiseGateway($job);
0 ignored issues
show
$job of type object<Cronario\AbstractJob> is not a sub-type of object<Messenger\Sms\Job>. It seems like you assume a child class of the class Cronario\AbstractJob to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
119
120 3
        if ($job->isSync()) {
121 1
            $worker = AbstractWorker::factory($gatewayClass);
122
123 1
            return $worker($job);
124
        }
125
126 2
        if (!$job->hasAttempt()) {
127 1
            throw new ResultException(ResultException::FAILURE_MAX_ATTEMPTS);
128
        }
129
130
        // redirect result for new gateway class
131 1
        $job->addDebug(['set_gateway' => $gatewayClass]);
132 1
        $job->setWorkerClass($gatewayClass)->save();
133
134 1
        throw new ResultException(ResultException::REDIRECT_GATEWAY_CLASS);
135
    }
136
}