Issues (1507)

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.

PHPDaemon/SockJS/Application.php (25 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
namespace PHPDaemon\SockJS;
3
4
use PHPDaemon\Servers\WebSocket\Pool as WebSocketPool;
5
use PHPDaemon\Structures\ObjectStorage;
6
7
/**
8
 * @package    Libraries
9
 * @subpackage SockJS
10
 * @author     Vasily Zorin <[email protected]>
11
 */
12
class Application extends \PHPDaemon\Core\AppInstance
13
{
14
    public $wss;
15
    protected $redis;
16
    protected $sessions;
17
18
    /**
19
     * Set Redis instance
20
     * @param \PHPDaemon\Clients\Redis\Pool $redis
21
     * @return $this
22
     */
23
    public function setRedis(\PHPDaemon\Clients\Redis\Pool $redis)
24
    {
25
        $this->redis = $redis;
26
        return $this;
27
    }
28
29
    /**
30
     * getLocalSubscribersCount
31
     * @param  string $chan
32
     * @return integer
33
     */
34
    public function getLocalSubscribersCount($chan)
35
    {
36
        return $this->redis->getLocalSubscribersCount($this->config->redisprefix->value . $chan);
37
    }
38
39
    /**
40
     * subscribe
41
     * @param  string $chan [@todo description]
42
     * @param  callable $cb [@todo description]
43
     * @param  callable $opcb [@todo description]
0 ignored issues
show
Should the type for parameter $opcb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
44
     * @callback $cb ( )
45
     * @callback $opcb ( )
46
     * @return void
47
     */
48
    public function subscribe($chan, $cb, $opcb = null)
49
    {
50
        $this->redis->subscribe($this->config->redisprefix->value . $chan, $cb, $opcb);
0 ignored issues
show
The method subscribe() does not exist on PHPDaemon\Clients\Redis\Pool. Did you maybe mean getLocalSubscribersCount()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
51
    }
52
53
    /**
54
     * setnx
55
     * @param  string $key [@todo description]
56
     * @param  mixed $value [@todo description]
57
     * @param  callable $cb [@todo description]
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
58
     * @callback $cb ( )
59
     * @return void
60
     */
61
    public function setnx($key, $value, $cb = null)
62
    {
63
        $this->redis->setnx($this->config->redisprefix->value . $key, $value, $cb);
0 ignored issues
show
Documentation Bug introduced by
The method setnx does not exist on object<PHPDaemon\Clients\Redis\Pool>? 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...
64
    }
65
66
    /**
67
     * setkey
68
     * @param  string $key [@todo description]
69
     * @param  mixed $value [@todo description]
70
     * @param  callable $cb [@todo description]
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
71
     * @callback $cb ( )
72
     * @return void
73
     */
74
    public function setkey($key, $value, $cb = null)
75
    {
76
        $this->redis->set($this->config->redisprefix->value . $key, $value, $cb);
0 ignored issues
show
Documentation Bug introduced by
The method set does not exist on object<PHPDaemon\Clients\Redis\Pool>? 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...
77
    }
78
79
    /**
80
     * getkey
81
     * @param  string $key [@todo description]
82
     * @param  callable $cb [@todo description]
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
83
     * @callback $cb ( )
84
     * @return void
85
     */
86
    public function getkey($key, $cb = null)
87
    {
88
        $this->redis->get($this->config->redisprefix->value . $key, $cb);
0 ignored issues
show
Documentation Bug introduced by
The method get does not exist on object<PHPDaemon\Clients\Redis\Pool>? 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...
89
    }
90
91
    /**
92
     * expire
93
     * @param  string $key [@todo description]
94
     * @param  integer $seconds [@todo description]
95
     * @param  callable $cb [@todo description]
0 ignored issues
show
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
96
     * @callback $cb ( )
97
     * @return void
98
     */
99
    public function expire($key, $seconds, $cb = null)
100
    {
101
        $this->redis->expire($this->config->redisprefix->value . $key, $seconds, $cb);
0 ignored issues
show
Documentation Bug introduced by
The method expire does not exist on object<PHPDaemon\Clients\Redis\Pool>? 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...
102
    }
103
104
    /**
105
     * unsubscribe
106
     * @param  string $chan [@todo description]
107
     * @param  callable $cb [@todo description]
108
     * @param  callable $opcb [@todo description]
0 ignored issues
show
Should the type for parameter $opcb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
109
     * @callback $cb ( )
110
     * @callback $opcb ( )
111
     * @return void
112
     */
113
    public function unsubscribe($chan, $cb, $opcb = null)
114
    {
115
        $this->redis->unsubscribe($this->config->redisprefix->value . $chan, $cb, $opcb);
0 ignored issues
show
Documentation Bug introduced by
The method unsubscribe does not exist on object<PHPDaemon\Clients\Redis\Pool>? 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...
116
    }
117
118
    /**
119
     * unsubscribeReal
120
     * @param  string $chan [@todo description]
121
     * @param  callable $opcb [@todo description]
0 ignored issues
show
Should the type for parameter $opcb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
122
     * @callback $opcb ( )
123
     * @return void
124
     */
125
    public function unsubscribeReal($chan, $opcb = null)
126
    {
127
        $this->redis->unsubscribeReal($this->config->redisprefix->value . $chan, $opcb);
0 ignored issues
show
Documentation Bug introduced by
The method unsubscribeReal does not exist on object<PHPDaemon\Clients\Redis\Pool>? 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...
128
    }
129
130
    /**
131
     * publish
132
     * @param  string $chan [@todo description]
133
     * @param  callable $cb [@todo description]
134
     * @param  callable $opcb [@todo description]
0 ignored issues
show
Should the type for parameter $opcb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
135
     * @callback $cb ( )
136
     * @callback $opcb ( )
137
     * @return void
138
     */
139
    public function publish($chan, $cb, $opcb = null)
140
    {
141
        $this->redis->publish($this->config->redisprefix->value . $chan, $cb, $opcb);
0 ignored issues
show
Documentation Bug introduced by
The method publish does not exist on object<PHPDaemon\Clients\Redis\Pool>? 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...
142
    }
143
144
    /**
145
     * Called when the worker is ready to go
146
     * @return void
147
     */
148
    public function onReady()
149
    {
150
        $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance($this->config->redisname->value);
151
        $this->sessions = new ObjectStorage;
152
        $this->wss = new ObjectStorage;
153
        foreach (preg_split('~\s*;\s*~', $this->config->wssname->value) as $wssname) {
154
            $this->attachWss(WebSocketPool::getInstance(trim($wssname)));
155
        }
156
    }
157
158
    /**
159
     * attachWss
160
     * @param \PHPDaemon\Network\Pool $wss
161
     * @return boolean
162
     */
163
    public function attachWss($wss)
164
    {
165
        if ($this->wss->contains($wss)) {
166
            return false;
167
        }
168
        $this->wss->attach($wss);
169
        $wss->bind('customTransport', [$this, 'wsHandler']);
0 ignored issues
show
Documentation Bug introduced by
The method bind does not exist on object<PHPDaemon\Network\Pool>? 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...
170
        return true;
171
    }
172
173
    /**
174
     * onFinish
175
     * @return void
176
     */
177
    public function onFinish()
178
    {
179
        foreach ($this->attachedTo as $wss) {
0 ignored issues
show
The property attachedTo does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
180
            $this->detachWss($wss);
181
        }
182
        parent::onFinish();
183
    }
184
185
    /**
186
     * detachWss
187
     * @param  object $wss [@todo description]
188
     * @return boolean
189
     */
190
    public function detachWss($wss)
191
    {
192
        if (!$this->wss->contains($wss)) {
193
            return false;
194
        }
195
        $this->wss->detach($wss);
196
        $wss->unbind('transport', [$this, 'wsHandler']);
197
        return true;
198
    }
199
200
    /**
201
     * wsHandler
202
     * @param  object $ws [@todo description]
203
     * @param  string $path [@todo description]
204
     * @param  object $client [@todo description]
205
     * @param  callable $state [@todo description]
206
     * @callback $state ( object $route )
207
     * @return boolean
208
     */
209
    public function wsHandler($ws, $path, $client, $state)
210
    {
211
        $e = explode('/', $path);
212
        $method = array_pop($e);
213
        $serverId = null;
0 ignored issues
show
$serverId 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...
214
        $sessId = null;
0 ignored issues
show
$sessId 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...
215
        if ($method !== 'websocket') {
216
            return false;
217
        }
218
        if (sizeof($e) < 3 || !isset($e[sizeof($e) - 2]) || !ctype_digit($e[sizeof($e) - 2])) {
219
            return false;
220
        }
221
        $sessId = array_pop($e);
0 ignored issues
show
$sessId 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...
222
        $serverId = array_pop($e);
0 ignored issues
show
$serverId 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...
223
        $path = implode('/', $e);
224
        $client = new WebSocketConnectionProxy($this, $client);
225
        $route = $ws->getRoute($path, $client, true);
226
        if (!$route) {
227
            $state($route);
228
            return false;
229
        }
230
        $route = new WebSocketRouteProxy($this, $route);
231
        $state($route);
232
        return true;
233
    }
234
235
    /**
236
     * beginSession
237
     * @param  string $path [@todo description]
238
     * @param  string $sessId [@todo description]
239
     * @param  string $server [@todo description]
240
     * @return object
0 ignored issues
show
Should the return type not be false|Session?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
241
     */
242
    public function beginSession($path, $sessId, $server)
243
    {
244
        $session = new Session($this, $sessId, $server);
0 ignored issues
show
$server is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
245
        foreach ($this->wss as $wss) {
246
            if ($session->route = $wss->getRoute($path, $session)) {
247
                break;
248
            }
249
        }
250
        if (!$session->route) {
251
            return false;
252
        }
253
        $this->sessions->attach($session);
254
        $session->onHandshake();
255
        return $session;
256
    }
257
258
    /**
259
     * getRouteOptions
260
     * @param  string $path [@todo description]
261
     * @return array
262
     */
263
    public function getRouteOptions($path)
264
    {
265
        $opts = [
266
            'websocket' => true,
267
            'origins' => ['*:*'],
268
            'cookie_needed' => false,
269
        ];
270
        foreach ($this->wss as $wss) {
271
            if ($wss->routeExists($path)) {
272
                foreach ($wss->getRouteOptions($path) as $k => $v) {
273
                    $opts[$k] = $v;
274
                }
275
                break;
276
            }
277
        }
278
        return $opts;
279
    }
280
281
    /**
282
     * endSession
283
     * @param Session $session
284
     * @return void
285
     */
286
    public function endSession($session)
287
    {
288
        $this->sessions->detach($session);
289
    }
290
291
    /**
292
     * Creates Request.
293
     * @param  object $req Request.
294
     * @param  object $upstream Upstream application instance.
295
     * @return object           Request.
296
     */
297
    public function beginRequest($req, $upstream)
298
    {
299
        $e = array_map('rawurldecode', explode('/', $req->attrs->server['DOCUMENT_URI']));
300
301
        $serverId = null;
302
        $sessId = null;
303
304
        /* Route discovery */
305
        $path = null;
306
        $extra = [];
307
        do {
308
            foreach ($this->wss as $wss) {
309
                $try = implode('/', $e);
310
                if ($try === '') {
311
                    $try = '/';
312
                }
313
                if ($wss->routeExists($try)) {
314
                    $path = $try;
315
                    break 2;
316
                }
317
            }
318
            array_unshift($extra, array_pop($e));
319
        } while (sizeof($e) > 0);
320
321
        if ($path === null) {
322
            return $this->callMethod('NotFound', $req, $upstream);
323
        }
324
325
        if (sizeof($extra) > 0 && end($extra) === '') {
326
            array_pop($extra);
327
        }
328
329
        $method = sizeof($extra) ? array_pop($extra) : null;
330
331
        if ($method === null) {
332
            $method = 'Welcome';
333
        } elseif ($method === 'info') {
334
        } elseif (preg_match('~^iframe(?:-([^/]*))?\.html$~', $method, $m)) {
335
            $method = 'Iframe';
336
            $version = isset($m[1]) ? $m[1] : null;
337
        } else {
338
            if (sizeof($extra) < 2) {
339
                return $this->callMethod('NotFound', $req, $upstream);
340
            }
341
            $sessId = array_pop($extra);
342
            $serverId = array_pop($extra);
343
            if ($sessId === '' || $serverId === '' || mb_orig_strpos($sessId,
344
                    '.') !== false || mb_orig_strpos($serverId, '.') !== false
345
            ) {
346
                return $this->callMethod('NotFound', $req, $upstream);
347
            }
348
        }
349
        $req->attrs->sessId = $sessId;
350
        $req->attrs->serverId = $serverId;
351
        $req->attrs->path = $path;
352
        $req = $this->callMethod($method, $req, $upstream);
353
        if ($req instanceof Methods\Iframe && mb_orig_strlen($version)) {
354
            $req->attrs->version = $version;
0 ignored issues
show
The variable $version does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
355
        }
356
        return $req;
357
    }
358
359
    /**
360
     * callMethod
361
     * @param  string $method [@todo description]
362
     * @param  object $req [@todo description]
363
     * @param  object $upstream [@todo description]
364
     * @return object
365
     */
366
    public function callMethod($method, $req, $upstream)
367
    {
368
        $method = strtr(ucwords(strtr($method, ['_' => ' '])), [' ' => '']);
369
        if (strtolower($method) === 'generic') {
370
            $method = 'NotFound';
371
        }
372
        $class = __NAMESPACE__ . '\\Methods\\' . $method;
373
        if (!class_exists($class)) {
374
            $class = __NAMESPACE__ . '\\Methods\\NotFound';
375
        }
376
        return new $class($this, $upstream, $req);
377
    }
378
379
    /**
380
     * Setting default config options
381
     * @return array|bool
382
     */
383
    protected function getConfigDefaults()
384
    {
385
        return [
386
            /* [string] @todo redis-name */
387
            'redis-name' => '',
388
389
            /* [string] @todo redis-prefix */
390
            'redis-prefix' => 'sockjs:',
391
392
            /* [string] @todo wss-name */
393
            'wss-name' => '',
394
395
            /* [Double] @todo batch-delay */
396
            'batch-delay' => new \PHPDaemon\Config\Entry\Double('0.05'),
397
398
            /* [Double] @todo heartbeat-interval */
399
            'heartbeat-interval' => new \PHPDaemon\Config\Entry\Double('25'),
400
401
            /* [Time] @todo dead-session-timeout */
402
            'dead-session-timeout' => new \PHPDaemon\Config\Entry\Time('1h'),
403
404
            /* [Size] @todo gc-max-response-size */
405
            'gc-max-response-size' => new \PHPDaemon\Config\Entry\Size('128k'),
406
407
            /* [Time] @todo network-timeout-read */
408
            'network-timeout-read' => new \PHPDaemon\Config\Entry\Time('2h'),
409
410
            /* [Time] @todo network-timeout-write */
411
            'network-timeout-write' => new \PHPDaemon\Config\Entry\Time('120s'),
412
        ];
413
    }
414
}
415