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/Clients/IRC/Connection.php (30 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\Clients\IRC;
3
4
use PHPDaemon\Core\Daemon;
5
use PHPDaemon\Network\ClientConnection;
6
use PHPDaemon\Utils\IRC;
7
8
/**
9
 * @package    NetworkClients
10
 * @subpackage IRCClient
11
 * @author     Vasily Zorin <[email protected]>
12
 */
13
class Connection extends ClientConnection
14
{
15
16
    /**
17
     * @var string Username
18
     */
19
    protected $user = 'Guest';
20
21
    /**
22
     * @var string Password
23
     */
24
    protected $password = '';
25
26
    /**
27
     * @var string
28
     */
29
    public $EOL = "\r\n";
30
31
    /**
32
     * @var string
33
     */
34
    public $nick;
35
36
    /**
37
     * @var string
38
     */
39
    public $realname;
40
41
    /**
42
     * @var string
43
     */
44
    public $mode = '';
45
46
    /**
47
     * @var array
48
     */
49
    public $buffers = [];
50
51
    /**
52
     * @var string
53
     */
54
    public $servername;
55
56
    /**
57
     * @var array
58
     */
59
    public $channels = [];
60
61
    /**
62
     * @var integer
63
     */
64
    public $latency;
65
66
    /**
67
     * @var integer
68
     */
69
    public $lastPingTS;
70
71
    /**
72
     * @var int
73
     */
74
    public $timeout = 300;
75
76
    /**
77
     * @var bool To get local port number
78
     */
79
    protected $bevConnectEnabled = false;
80
81
    /**
82
     * Called when the connection is handshaked (at low-level), and peer is ready to recv. data
83
     * @return void
84
     */
85
    public function onReady()
86
    {
87
        if ($this->pool->identd) {
88
            /** @noinspection PhpParamsInspection */
89
            $this->getSocketName();
0 ignored issues
show
The call to getSocketName() misses some required arguments starting with $addr.
Loading history...
90
            $this->pool->identd->registerPair($this->locAddr, $this->locPort, ['UNIX', $this->user]);
91
        }
92
        list($this->nick, $this->realname) = explode('/', $this->path . '/John Doe');
93
        $this->command('USER', $this->user, 0, '*', $this->realname);
94
        $this->command('NICK', $this->nick);
95
        if (mb_orig_strlen($this->password)) {
96
            $this->message('NickServ', 'IDENTIFY ' . $this->password);
97
        }
98
    }
99
100
    /**
101
     * @TODO DESCR
102
     * @param  string $cmd
103
     * @param  mixed ...$args Arguments
104
     */
105
    public function command($cmd)
106
    {
107
        if (ctype_digit($cmd)) {
108
            $cmd = IRC::getCommandByCode((int)$cmd);
109
        }
110
        $line = $cmd;
111 View Code Duplication
        for ($i = 1, $s = func_num_args(); $i < $s; ++$i) {
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...
112
            $arg = func_get_arg($i);
113
            if (($i + 1 === $s) && (mb_orig_strpos($arg, "\x20") !== false)) {
114
                $line .= ' :';
115
            } else {
116
                $line .= ' ';
117
            }
118
            $line .= $arg;
119
        }
120
        $this->writeln($line);
121
        if ($this->pool->protologging) {
122
            Daemon::log('->->->-> ' . $line);
123
        }
124
    }
125
126
    /**
127
     * @TODO DESCR
128
     * @param  integer|string $cmd
129
     * @param  array $args
130
     * @return bool
131
     */
132
    public function commandArr($cmd, $args = [])
133
    {
134
        if (!is_array($args)) {
135
            return false;
136
        }
137
        if (ctype_digit($cmd)) {
138
            $cmd = IRC::getCommandByCode((int)$cmd);
139
        }
140
        $line = $cmd;
141 View Code Duplication
        for ($i = 0, $s = sizeof($args); $i < $s; ++$i) {
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...
142
            if (($i + 1 === $s) && (mb_orig_strpos($args[$i], "\x20") !== false)) {
143
                $line .= ' :';
144
            } else {
145
                $line .= ' ';
146
            }
147
            $line .= $args[$i];
148
        }
149
        $this->writeln($line);
150
        if ($this->pool->protologging && $cmd !== 'PONG') {
151
            Daemon::log('->->->-> ' . $line);
152
        }
153
        return true;
154
    }
155
156
    /**
157
     * @TODO DESCR
158
     * @param array $channels
159
     */
160
    public function join($channels)
161
    {
162
        if (!is_array($channels)) {
163
            $channels = array_map('trim', explode(',', $channels));
164
        }
165
        foreach ($channels as $chan) {
166
            $this->command('JOIN', $chan);
167
        }
168
    }
169
170
    /**
171
     * @TODO DESCR
172
     * @param array $channels
173
     * @param mixed $msg
174
     */
175
    public function part($channels, $msg = null)
176
    {
177
        $this->command('PART', $channels, $msg);
178
    }
179
180
    /**
181
     * Called when connection finishes
182
     * @return void
183
     */
184
    public function onFinish()
185
    {
186
        if ($this->pool->identd) {
187
            $this->pool->identd->unregisterPair($this->locPort, $this->port);
188
        }
189
        $this->event('disconnect');
190
        parent::onFinish();
191
    }
192
193
    /**
194
     * @TODO DESCR
195
     */
196
    public function ping()
197
    {
198
        $this->lastPingTS = microtime(true);
0 ignored issues
show
Documentation Bug introduced by
The property $lastPingTS was declared of type integer, but microtime(true) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
199
        $this->writeln('PING :' . $this->servername);
200
    }
201
202
    /**
203
     * @TODO DESCR
204
     * @param string $to
205
     * @param string $msg
206
     */
207
    public function message($to, $msg)
208
    {
209
        $this->command('PRIVMSG', $to, $msg);
210
    }
211
212
    /**
213
     * @TODO DESCR
214
     * @param string $channel
215
     * @param string $target
216
     * @param string $mode
217
     */
218
    public function addMode($channel, $target, $mode)
219
    {
220
        if ($channel) {
221
            $this->channel($channel)->addMode($target, $mode);
222
        } else {
223
            if (mb_orig_strpos($this->mode, $mode) === false) {
224
                $this->mode .= $mode;
225
            }
226
        }
227
    }
228
229
    /**
230
     * @TODO DESCR
231
     * @param string $channel
232
     * @param string $target
233
     * @param string $mode
234
     */
235
    public function removeMode($channel, $target, $mode)
236
    {
237
        if ($channel) {
238
            $this->channel($channel)->removeMode($target, $mode);
239
        }
240
        $this->mode = str_replace($mode, '', $this->mode);
241
    }
242
243
    /**
244
     * @TODO DESCR
245
     * @param string $from
246
     * @param string $cmd
247
     * @param array $args
248
     */
249
    public function onCommand($from, $cmd, $args)
250
    {
251
        $this->event('command', $from, $cmd, $args);
252
        if ($cmd === 'RPL_WELCOME') {
253
            $this->servername = $from['orig'];
254
            if ($this->onConnected) {
255
                $this->connected = true;
256
                $this->onConnected->executeAll($this);
257
                $this->onConnected = null;
258
            }
259
        } elseif ($cmd === 'NOTICE') {
260
            list($target, $text) = $args;
261
            $this->event('notice', $target, $text);
262
        } elseif ($cmd === 'RPL_YOURHOST') {
263
        } elseif ($cmd === 'RPL_MOTDSTART') {
264
            $this->motd = $args[1];
0 ignored issues
show
The property motd does not exist on object<PHPDaemon\Clients\IRC\Connection>. Since you implemented __set, maybe consider adding a @property annotation.

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

<?php

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

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

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

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

}

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

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

See also the PhpDoc documentation for @property.

Loading history...
265
            return;
266
        } elseif ($cmd === 'RPL_MOTD') {
267
            $this->motd .= "\r\n" . $args[1];
0 ignored issues
show
The property motd does not exist on object<PHPDaemon\Clients\IRC\Connection>. Since you implemented __set, maybe consider adding a @property annotation.

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

<?php

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

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

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

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

}

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

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

See also the PhpDoc documentation for @property.

Loading history...
268
            return;
269
        } elseif ($cmd === 'RPL_ENDOFMOTD') {
270
            $this->motd .= "\r\n"; // . $args[1];
0 ignored issues
show
The property motd does not exist on object<PHPDaemon\Clients\IRC\Connection>. Since you implemented __set, maybe consider adding a @property annotation.

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

<?php

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

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

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

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

}

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

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

See also the PhpDoc documentation for @property.

Loading history...
271
            $this->event('motd', $this->motd);
0 ignored issues
show
The property motd does not exist on object<PHPDaemon\Clients\IRC\Connection>. 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...
272
            return;
273
        } elseif ($cmd === 'JOIN') {
274
            list($channel) = $args;
275
            $chan = $this->channel($channel);
276
            ChannelParticipant::instance($chan, $from['nick'])->setUsermask($from);
0 ignored issues
show
$chan is of type object<PHPDaemon\Clients\IRC\Channel>, but the function expects a string.

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...
277
        } elseif ($cmd === 'NICK') {
278
            list($newNick) = $args;
279
            foreach ($this->channels as $channel) {
280
                if (isset($channel->nicknames[$from['nick']])) {
281
                    $channel->nicknames[$from['nick']]->setNick($newNick);
282
                }
283
            }
284
        } elseif ($cmd === 'QUIT') {
285
            $args[] = null;
286
            list($msg) = $args;
0 ignored issues
show
The assignment to $msg 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...
287
            foreach ($this->channels as $channel) {
288
                if (isset($channel->nicknames[$from['nick']])) {
289
                    $channel->nicknames[$from['nick']]->destroy();
290
                }
291
            }
292
        } elseif ($cmd === 'PART') {
293
            $args[] = null;
294
            list($channel, $msg) = $args;
295
            if ($chan = $this->channelIfExists($channel)) {
296
                $chan->onPart($from, $msg);
0 ignored issues
show
The method onPart cannot be called on $chan (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
297
            }
298
        } elseif ($cmd === 'RPL_NAMREPLY') {
299
            $bufName = 'RPL_NAMREPLY';
300
            list(/*$myNick*/, $chanType, $channelName) = $args;
301
            $this->channel($channelName)->setChanType($chanType);
302
            if (!isset($this->buffers[$bufName])) {
303
                $this->buffers[$bufName] = [];
304
            }
305
            if (!isset($this->buffers[$bufName][$channelName])) {
306
                $this->buffers[$bufName][$channelName] = new \SplStack;
307
            }
308
            $this->buffers[$bufName][$channelName]->push($args);
309
        } elseif ($cmd === 'RPL_ENDOFNAMES') {
310
            $bufName = 'RPL_NAMREPLY';
311
            list(/*$nick*/, $channelName, /*$text*/) = $args;
312
            if (!isset($this->buffers[$bufName][$channelName])) {
313
                return;
314
            }
315
            $buf = $this->buffers[$bufName][$channelName];
316
            $chan = null;
317
            while (!$buf->isEmpty()) {
318
                $shift = $buf->shift();
319
                list($nick, $chantype, $channelName, $participants) = $shift;
0 ignored issues
show
The assignment to $nick 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...
320
                if (!$chan) {
321
                    $chan = $this->channel($channelName)->setType($chantype);
322
                    $chan->each('destroy');
323
                }
324
                preg_match_all('~([\+%@]?)(\S+)~', $participants, $matches, PREG_SET_ORDER);
325
326
                foreach ($matches as $m) {
0 ignored issues
show
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
327
                    list(, $flag, $nickname) = $m;
328
                    ChannelParticipant::instance($chan, $nickname)->setFlag($flag);
0 ignored issues
show
$chan is of type object<PHPDaemon\Clients\IRC\Channel>, but the function expects a string.

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...
329
                }
330
            }
331
        } elseif ($cmd === 'RPL_WHOREPLY') {
332
            if (sizeof($args) < 7) {
333
            }
334
            list(/*$myNick*/, $channelName, $user, /*$host*/, $server, $nick, $mode, $hopCountRealName) = $args;
335
            list($hopCount, $realName) = explode("\x20", $hopCountRealName);
0 ignored issues
show
The assignment to $hopCount 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...
The assignment to $realName 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...
336
            if ($channel = $this->channelIfExists($channelName)) {
337
                ChannelParticipant::instance($channel, $nick)
0 ignored issues
show
$channel is of type boolean, but the function expects a string.

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...
338
                    ->setUsermask($nick . '!' . $user . '@' . $server)
339
                    ->setFlag($mode);
340
            }
341
        } elseif ($cmd === 'RPL_TOPIC') {
342
            list(/*$myNick*/, $channelName, $text) = $args;
343
            if ($channel = $this->channelIfExists($channelName)) {
344
                $channel->setTopic($text);
0 ignored issues
show
The method setTopic cannot be called on $channel (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
345
            }
346
        } elseif ($cmd === 'RPL_ENDOFWHO') {
347
            /*list($myNick, $channelName, $text) = $args;*/
348
        } elseif ($cmd === 'MODE') {
349
            if (sizeof($args) === 3) {
350
                list($channel, $mode, $target) = $args;
351
            } else {
352
                $channel = null;
353
                list($target, $mode) = $args;
354
            }
355
            if (mb_orig_strlen($mode)) {
356
                if ($mode[0] === '+') {
357
                    $this->addMode($channel, $target, mb_orig_substr($mode, 1));
358
                } elseif ($mode[0] === '-') {
359
                    $this->removeMode($channel, $target, mb_orig_substr($mode, 1));
360
                }
361
            }
362
        } elseif ($cmd === 'RPL_CREATED') {
363
            list(/*$to*/, $this->created) = $args;
0 ignored issues
show
The property created does not exist on object<PHPDaemon\Clients\IRC\Connection>. 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...
364
        } elseif ($cmd === 'RPL_MYINFO') {
365
            list(/*$to*/, $this->servername, $this->serverver, $this->availUserModes, $this->availChanModes) = $args;
0 ignored issues
show
The property serverver does not exist on object<PHPDaemon\Clients\IRC\Connection>. 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...
The property availUserModes does not exist on object<PHPDaemon\Clients\IRC\Connection>. 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...
The property availChanModes does not exist on object<PHPDaemon\Clients\IRC\Connection>. 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...
366
        } elseif ($cmd === 'PRIVMSG') {
367
            list($target, $body) = $args;
368
            $msg = [
369
                'from' => $from,
370
                'to' => $target,
371
                'body' => $body,
372
                'private' => mb_orig_substr($target, 0, 1) !== '#',
373
            ];
374
            $this->event($msg['private'] ? 'privateMsg' : 'channelMsg', $msg);
375
            $this->event('msg', $msg);
376
            if (!$msg['private']) {
377
                $this->channel($target)->event('msg', $msg);
378
            }
379
        } elseif ($cmd === 'PING') {
380
            $this->writeln(isset($args[0]) ? 'PONG :' . $args[0] : 'PONG');
381 View Code Duplication
        } elseif ($cmd === 'PONG') {
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...
382
            if ($this->lastPingTS) {
383
                $this->latency = microtime(true) - $this->lastPingTS;
0 ignored issues
show
Documentation Bug introduced by
The property $latency was declared of type integer, but microtime(true) - $this->lastPingTS is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
384
                $this->lastPingTS = null;
385
            }
386
            return;
387
        }
388
        if ($this->pool->protologging) {
389
            Daemon::$process->log('<-<-<-< ' . $cmd . ': ' . json_encode($args) . ' (' . json_encode($from['orig']) . ') (' . json_encode($this->lastLine) . ')');
0 ignored issues
show
The property lastLine does not exist on object<PHPDaemon\Clients\IRC\Connection>. 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...
390
        }
391
    }
392
393
    /**
394
     * Called when new data received
395
     * @return void
396
     */
397
    public function onRead()
398
    {
399
        while (($line = $this->readline()) !== null) {
400
            if ($line === '') {
401
                continue;
402
            }
403
            if (mb_orig_strlen($line) > 512) {
404
                Daemon::$process->log('IRCClientConnection error: buffer overflow.');
405
                $this->finish();
406
                return;
407
            }
408
            $line = mb_orig_substr($line, 0, -mb_orig_strlen($this->EOL));
409
            $p = mb_orig_strpos($line, ' :', 1);
410
            $max = $p !== false ? substr_count($line, "\x20", 0, $p + 1) + 1 : 18;
411
            $e = explode("\x20", $line, $max);
412
            $i = 0;
413
            $from = IRC::parseUsermask($e[$i][0] === ':' ? mb_orig_substr($e[$i++], 1) : null);
414
            $cmd = $e[$i++];
415
            $args = [];
416
417 View Code Duplication
            for ($s = min(sizeof($e), 14); $i < $s; ++$i) {
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...
418
                if ($e[$i][0] === ':') {
419
                    $args[] = mb_orig_substr($e[$i], 1);
420
                    break;
421
                }
422
                $args[] = $e[$i];
423
            }
424
425 View Code Duplication
            if (ctype_digit($cmd)) {
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...
426
                $code = (int)$cmd;
427
                $cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : $code;
428
            }
429
            $this->lastLine = $line;
0 ignored issues
show
The property lastLine does not exist on object<PHPDaemon\Clients\IRC\Connection>. Since you implemented __set, maybe consider adding a @property annotation.

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

<?php

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

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

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

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

}

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

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

See also the PhpDoc documentation for @property.

Loading history...
430
            $this->onCommand($from, $cmd, $args);
0 ignored issues
show
$from is of type array<string,string|bool...ring","orig":"string"}>, but the function expects a string.

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...
431
        }
432
        if (mb_orig_strlen($this->buf) > 512) {
0 ignored issues
show
The property buf does not exist on object<PHPDaemon\Clients\IRC\Connection>. 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...
433
            Daemon::$process->log('IRCClientConnection error: buffer overflow.');
434
            $this->finish();
435
        }
436
    }
437
438
    /**
439
     * @TODO DESCR
440
     * @param  string $chan
441
     * @return Channel
442
     */
443
    public function channel($chan)
444
    {
445
        if (isset($this->channels[$chan])) {
446
            return $this->channels[$chan];
447
        }
448
        return $this->channels[$chan] = new Channel($this, $chan);
449
    }
450
451
    /**
452
     * @TODO DESCR
453
     * @param  string $chan
454
     * @return bool
455
     */
456
    public function channelIfExists($chan)
457
    {
458
        if (isset($this->channels[$chan])) {
459
            return $this->channels[$chan];
460
        }
461
        return false;
462
    }
463
}
464