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/Methods/Generic.php (33 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\Methods;
3
4
use PHPDaemon\Core\Timer;
5
6
/**
7
 * Contains some base methods
8
 * @package Libraries
9
 * @subpackage SockJS
10
 * @author  Vasily Zorin <[email protected]>
11
 */
12
abstract class Generic extends \PHPDaemon\HTTPRequest\Generic
13
{
14
    protected $stage = 0;
15
    protected $sessId;
16
    protected $serverId;
17
    protected $path;
18
    protected $heartbeatTimer;
19
20
    protected $opts;
21
22
    protected $stopped = false;
23
24
    protected $callbackParamEnabled = false;
25
    protected $frames = [];
26
27
    protected $allowedMethods = 'GET';
28
29
    protected $errors = [
30
        1002 => 'Connection interrupted',
31
        2010 => 'Another connection still open',
32
        3000 => 'Go away!',
33
    ];
34
35
    protected $pollMode = ['stream'];
36
37
    protected $gcEnabled = true;
38
39
    protected $cacheable = false;
40
    protected $poll = false;
41
42
    protected $bytesSent = 0;
43
44
    protected $heartbeatOnFinish = false;
45
46
47
    /**
48
     * Constructor
49
     * @return void
50
     */
51
    public function init()
52
    {
53
        $this->sessId = $this->attrs->sessId;
54
        $this->serverId = $this->attrs->serverId;
55
        $this->path = $this->attrs->path;
56
57
        // @TODO: revert timeout after request
58
        $this->upstream->setTimeouts($this->appInstance->config->networktimeoutread->value,
59
            $this->appInstance->config->networktimeoutwrite->value);
60
61
        $this->opts = $this->appInstance->getRouteOptions($this->attrs->path);
0 ignored issues
show
Documentation Bug introduced by
The method getRouteOptions does not exist on object<PHPDaemon\Core\AppInstance>? 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...
62
        $this->CORS();
63
        if ($this->isFinished()) {
64
            return;
65
        }
66
        if ($this->opts['cookie_needed'] && !$this instanceof Info) {
67
            if (isset($_COOKIE['JSESSIONID'])) {
68
                $val = $_COOKIE['JSESSIONID'];
69
                if (!is_string($val) || $val === '') {
70
                    $val = 'dummy';
71
                }
72
            } else {
73
                $val = 'dummy';
74
            }
75
            $this->setcookie('JSESSIONID', $val, 0, '/');
76
        }
77
        $this->contentType($this->contentType);
0 ignored issues
show
The property contentType does not exist on object<PHPDaemon\SockJS\Methods\Generic>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
78
        if (!$this->cacheable) {
79
            $this->noncache();
80
            $this->header('X-Accel-Buffering: no');
81
        }
82
        if ($this->callbackParamEnabled) {
83
            if (!isset($_GET['c']) || !is_string($_GET['c']) || preg_match('~[^_\.a-zA-Z0-9]~', $_GET['c'])) {
84
                $this->header('500 Internal Server Error');
85
                $this->out('"callback" parameter required');
86
                $this->finish();
87
                return;
88
            }
89
        }
90
        if (($f = $this->appInstance->config->heartbeatinterval->value) > 0) {
91
            $this->heartbeatTimer = setTimeout(function ($timer) {
0 ignored issues
show
The parameter $timer 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...
92
                if (in_array('one-by-one', $this->pollMode)) {
93
                    $this->heartbeatOnFinish = true;
94
                    $this->stop();
95
                    return;
96
                }
97
                $this->sendFrame('h');
98
                if ($this->gcEnabled) {
99
                    $this->gcCheck();
100
                }
101
            }, $f * 1e6);
102
        }
103
        $this->afterHeaders();
104
        if ($this->poll) {
105
            $this->acquire(function () {
106
                $this->poll();
107
            });
108
        }
109
    }
110
111
    /**
112
     * CORS
113
     * @return void
114
     */
115
    protected function CORS()
116
    {
117
        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
118
            $this->header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
119
        }
120
        if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] !== 'null') {
121
            $this->header('Access-Control-Allow-Origin:' . $_SERVER['HTTP_ORIGIN']);
122
        } else {
123
            $this->header('Access-Control-Allow-Origin: *');
124
        }
125
        $this->header('Access-Control-Allow-Credentials: true');
126
        if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
127
            $this->header('204 No Content');
128
            $this->header('Cache-Control: max-age=31536000, public, pre-check=0, post-check=0');
129
            $this->header('Access-Control-Max-Age: 31536000');
130
            $this->header('Access-Control-Allow-Methods: OPTIONS, ' . $this->allowedMethods);
131
            $this->header('Expires: ' . date('r', strtotime('+1 year')));
132
            $this->finish();
133
        } elseif (!in_array($_SERVER['REQUEST_METHOD'], explode(', ', $this->allowedMethods), true)) {
134
            $this->header('405 Method Not Allowed');
135
            $this->finish();
136
        }
137
    }
138
139
    /**
140
     * contentType
141
     * @param  string $type Content-Type
142
     * @return void
143
     */
144
    protected function contentType($type)
145
    {
146
        $this->header('Content-Type: ' . $type . '; charset=UTF-8');
147
    }
148
149
    /**
150
     * noncache
151
     * @return void
152
     */
153
    protected function noncache()
154
    {
155
        $this->header('Pragma: no-cache');
156
        $this->header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
157
    }
158
159
    /**
160
     * Output some data
161
     * @param  string $s String to out
162
     * @param  boolean $flush
163
     * @return boolean        Success
164
     */
165
    public function out($s, $flush = true)
166
    {
167
        if ($this->heartbeatTimer !== null) {
168
            Timer::setTimeout($this->heartbeatTimer);
169
        }
170
        return parent::out($s, $flush);;
171
    }
172
173
    /**
174
     * Stop
175
     * @return void
176
     */
177
    public function stop()
178
    {
179
        if ($this->stopped) {
180
            return;
181
        }
182
        $this->stopped = true;
183
        if (in_array('one-by-one', $this->pollMode)) {
184
            $this->finish();
185
            return;
186
        }
187
        $this->appInstance->unsubscribeReal('s2c:' . $this->sessId, function ($redis) {
0 ignored issues
show
Documentation Bug introduced by
The method unsubscribeReal does not exist on object<PHPDaemon\Core\AppInstance>? 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...
The parameter $redis 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...
188
            $this->finish();
189
        });
190
    }
191
192
    /**
193
     * Send frame
194
     * @param  string $frame
195
     * @return void
196
     */
197
    protected function sendFrame($frame)
198
    {
199
        if (substr($frame, 0, 1) === 'c') {
200
            $this->finish();
201
        }
202
    }
203
204
    /**
205
     * gcCheck
206
     * @return void
207
     */
208
    public function gcCheck()
209
    {
210
        if ($this->stopped) {
211
            return;
212
        }
213
        $max = $this->appInstance->config->gcmaxresponsesize->value;
214
        if ($max > 0 && $this->bytesSent > $max) {
215
            $this->stop();
216
        }
217
    }
218
219
    /**
220
     * afterHeaders
221
     * @return void
222
     */
223
    public function afterHeaders()
224
    {
225
    }
226
227
    /**
228
     * acquire
229
     * @param  callable $cb
230
     * @callback $cb ( )
231
     * @return void
232
     */
233
    protected function acquire($cb)
234
    {
235
        $this->appInstance->getkey('error:' . $this->sessId, function ($redis) use ($cb) {
0 ignored issues
show
Documentation Bug introduced by
The method getkey does not exist on object<PHPDaemon\Core\AppInstance>? 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...
236
            if (!$redis) {
237
                $this->internalServerError();
238
                return;
239
            }
240
            if ($redis->result !== null) {
241
                $this->error((int)$redis->result);
242
                return;
243
            }
244
            if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 0) {
0 ignored issues
show
Documentation Bug introduced by
The method getLocalSubscribersCount does not exist on object<PHPDaemon\Core\AppInstance>? 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...
245
                $this->anotherConnectionStillOpen();
246
                return;
247
            }
248
            $this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use ($cb) {
0 ignored issues
show
Documentation Bug introduced by
The method publish does not exist on object<PHPDaemon\Core\AppInstance>? 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...
249
                if (!$redis) {
250
                    $this->internalServerError();
251
                    return;
252
                }
253
                if ($redis->result > 0) {
254
                    $this->anotherConnectionStillOpen();
255
                    return;
256
                }
257
                $this->appInstance->subscribe('w8in:' . $this->sessId, [$this, 'w8in'], function ($redis) use ($cb) {
0 ignored issues
show
Documentation Bug introduced by
The method subscribe does not exist on object<PHPDaemon\Core\AppInstance>? 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...
258
                    if (!$redis) {
259
                        $this->internalServerError();
260
                        return;
261
                    }
262
                    if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
0 ignored issues
show
Documentation Bug introduced by
The method getLocalSubscribersCount does not exist on object<PHPDaemon\Core\AppInstance>? 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...
263
                        $this->anotherConnectionStillOpen();
264
                        return;
265
                    }
266
                    $this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use ($cb) {
0 ignored issues
show
Documentation Bug introduced by
The method publish does not exist on object<PHPDaemon\Core\AppInstance>? 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...
267
                        if (!$redis) {
268
                            $this->internalServerError();
269
                            return;
270
                        }
271
                        if ($redis->result > 1) {
272
                            $this->anotherConnectionStillOpen();
273
                            return;
274
                        }
275
                        if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
0 ignored issues
show
Documentation Bug introduced by
The method getLocalSubscribersCount does not exist on object<PHPDaemon\Core\AppInstance>? 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...
276
                            $this->anotherConnectionStillOpen();
277
                            return;
278
                        }
279
                        $cb === null || $cb();
280
                    });
281
                });
282
            });
283
        });
284
    }
285
286
    /**
287
     * internalServerError
288
     * @return void
289
     */
290
    public function internalServerError()
291
    {
292
        $this->header('500 Internal Server Error');
293
        $this->out('"callback" parameter required');
294
        $this->finish();
295
    }
296
297
    /**
298
     * error
299
     * @param  integer $code
300
     * @return void
301
     */
302
    protected function error($code)
303
    {
304
        $this->sendFrame('c' . json_encode([$code, isset($this->errors[$code]) ? $this->errors[$code] : null]));
305
    }
306
307
    /**
308
     * anotherConnectionStillOpen
309
     * @return void
310
     */
311
    protected function anotherConnectionStillOpen()
312
    {
313
        $this->appInstance->setkey('error:' . $this->sessId, 1002, function () {
0 ignored issues
show
Documentation Bug introduced by
The method setkey does not exist on object<PHPDaemon\Core\AppInstance>? 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...
314
            $this->appInstance->expire('error:' . $this->sessId, $this->appInstance->config->deadsessiontimeout->value,
0 ignored issues
show
Documentation Bug introduced by
The method expire does not exist on object<PHPDaemon\Core\AppInstance>? 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...
315
                function () {
316
                    $this->error(2010);
317
                });
318
        });
319
    }
320
321
    /**
322
     * Poll
323
     * @param  callable $cb
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...
324
     * @callback $cb ( )
325
     * @return void
326
     */
327
    protected function poll($cb = null)
328
    {
329
        $this->appInstance->subscribe('s2c:' . $this->sessId, [$this, 's2c'], function ($redis) use ($cb) {
0 ignored issues
show
Documentation Bug introduced by
The method subscribe does not exist on object<PHPDaemon\Core\AppInstance>? 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...
The parameter $redis 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...
330
            $this->appInstance->publish('poll:' . $this->sessId, json_encode($this->pollMode),
0 ignored issues
show
Documentation Bug introduced by
The method publish does not exist on object<PHPDaemon\Core\AppInstance>? 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...
331
                function ($redis) use ($cb) {
332
                    if (!$redis) {
333
                        $cb === null || $cb();
334
                        return;
335
                    }
336
                    if ($redis->result > 0) {
337
                        $cb === null || $cb();
338
                        return;
339
                    }
340
                    $this->appInstance->setnx('sess:' . $this->sessId, $this->attrs->server['REQUEST_URI'],
0 ignored issues
show
Documentation Bug introduced by
The method setnx does not exist on object<PHPDaemon\Core\AppInstance>? 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...
341
                        function ($redis) use ($cb) {
342 View Code Duplication
                            if (!$redis || $redis->result === 0) {
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...
343
                                $this->error(3000);
344
                                $cb === null || $cb();
345
                                return;
346
                            }
347
                            $this->appInstance->expire('sess:' . $this->sessId,
0 ignored issues
show
Documentation Bug introduced by
The method expire does not exist on object<PHPDaemon\Core\AppInstance>? 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...
348
                                $this->appInstance->config->deadsessiontimeout->value, function ($redis) use ($cb) {
349 View Code Duplication
                                    if (!$redis || $redis->result === 0) {
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...
350
                                        $this->error(3000);
351
                                        $cb === null || $cb();
352
                                        return;
353
                                    }
354
                                    $this->appInstance->subscribe('state:' . $this->sessId,
0 ignored issues
show
Documentation Bug introduced by
The method subscribe does not exist on object<PHPDaemon\Core\AppInstance>? 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...
355
                                        function ($redis) use ($cb) {
356
                                            if (!$redis) {
357
                                                return;
358
                                            }
359
                                            list(, $chan, $state) = $redis->result;
0 ignored issues
show
The assignment to $chan is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
360
                                            if ($state === 'started') {
361
                                                $this->sendFrame('o');
362
                                                if (!in_array('stream', $this->pollMode)) {
363
                                                    $this->finish();
364
                                                    return;
365
                                                }
366
                                            }
367
                                            $this->appInstance->publish('poll:' . $this->sessId,
0 ignored issues
show
Documentation Bug introduced by
The method publish does not exist on object<PHPDaemon\Core\AppInstance>? 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...
368
                                                json_encode($this->pollMode), function ($redis) use ($cb) {
369 View Code Duplication
                                                    if (!$redis || $redis->result === 0) {
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...
370
                                                        $this->error(3000);
371
                                                        $cb === null || $cb();
372
                                                        return;
373
                                                    }
374
                                                    $cb === null || $cb();
375
                                                });
376
                                        }, function ($redis) use ($cb) {
0 ignored issues
show
The parameter $redis 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...
377
                                            if (!$this->appInstance->beginSession($this->path, $this->sessId,
0 ignored issues
show
Documentation Bug introduced by
The method beginSession does not exist on object<PHPDaemon\Core\AppInstance>? 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...
378
                                                $this->attrs->server)
379
                                            ) {
380
                                                $this->header('404 Not Found');
381
                                                $this->finish();
382
                                                $this->unsubscribeReal('state:' . $this->sessId);
0 ignored issues
show
Documentation Bug introduced by
The method unsubscribeReal does not exist on object<PHPDaemon\SockJS\Methods\Generic>? 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...
383
                                            }
384
                                            $cb === null || $cb();
385
                                        });
386
                                });
387
                        });
388
                });
389
        });
390
    }
391
392
    /**
393
     * Output some data
394
     * @param  string $s String to out
395
     * @param  boolean $flush
396
     * @return boolean        Success
397
     */
398
    public function outputFrame($s, $flush = true)
399
    {
400
        $this->bytesSent += mb_orig_strlen($s);
401
        return parent::out($s, $flush);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (out() instead of outputFrame()). Are you sure this is correct? If so, you might want to change this to $this->out().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
402
    }
403
404
    /**
405
     * Called when request iterated
406
     * @return void
407
     */
408
    public function run()
409
    {
410
        $this->sleep(30);
411
    }
412
413
    /**
414
     * w8in
415
     * @return void
416
     */
417
    public function w8in()
418
    {
419
    }
420
421
    /**
422
     * s2c
423
     * @param  object $redis
424
     * @return void
425
     */
426
    public function s2c($redis)
427
    {
428
        if (!$redis) {
429
            return;
430
        }
431
        list(, $chan, $msg) = $redis->result;
0 ignored issues
show
The assignment to $chan is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
432
        $frames = json_decode($msg, true);
433
        if (!is_array($frames) || !sizeof($frames)) {
434
            return;
435
        }
436
        foreach ($frames as $frame) {
437
            $this->sendFrame($frame);
438
        }
439
        if (!in_array('stream', $this->pollMode)) {
440
            $this->heartbeatOnFinish = false;
441
            $this->stop();
442
            return;
443
        }
444
        if ($this->gcEnabled) {
445
            $this->gcCheck();
446
        }
447
    }
448
449
    /**
450
     * On finish
451
     * @return void
452
     */
453
    public function onFinish()
454
    {
455
        $this->appInstance->unsubscribe('s2c:' . $this->sessId, [$this, 's2c']);
0 ignored issues
show
Documentation Bug introduced by
The method unsubscribe does not exist on object<PHPDaemon\Core\AppInstance>? 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...
456
        $this->appInstance->unsubscribe('w8in:' . $this->sessId, [$this, 'w8in']);
0 ignored issues
show
Documentation Bug introduced by
The method unsubscribe does not exist on object<PHPDaemon\Core\AppInstance>? 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...
457
        Timer::remove($this->heartbeatTimer);
458
        if ($this->heartbeatOnFinish) {
459
            $this->sendFrame('h');
460
        }
461
        parent::onFinish();
462
    }
463
}
464