Completed
Push — 123 ( d13f38 )
by Vasily
05:11
created
lib/IOStream.php 4 patches
Doc Comments   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	/**
56 56
 	 * Set the size of data to read at each reading
57 57
 	 * @param integer Size
58
-	 * @return object This
58
+	 * @return IOStream This
59 59
 	 */
60 60
 	public function setReadPacketSize($n) {
61 61
 		$this->readPacketSize = $n;
@@ -231,6 +231,7 @@  discard block
 block discarded – undo
231 231
 	/**
232 232
 	 * Send data to the connection. Note that it just writes to buffer that flushes at every baseloop
233 233
 	 * @param string Data to send.
234
+	 * @param string $s
234 235
 	 * @return boolean Success.
235 236
 	 */
236 237
 	public function send($s) {
@@ -248,7 +249,7 @@  discard block
 block discarded – undo
248 249
 
249 250
 	/**
250 251
 	 * Finish the session. You shouldn't care about pending buffers, it will be flushed properly.
251
-	 * @return void
252
+	 * @return null|boolean
252 253
 	 */
253 254
 	public function finish() {
254 255
 		if ($this->finished) {
@@ -277,6 +278,7 @@  discard block
 block discarded – undo
277 278
 	 * Called when new data received
278 279
 	 * @todo +on & -> protected?
279 280
 	 * @param string New received data
281
+	 * @param string $buf
280 282
 	 * @return void
281 283
 	 */
282 284
 	public function stdin($buf) {}
@@ -396,6 +398,7 @@  discard block
 block discarded – undo
396 398
 	 * @param resource Bufferevent
397 399
 	 * @param int Events
398 400
 	 * @param mixed Attached variable
401
+	 * @param EventBufferEvent|null $bev
399 402
 	 * @return void
400 403
 	 */
401 404
 	public function onStateEvent($bev, $events) {
@@ -423,6 +426,7 @@  discard block
 block discarded – undo
423 426
 	/**
424 427
 	 * Read data from the connection's buffer
425 428
 	 * @param integer Max. number of bytes to read
429
+	 * @param integer $n
426 430
 	 * @return string Readed data
427 431
 	 */
428 432
 	public function read($n) {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
 
36 36
 	/**
37 37
 	 * IOStream constructor
38
- 	 * @param resource File descriptor.
38
+	 * @param resource File descriptor.
39 39
 	 * @param object AppInstance
40 40
 	 * @return void
41 41
 	 */
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	public $buf = '';
13 13
 	public $EOL = "\n";
14 14
 
15
-	public $readPacketSize  = 8192;
15
+	public $readPacketSize = 8192;
16 16
 	public $bev;
17 17
 	public $fd;
18 18
 	public $finished = false;
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
 	public $readLocked = false;
21 21
 	public $sending = true;
22 22
 	public $reading = false;
23
-	protected $lowMark  = 1;         // initial value of the minimal amout of bytes in buffer
24
-	protected $highMark = 0xFFFF;  	// initial value of the maximum amout of bytes in buffer
23
+	protected $lowMark  = 1; // initial value of the minimal amout of bytes in buffer
24
+	protected $highMark = 0xFFFF; // initial value of the maximum amout of bytes in buffer
25 25
 	public $priority;
26 26
 	public $inited = false;
27
-	public $state = 0;             // stream state of the connection (application protocol level)
27
+	public $state = 0; // stream state of the connection (application protocol level)
28 28
 	const STATE_ROOT = 0;
29 29
 	public $onWriteOnce;
30 30
 	public $timeout = null;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 */
206 206
 	public function write($data) {
207 207
 		if (!$this->alive) {
208
-			Daemon::log('Attempt to write to dead IOStream ('.get_class($this).')');
208
+			Daemon::log('Attempt to write to dead IOStream (' . get_class($this) . ')');
209 209
 			return false;
210 210
 		}
211 211
 		if (!isset($this->bev)) {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -401,8 +401,7 @@
 block discarded – undo
401 401
 	public function onStateEvent($bev, $events) {
402 402
 		if ($events & EventBufferEvent::CONNECTED) {
403 403
 			$this->onWriteEvent($bev);
404
-		}
405
-  		elseif ($events & (EventBufferEvent::ERROR | EventBufferEvent::EOF)) {
404
+		} elseif ($events & (EventBufferEvent::ERROR | EventBufferEvent::EOF)) {
406 405
 			try {
407 406
 				$this->close();
408 407
 				if ($this->finished) {
Please login to merge, or discard this patch.
lib/IRCBouncer.php 4 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -175,6 +175,10 @@  discard block
 block discarded – undo
175 175
 		Timer::setTimeout($this->keepaliveTimer);
176 176
 	}
177 177
 
178
+	/**
179
+	 * @param null|string $from
180
+	 * @param string $cmd
181
+	 */
178 182
 	public function command($from, $cmd) {
179 183
 		if ($from === null) {
180 184
 			$from = $this->pool->config->servername->value;
@@ -326,6 +330,9 @@  discard block
 block discarded – undo
326 330
 		}
327 331
 	}
328 332
 
333
+	/**
334
+	 * @param string $msg
335
+	 */
329 336
 	public function msgFromBNC($msg) {
330 337
 		if ($this->usermask === null) {
331 338
 			return;
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -337,7 +337,7 @@
 block discarded – undo
337 337
 	 * Called when new data received
338 338
 	 * @param string New data
339 339
 	 * @return void
340
-	*/
340
+	 */
341 341
 	public function stdin($buf) {
342 342
 		Timer::setTimeout($this->keepaliveTimer);
343 343
 		$this->buf .= $buf;
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
 
58 58
 	public function getConnection($url) {
59 59
 		$pool = $this;
60
-		$this->client->getConnection($url, function ($conn) use ($pool, $url) {
60
+		$this->client->getConnection($url, function($conn) use ($pool, $url) {
61 61
 			$pool->conn = $conn;
62 62
 			$conn->attachedClients = new ObjectStorage;
63 63
 			if ($conn->connected) {
64
-				Daemon::log('IRC bot connected at '.$url);
64
+				Daemon::log('IRC bot connected at ' . $url);
65 65
 				$conn->join($pool->config->defaultchannels->value);
66 66
 				$conn->bind('motd', function($conn) {
67 67
 					//Daemon::log($conn->motd);
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 					$conn->attachedClients->each('commandArr', $from['orig'], $cmd, $args);
85 85
 				});
86 86
 				$conn->bind('privateMsg', function($conn, $msg) {
87
-					Daemon::log('IRCBouncer: got private message \''.$msg['body'].'\' from \''.$msg['from']['orig'].'\'');
87
+					Daemon::log('IRCBouncer: got private message \'' . $msg['body'] . '\' from \'' . $msg['from']['orig'] . '\'');
88 88
 				});
89 89
 				$conn->bind('msg', function($conn, $msg) use ($pool) {
90 90
 					$msg['ts'] = microtime(true);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 				});
102 102
 			}
103 103
 			else {
104
-				Daemon::log('IRCBouncer: unable to connect ('.$url.')');
104
+				Daemon::log('IRCBouncer: unable to connect (' . $url . ')');
105 105
 			}
106 106
 		});
107 107
 	}
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
 	public function ping() {
173 173
 		$this->lastPingTS = microtime(true);
174
-		$this->writeln('PING :'.$this->usermask);
174
+		$this->writeln('PING :' . $this->usermask);
175 175
 		Timer::setTimeout($this->keepaliveTimer);
176 176
 	}
177 177
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 		}
193 193
 		$this->writeln($line);
194 194
 		if ($this->pool->protologging && !in_array($cmd, array('PONG'))) {
195
-			Daemon::log('=>=>=>=> '.json_encode($line));
195
+			Daemon::log('=>=>=>=> ' . json_encode($line));
196 196
 		}
197 197
 	}
198 198
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 			$from = $this->pool->config->servername->value;
202 202
 		}
203 203
 		if (is_string($args)) {
204
-			Daemon::log(get_class($this).'->commandArr: args is string');
204
+			Daemon::log(get_class($this) . '->commandArr: args is string');
205 205
 			return;
206 206
 		}
207 207
 		$cmd = IRC::getCodeByCommand($cmd);
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 		}
217 217
 		$this->writeln($line);
218 218
 		if ($this->pool->protologging && !in_array($cmd, array('PONG'))) {
219
-			Daemon::log('=>=>=>=> '.json_encode($line));
219
+			Daemon::log('=>=>=>=> ' . json_encode($line));
220 220
 		}
221 221
 	}
222 222
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		} else {
235 235
 			return;
236 236
 		}
237
-		$this->msgFromBNC('Attached to '.$this->attachedServer->url);
237
+		$this->msgFromBNC('Attached to ' . $this->attachedServer->url);
238 238
 		$this->usermask = $this->attachedServer->nick . '!' . $this->attachedServer->user . '@' . $this->pool->config->servername->value;
239 239
 		$this->command(null, 'RPL_WELCOME', $this->attachedServer->nick, 'Welcome to phpDaemon bouncer -- ' . $this->pool->config->servername->value);
240 240
 		foreach ($this->attachedServer->channels as $chan) {
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 					}
307 307
 
308 308
 				} else {
309
-					$this->msgFromBNC('Unknown command: '.$msg);
309
+					$this->msgFromBNC('Unknown command: ' . $msg);
310 310
 				}
311 311
 				return;
312 312
 			}
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 			$this->attachedServer->commandArr($cmd, $args);
323 323
 		}
324 324
 		if ($this->protologging) {
325
-			Daemon::$process->log('<=<=<=< '.$cmd.': '.json_encode($args));
325
+			Daemon::$process->log('<=<=<=< ' . $cmd . ': ' . json_encode($args));
326 326
 		}
327 327
 	}
328 328
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 		if ($this->usermask === null) {
331 331
 			return;
332 332
 		}
333
-		$this->command('$!@' . $this->pool->config->servername->value, 'PRIVMSG' , $this->usermask, $msg);
333
+		$this->command('$!@' . $this->pool->config->servername->value, 'PRIVMSG', $this->usermask, $msg);
334 334
 	}
335 335
 
336 336
 	/**
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 
369 369
 			if (ctype_digit($cmd)) {
370 370
 				$code = (int) $cmd;
371
-				$cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : 'UNKNOWN-'.$code;
371
+				$cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : 'UNKNOWN-' . $code;
372 372
 			}
373 373
 			$this->onCommand($cmd, $args);
374 374
 		}
Please login to merge, or discard this patch.
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -74,8 +74,7 @@  discard block
 block discarded – undo
74 74
 				$conn->bind('command', function($conn, $from, $cmd, $args) use ($pool) {
75 75
 					if ($cmd === 'PONG') {
76 76
 						return;
77
-					}
78
-					elseif ($cmd === 'PING') {
77
+					} elseif ($cmd === 'PING') {
79 78
 						return;
80 79
 					}
81 80
 					if ($from['orig'] === $conn->servername) {
@@ -99,8 +98,7 @@  discard block
 block discarded – undo
99 98
 					}
100 99
 					$pool->getConnection($url);
101 100
 				});
102
-			}
103
-			else {
101
+			} else {
104 102
 				Daemon::log('IRCBouncer: unable to connect ('.$url.')');
105 103
 			}
106 104
 		});
@@ -264,42 +262,34 @@  discard block
 block discarded – undo
264 262
 			list ($nick) = $args;
265 263
 			$this->attachTo();
266 264
 			return;
267
-		}
268
-		elseif ($cmd === 'QUIT') {
265
+		} elseif ($cmd === 'QUIT') {
269 266
 			$this->finish();
270 267
 			return;
271
-		}
272
-		elseif ($cmd === 'PING') {
268
+		} elseif ($cmd === 'PING') {
273 269
 			$this->writeln(isset($args[0]) ? 'PONG :' . $args[0] : 'PONG');
274 270
 			return;
275
-		}
276
-		elseif ($cmd === 'PONG') {
271
+		} elseif ($cmd === 'PONG') {
277 272
 			if ($this->lastPingTS) {
278 273
 				$this->latency = microtime(true) - $this->lastPingTS;
279 274
 				$this->lastPingTS = null;
280 275
 				$this->event('lantency');
281 276
 			}
282 277
 			return;
283
-		}
284
-		elseif ($cmd === 'NICK') {
278
+		} elseif ($cmd === 'NICK') {
285 279
 			return;
286
-		}
287
-		elseif ($cmd === 'PRIVMSG') {
280
+		} elseif ($cmd === 'PRIVMSG') {
288 281
 			list ($target, $msg) = $args;
289 282
 			if ($target === '$') {
290 283
 				if (preg_match('~^\s*(NICK\s+\S+|DETACH|ATTACH|BYE)\s*$~i', $msg, $m)) {
291 284
 					$clientCmd = strtoupper($m[1]);
292 285
 					if ($clientCmd === 'NICK') {
293 286
 
294
-					}
295
-					elseif ($clientCmd === 'DETACH') {
287
+					} elseif ($clientCmd === 'DETACH') {
296 288
 						$this->detach();
297 289
 						$this->msgFromBNC('Detached.');
298
-					}
299
-					elseif ($clientCmd === 'ATTACH') {
290
+					} elseif ($clientCmd === 'ATTACH') {
300 291
 						$this->attachTo();
301
-					}
302
-					elseif ($clientCmd === 'BYE') {
292
+					} elseif ($clientCmd === 'BYE') {
303 293
 						$this->detach();
304 294
 						$this->msgFromBNC('Bye-bye.');
305 295
 						$this->finish();
Please login to merge, or discard this patch.
lib/IRCClient.php 4 patches
Doc Comments   +17 added lines patch added patch discarded remove patch
@@ -59,6 +59,9 @@  discard block
 block discarded – undo
59 59
 		}
60 60
 	}
61 61
 
62
+	/**
63
+	 * @param string $cmd
64
+	 */
62 65
 	public function command($cmd) {
63 66
 		if (ctype_digit($cmd)) {
64 67
 			$cmd = IRC::getCommandByCode((int) $cmd);
@@ -134,6 +137,10 @@  discard block
 block discarded – undo
134 137
 		$this->writeln('PING :'.$this->servername);
135 138
 	}
136 139
 
140
+	/**
141
+	 * @param string $to
142
+	 * @param string $msg
143
+	 */
137 144
 	public function message($to, $msg) {
138 145
 		$this->command('PRIVMSG', $to, $msg);
139 146
 	}
@@ -172,6 +179,9 @@  discard block
 block discarded – undo
172 179
 		}
173 180
 	}
174 181
 
182
+	/**
183
+	 * @param string $mode
184
+	 */
175 185
 	public function addMode($channel, $target, $mode) {
176 186
 		if ($channel) {
177 187
 			$this->channel($channel)->addMode($target, $mode);
@@ -182,6 +192,9 @@  discard block
 block discarded – undo
182 192
 		}
183 193
 	}
184 194
 
195
+	/**
196
+	 * @param string $mode
197
+	 */
185 198
 	public function removeMode($channel, $target, $mode) {
186 199
 		if ($channel) {
187 200
 			$this->channel($channel)->removeMode($target, $mode);
@@ -421,6 +434,10 @@  discard block
 block discarded – undo
421 434
 	public $self;
422 435
 	public $type;
423 436
 	public $topic;
437
+
438
+	/**
439
+	 * @param IRCClientConnection $irc
440
+	 */
424 441
 	public function __construct($irc, $name) {
425 442
 		$this->irc = $irc;
426 443
 		$this->name = $name;
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -357,7 +357,7 @@
 block discarded – undo
357 357
 	 * Called when new data received
358 358
 	 * @param string New data
359 359
 	 * @return void
360
-	*/
360
+	 */
361 361
 	public function stdin($buf) {
362 362
 		$this->buf .= $buf;
363 363
 		while (($line = $this->gets()) !== false) {
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 }
29 29
 
30 30
 class IRCClientConnection extends NetworkClientConnection {
31
-	public $user 			= 'Guest';     // Username
32
-	public $password 		= '';         // Password
33
-	public $EOL				= "\r\n";
31
+	public $user = 'Guest'; // Username
32
+	public $password = ''; // Password
33
+	public $EOL = "\r\n";
34 34
 	public $nick;
35 35
 	public $realname;
36 36
 	public $eventHandlers = array();
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public function onReady() {
51 51
 		if ($this->pool->identd) {
52
-			$this->pool->identd->registerPair($this->locPort, $this->port, 'UNIX : '.$this->user);
52
+			$this->pool->identd->registerPair($this->locPort, $this->port, 'UNIX : ' . $this->user);
53 53
 		}
54 54
 		list($this->nick, $this->realname) = explode('/', $this->path . '/John Doe');
55 55
 		$this->command('USER', $this->user, 0, '*', $this->realname);
56 56
 		$this->command('NICK', $this->nick);
57 57
 		if (strlen($this->password)) {
58
-			$this->message('NickServ', 'IDENTIFY '.$this->password);
58
+			$this->message('NickServ', 'IDENTIFY ' . $this->password);
59 59
 		}
60 60
 	}
61 61
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 		}
77 77
 		$this->writeln($line);
78 78
 		if ($this->pool->protologging) {
79
-			Daemon::log('->->->-> '.$line);
79
+			Daemon::log('->->->-> ' . $line);
80 80
 		}
81 81
 	}
82 82
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 		}
100 100
 		$this->writeln($line);
101 101
 		if ($this->pool->protologging && !in_array($cmd, array('PONG'))) {
102
-			Daemon::log('->->->-> '.$line);
102
+			Daemon::log('->->->-> ' . $line);
103 103
 		}
104 104
 	}
105 105
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 
132 132
 	public function ping() {
133 133
 		$this->lastPingTS = microtime(true);
134
-		$this->writeln('PING :'.$this->servername);
134
+		$this->writeln('PING :' . $this->servername);
135 135
 	}
136 136
 
137 137
 	public function message($to, $msg) {
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 			return;
216 216
 		}
217 217
 		elseif ($cmd === 'RPL_ENDOFMOTD') {
218
-			$this->motd .= "\r\n";// . $args[1];
218
+			$this->motd .= "\r\n"; // . $args[1];
219 219
 			$this->event('motd', $this->motd);
220 220
 			return;
221 221
 		}
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 			}
340 340
 		}
341 341
 		elseif ($cmd === 'PING') {
342
-			$this->writeln(isset($args[0]) ? 'PONG :'.$args[0] : 'PONG');
342
+			$this->writeln(isset($args[0]) ? 'PONG :' . $args[0] : 'PONG');
343 343
 		}
344 344
 		elseif ($cmd === 'PONG') {
345 345
 			if ($this->lastPingTS) {
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 			return;
350 350
 		}
351 351
 		if ($this->pool->protologging) {
352
-			Daemon::$process->log('<-<-<-< '.$cmd.': '.json_encode($args). ' ('.json_encode($from['orig']).') (' . json_encode($this->lastLine) . ')');
352
+			Daemon::$process->log('<-<-<-< ' . $cmd . ': ' . json_encode($args) . ' (' . json_encode($from['orig']) . ') (' . json_encode($this->lastLine) . ')');
353 353
 		}
354 354
 	}
355 355
 
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 		$this->channel->detach($this);
627 627
 	}
628 628
 	public function chanMessage($msg) {
629
-		$this->channel->message($this->nick.': '.$msg);
629
+		$this->channel->message($this->nick . ': ' . $msg);
630 630
 	}
631 631
 }
632 632
 
Please login to merge, or discard this patch.
Braces   +26 added lines, -52 removed lines patch added patch discarded remove patch
@@ -68,8 +68,7 @@  discard block
 block discarded – undo
68 68
 			$arg = func_get_arg($i);
69 69
 			if (($i + 1 === $s) && (strpos($arg, "\x20") !== false)) {
70 70
 				$line .= ' :';
71
-			}
72
-			else {
71
+			} else {
73 72
 				$line .= ' ';
74 73
 			}
75 74
 			$line .= $arg;
@@ -91,8 +90,7 @@  discard block
 block discarded – undo
91 90
 		for ($i = 0, $s = sizeof($args); $i < $s; ++$i) {
92 91
 			if (($i + 1 === $s) && (strpos($args[$i], "\x20") !== false)) {
93 92
 				$line .= ' :';
94
-			}
95
-			else {
93
+			} else {
96 94
 				$line .= ' ';
97 95
 			}
98 96
 			$line .= $args[$i];
@@ -198,41 +196,33 @@  discard block
 block discarded – undo
198 196
 				$this->onConnected->executeAll($this);
199 197
 				$this->onConnected = null;
200 198
 			}
201
-		}
202
-		elseif ($cmd === 'NOTICE') {
199
+		} elseif ($cmd === 'NOTICE') {
203 200
 			list ($target, $text) = $args;
204 201
 			$log = true;
205 202
 			$this->event('notice', $target, $text);
206
-		}
207
-		elseif ($cmd == 'RPL_YOURHOST') {
208
-		}
209
-		elseif ($cmd === 'RPL_MOTDSTART') {
203
+		} elseif ($cmd == 'RPL_YOURHOST') {
204
+		} elseif ($cmd === 'RPL_MOTDSTART') {
210 205
 			$this->motd = $args[1];
211 206
 			return;
212
-		}
213
-		elseif ($cmd === 'RPL_MOTD') {
207
+		} elseif ($cmd === 'RPL_MOTD') {
214 208
 			$this->motd .= "\r\n" . $args[1];
215 209
 			return;
216
-		}
217
-		elseif ($cmd === 'RPL_ENDOFMOTD') {
210
+		} elseif ($cmd === 'RPL_ENDOFMOTD') {
218 211
 			$this->motd .= "\r\n";// . $args[1];
219 212
 			$this->event('motd', $this->motd);
220 213
 			return;
221
-		}
222
-		elseif ($cmd === 'JOIN') {
214
+		} elseif ($cmd === 'JOIN') {
223 215
 			list ($channel) = $args;
224 216
 			$chan = $this->channel($channel);
225 217
 			IRCClientChannelParticipant::instance($chan, $from['nick'])->setUsermask($from);
226
-		}
227
-		elseif ($cmd === 'NICK') {
218
+		} elseif ($cmd === 'NICK') {
228 219
 			list ($newNick) = $args;
229 220
 			foreach ($this->channels as $channel) {
230 221
 				if (isset($channel->nicknames[$from['nick']])) {
231 222
 					$channel->nicknames[$from['nick']]->setNick($newNick);
232 223
 				}
233 224
 			}
234
-		}
235
-		elseif ($cmd === 'QUIT') {
225
+		} elseif ($cmd === 'QUIT') {
236 226
 			$args[] = null;
237 227
 			list ($msg) = $args;
238 228
 			foreach ($this->channels as $channel) {
@@ -240,15 +230,13 @@  discard block
 block discarded – undo
240 230
 					$channel->nicknames[$from['nick']]->destroy();
241 231
 				}
242 232
 			}
243
-		}
244
-		elseif ($cmd === 'PART') {
233
+		} elseif ($cmd === 'PART') {
245 234
 			$args[] = null;
246 235
 			list ($channel, $msg) = $args;
247 236
 			if ($chan = $this->channelIfExists($channel)) {
248 237
 				$chan->onPart($from, $msg);
249 238
 			}
250
-		}
251
-		elseif ($cmd === 'RPL_NAMREPLY') {
239
+		} elseif ($cmd === 'RPL_NAMREPLY') {
252 240
 			$bufName = 'RPL_NAMREPLY';
253 241
 			list($myNick, $chanType, $channelName) = $args;
254 242
 			$this->channel($channelName)->setChanType($chanType);
@@ -259,8 +247,7 @@  discard block
 block discarded – undo
259 247
 				$this->buffers[$bufName][$channelName] = new SplStack;
260 248
 			}
261 249
 			$this->buffers[$bufName][$channelName]->push($args);
262
-		}
263
-		elseif ($cmd === 'RPL_ENDOFNAMES') {
250
+		} elseif ($cmd === 'RPL_ENDOFNAMES') {
264 251
 			$bufName = 'RPL_NAMREPLY';
265 252
 			list($nick, $channelName, $text) = $args;
266 253
 			if (!isset($this->buffers[$bufName][$channelName])) {
@@ -283,8 +270,7 @@  discard block
 block discarded – undo
283 270
 				}
284 271
 
285 272
 			}
286
-		}
287
-		elseif ($cmd === 'RPL_WHOREPLY') {
273
+		} elseif ($cmd === 'RPL_WHOREPLY') {
288 274
 			if (sizeof($args) < 7) {
289 275
 
290 276
 			}
@@ -295,17 +281,14 @@  discard block
 block discarded – undo
295 281
 				->setUsermask($nick . '!' . $user . '@' . $server)
296 282
 				->setFlag($mode);
297 283
 			}
298
-		}
299
-		elseif ($cmd === 'RPL_TOPIC') {
284
+		} elseif ($cmd === 'RPL_TOPIC') {
300 285
 			list($myNick, $channelName, $text) = $args;
301 286
 			if ($channel = $this->channelIfExists($channelName)) {
302 287
 				$channel->setTopic($text);
303 288
 			}	
304
-		}
305
-		elseif ($cmd === 'RPL_ENDOFWHO') {
289
+		} elseif ($cmd === 'RPL_ENDOFWHO') {
306 290
 			list($myNick, $channelName, $text) = $args;
307
-		}
308
-		elseif ($cmd === 'MODE') {
291
+		} elseif ($cmd === 'MODE') {
309 292
 			if (sizeof($args) === 3) {
310 293
 				list ($channel, $mode, $target) = $args;
311 294
 			} else {
@@ -317,14 +300,11 @@  discard block
 block discarded – undo
317 300
 			} elseif ($mode[0] === '-') {
318 301
 				$this->removeMode($channel, $target, binarySubstr($mode, 1));
319 302
 			}
320
-		}
321
-		elseif ($cmd === 'RPL_CREATED') {
303
+		} elseif ($cmd === 'RPL_CREATED') {
322 304
 			list($to, $this->created) = $args;
323
-		}
324
-		elseif ($cmd === 'RPL_MYINFO') {
305
+		} elseif ($cmd === 'RPL_MYINFO') {
325 306
 			list($to, $this->servername, $this->serverver, $this->availUserModes, $this->availChanModes) = $args;
326
-		}
327
-		elseif ($cmd === 'PRIVMSG') {
307
+		} elseif ($cmd === 'PRIVMSG') {
328 308
 			list ($target, $body) = $args;
329 309
 			$msg = array(
330 310
 				'from' => $from,
@@ -337,11 +317,9 @@  discard block
 block discarded – undo
337 317
 			if (!$msg['private']) {
338 318
 				$this->channel($target)->event('msg', $msg);
339 319
 			}
340
-		}
341
-		elseif ($cmd === 'PING') {
320
+		} elseif ($cmd === 'PING') {
342 321
 			$this->writeln(isset($args[0]) ? 'PONG :'.$args[0] : 'PONG');
343
-		}
344
-		elseif ($cmd === 'PONG') {
322
+		} elseif ($cmd === 'PONG') {
345 323
 			if ($this->lastPingTS) {
346 324
 				$this->latency = microtime(true) - $this->lastPingTS;
347 325
 				$this->lastPingTS = null;
@@ -544,11 +522,9 @@  discard block
 block discarded – undo
544 522
 		$this->flag = $flag;
545 523
 		if ($flag === '@') {
546 524
 			$this->mode = 'o';
547
-		}
548
-		elseif ($flag === '%') {
525
+		} elseif ($flag === '%') {
549 526
 			$this->mode = 'h';
550
-		}
551
-		elseif ($flag === '+') {
527
+		} elseif ($flag === '+') {
552 528
 			$this->mode = 'v';
553 529
 		}
554 530
 		return $this;
@@ -562,11 +538,9 @@  discard block
 block discarded – undo
562 538
 	public function onModeUpdate() {
563 539
 		if (strpos($this->mode, 'o') !== false) {
564 540
 			$this->flag = '@';
565
-		}
566
-		elseif (strpos($this->mode, 'h') !== false) {
541
+		} elseif (strpos($this->mode, 'h') !== false) {
567 542
 			$this->flag = '%';
568
-		}
569
-		elseif (strpos($this->mode, 'v') !== false) {
543
+		} elseif (strpos($this->mode, 'v') !== false) {
570 544
 			$this->flag = '+';
571 545
 		} else {
572 546
 			$this->flag = '';
Please login to merge, or discard this patch.
lib/LockServer.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -66,6 +66,7 @@
 block discarded – undo
66 66
 	 * Called when client sends done- or failed-event.	
67 67
 	 * @param string Name of job.
68 68
 	 * @param string Result.
69
+	 * @param string $result
69 70
 	 * @return string Result.
70 71
 	 */
71 72
 	public function done($name, $result) {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class LockServer extends NetworkServer {
10 10
 	
11
-	public $lockState = array();      // Jobs
12
-	public $lockConnState = array();  // Array of connection's state
11
+	public $lockState = array(); // Jobs
12
+	public $lockConnState = array(); // Array of connection's state
13 13
 
14 14
 	/**
15 15
 	 * Setting default config options
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 
33 33
 }
34 34
 class LockServerConnection extends Connection {
35
-	public $server = FALSE;   // Is this S2S-session?
36
-	public $locks = array();  // State of locks.
35
+	public $server = FALSE; // Is this S2S-session?
36
+	public $locks = array(); // State of locks.
37 37
 
38 38
 	/**
39 39
 	 * Called when client is trying to acquire lock.	
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			elseif ($e[0] !== '') {
138 138
 				$this->writeln('PROTOCOL_ERROR');
139 139
 			}
140
-			if($this->pool->config->protologging->value) {
140
+			if ($this->pool->config->protologging->value) {
141 141
 				Daemon::log('Lock client --> Lock server: ' . Debug::exportBytes(implode(' ', $e)) . "\n");
142 142
 			}
143 143
 		}
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -99,8 +99,7 @@  discard block
 block discarded – undo
99 99
 		foreach ($this->locks as $name => $status) {
100 100
 			if ($status === 1) {
101 101
 				$this->done($name, 'FAILED');
102
-			}
103
-			elseif ($status === 2) {
102
+			} elseif ($status === 2) {
104 103
 				unset($this->pool->lockConnState[$name][$this->connId]);
105 104
 			}
106 105
 		}
@@ -121,20 +120,15 @@  discard block
 block discarded – undo
121 120
 
122 121
 			if ($e[0] === 'acquire') {
123 122
 				$this->writeln($this->acquireLock($e[1]) . ' ' . $e[1]);
124
-			}
125
-			elseif ($e[0] === 'acquireWait') {
123
+			} elseif ($e[0] === 'acquireWait') {
126 124
 				$this->writeln($this->acquireLock($e[1], TRUE) . ' ' . $e[1]);
127
-			}
128
-			elseif ($e[0] === 'done') {
125
+			} elseif ($e[0] === 'done') {
129 126
 				$this->done($e[1], 'DONE'); 
130
-			}
131
-			elseif ($e[0] === 'failed') {
127
+			} elseif ($e[0] === 'failed') {
132 128
 				$this->done($e[1], 'FAILED');
133
-			}
134
-			elseif ($e[0] === 'quit') {
129
+			} elseif ($e[0] === 'quit') {
135 130
 				$this->finish();
136
-			}
137
-			elseif ($e[0] !== '') {
131
+			} elseif ($e[0] !== '') {
138 132
 				$this->writeln('PROTOCOL_ERROR');
139 133
 			}
140 134
 			if($this->pool->config->protologging->value) {
Please login to merge, or discard this patch.
lib/MongoClientAsync.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -81,6 +81,9 @@
 block discarded – undo
81 81
 	 * @param integer Opcode (see constants above)
82 82
 	 * @param string Data
83 83
 	 * @param boolean Is an answer expected?
84
+	 * @param string $key
85
+	 * @param integer $opcode
86
+	 * @param string $data
84 87
 	 * @return integer Request ID
85 88
 	 * @throws MongoClientAsyncConnectionFinished
86 89
 	 */
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -859,9 +859,9 @@
 block discarded – undo
859 859
 		if (strpos($col, '.') === false) {
860 860
 			$col = $this->dbname . '.' . $col;
861 861
 		} else {
862
-            $collName = explode('.', $col);
863
-            $this->dbname = $collName[0];
864
-        }
862
+			$collName = explode('.', $col);
863
+			$this->dbname = $collName[0];
864
+		}
865 865
 
866 866
 		if (isset($this->collections[$col])) {
867 867
 			return $this->collections[$col];
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@  discard block
 block discarded – undo
10 10
 	
11 11
 	public $requests    = array(); // Pending requests
12 12
 	public $cursors     = array(); // Active cursors
13
-	public $lastReqId   = 0;       // ID of the last request
13
+	public $lastReqId   = 0; // ID of the last request
14 14
 	public $collections = array(); // Objects of MongoClientAsyncCollection
15
-	public $dbname      = '';      // Current database
16
-	public $lastRequestConnection;    // Holds last used MongoClientAsyncConnection object.
15
+	public $dbname      = ''; // Current database
16
+	public $lastRequestConnection; // Holds last used MongoClientAsyncConnection object.
17 17
 
18 18
 	/* Codes of operations */
19 19
 	const OP_REPLY        = 1; 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	const OP_DELETE       = 2006;
26 26
 	const OP_KILL_CURSORS = 2007;
27 27
 
28
-	public $cache;                 // object of MemcacheClient
28
+	public $cache; // object of MemcacheClient
29 29
 
30 30
 	/**
31 31
 	 * Setting default config options
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	public function request($key, $opcode, $data, $reply = false) {
88 88
 		$reqId = ++$this->lastReqId;
89
-		$cb = function ($conn) use ($opcode, $data, $reply, $reqId) {
89
+		$cb = function($conn) use ($opcode, $data, $reply, $reqId) {
90 90
 			if (!$conn->connected) {
91 91
 				throw new MongoClientConnectionAsyncFinished;
92 92
 			}
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	public function findOne($p, $callback, $key = '') {
218 218
 		if (isset($p['cachekey'])) {
219 219
 			$db = $this;
220
-			$this->cache->get($p['cachekey'], function($r) use ($db,  $p,  $callback,  $key) {
220
+			$this->cache->get($p['cachekey'], function($r) use ($db, $p, $callback, $key) {
221 221
 				if ($r->result !== NULL) {
222 222
 					call_user_func($callback, bson_decode($r->result));
223 223
 				} else {
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 		}
616 616
 		
617 617
 		if (strpos($p['col'], '.') === false) {
618
-			$p['col'] = $this->dbname.'.'.$p['col'];
618
+			$p['col'] = $this->dbname . '.' . $p['col'];
619 619
 		}
620 620
 		
621 621
 		$e = explode('.', $p['col']);
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 		);
631 631
 		
632 632
 		if (isset($p[$k = 'cond'])) {
633
-			$query['group'][$k]= $p[$k];
633
+			$query['group'][$k] = $p[$k];
634 634
 		}
635 635
 		
636 636
 		if (isset($p[$k = 'finalize'])) {
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 	 * @param string Optional. Distribution key.
726 726
 	 * @return object MongoId
727 727
 	 */
728
-	public function insert($col, $doc = array(), $cb = NULL,  $key = '') {
728
+	public function insert($col, $doc = array(), $cb = NULL, $key = '') {
729 729
 		if (strpos($col, '.') === false) {
730 730
 			$col = $this->dbname . '.' . $col;
731 731
 		}
Please login to merge, or discard this patch.
Braces   +4 added lines, -10 removed lines patch added patch discarded remove patch
@@ -176,9 +176,7 @@  discard block
 block discarded – undo
176 176
 			
177 177
 				if ($k === 'sort') {
178 178
 					$o['orderby'] = $v;
179
-				}
180
-				elseif ($k === 'parse_oplog') {}
181
-				else {
179
+				} elseif ($k === 'parse_oplog') {} else {
182 180
 					$o[$k] = $v;
183 181
 				}
184 182
 			}
@@ -277,9 +275,7 @@  discard block
 block discarded – undo
277 275
 		
278 276
 				if ($k === 'sort') {
279 277
 					$o['orderby'] = $v;
280
-				}
281
-				elseif ($k === 'parse_oplog') {}
282
-				else {
278
+				} elseif ($k === 'parse_oplog') {} else {
283 279
 					$o[$k] = $v;
284 280
 				}
285 281
 			}
@@ -340,8 +336,7 @@  discard block
 block discarded – undo
340 336
 
341 337
 		if (is_string($p['where'])) {
342 338
 			$query['where'] = new MongoCode($p['where']);
343
-		}
344
-		elseif (
339
+		} elseif (
345 340
 			is_object($p['where']) 
346 341
 			|| sizeof($p['where'])
347 342
 		) {
@@ -481,8 +476,7 @@  discard block
 block discarded – undo
481 476
 		
482 477
 		if (is_string($p['where'])) {
483 478
 			$query['where'] = new MongoCode($p['where']);
484
-		}
485
-		elseif (
479
+		} elseif (
486 480
 			is_object($p['where']) 
487 481
 			|| sizeof($p['where'])
488 482
 		) {
Please login to merge, or discard this patch.
lib/MongoClientAsyncCollection.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -10,6 +10,7 @@  discard block
 block discarded – undo
10 10
 	 * Contructor of MongoClientAsyncCollection
11 11
 	 * @param string Name of collection
12 12
 	 * @param object Pool
13
+	 * @param MongoClientAsync $pool
13 14
 	 * @return void
14 15
 	 */
15 16
 	public function __construct($name, $pool) {
@@ -143,6 +144,8 @@  discard block
 block discarded – undo
143 144
      * @param string Code
144 145
      * @param mixed Callback called when response received
145 146
      * @param string Optional. Distribution key
147
+     * @param string $code
148
+     * @param Closure $cb
146 149
      * @return void
147 150
      */
148 151
     public function evaluate($code, $cb, $key = '')
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class MongoClientAsyncCollection {
3
-    /**
4
-     * @var MongoClient
5
-     */
3
+	/**
4
+	 * @var MongoClient
5
+	 */
6 6
 	public $pool;
7 7
 	public $name; // Name of collection.
8 8
 
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * @param array Hash of properties (offset,   opts,  where,  col,  fields,  sort,  hint,  explain,  snapshot,  orderby,  parse_oplog)
37 37
 	 * @param string Optional. Distribution key.
38 38
 	 * @return void
39
- 	*/
39
+	 */
40 40
 	public function findOne($cb, $p = array(), $key = '') {
41 41
 		$p['col'] = $this->name;
42 42
 
@@ -138,34 +138,34 @@  discard block
 block discarded – undo
138 138
 		return $this->pool->remove($this->name, $cond, $cb, $key);
139 139
 	}
140 140
 
141
-    /**
142
-     * Evaluates a code on the server side
143
-     * @param string Code
144
-     * @param mixed Callback called when response received
145
-     * @param string Optional. Distribution key
146
-     * @return void
147
-     */
148
-    public function evaluate($code, $cb, $key = '')
149
-    {
150
-        $this->pool->evaluate($code, $cb, $key);
151
-    }
141
+	/**
142
+	 * Evaluates a code on the server side
143
+	 * @param string Code
144
+	 * @param mixed Callback called when response received
145
+	 * @param string Optional. Distribution key
146
+	 * @return void
147
+	 */
148
+	public function evaluate($code, $cb, $key = '')
149
+	{
150
+		$this->pool->evaluate($code, $cb, $key);
151
+	}
152 152
 
153
-    /**
154
-     * Generation autoincrement
155
-     * @param Closure $cb called when response received
156
-     * @param string $key Optional. Distribution key
157
-     * @return void
158
-     */
159
-    public function autoincrement($cb, $key = '')
160
-    {
161
-        $this->evaluate(
162
-            'function () { '
163
-                . 'return db.autoincrement.findAndModify({ '
164
-                . 'query: {"_id":"' . $this->name . '"}, update: {$inc:{"id":1}}, new: true, upsert: true }); }',
165
-            function ($res) use ($cb) {
166
-                call_user_func($cb, $res);
167
-            },
168
-            $key
169
-        );
170
-    }
153
+	/**
154
+	 * Generation autoincrement
155
+	 * @param Closure $cb called when response received
156
+	 * @param string $key Optional. Distribution key
157
+	 * @return void
158
+	 */
159
+	public function autoincrement($cb, $key = '')
160
+	{
161
+		$this->evaluate(
162
+			'function () { '
163
+				. 'return db.autoincrement.findAndModify({ '
164
+				. 'query: {"_id":"' . $this->name . '"}, update: {$inc:{"id":1}}, new: true, upsert: true }); }',
165
+			function ($res) use ($cb) {
166
+				call_user_func($cb, $res);
167
+			},
168
+			$key
169
+		);
170
+	}
171 171
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -162,7 +162,7 @@
 block discarded – undo
162 162
             'function () { '
163 163
                 . 'return db.autoincrement.findAndModify({ '
164 164
                 . 'query: {"_id":"' . $this->name . '"}, update: {$inc:{"id":1}}, new: true, upsert: true }); }',
165
-            function ($res) use ($cb) {
165
+            function($res) use ($cb) {
166 166
                 call_user_func($cb, $res);
167 167
             },
168 168
             $key
Please login to merge, or discard this patch.
lib/MongoClientAsyncCursor.php 2 patches
Doc Comments   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
 	 * Constructor
15 15
 	 * @param string Cursor's ID
16 16
 	 * @param string Collection's name
17
-	 * @param object Network connection (MongoClientConnection), 
17
+	 * @param object Network connection (MongoClientConnection),
18
+	 * @param string $id
19
+	 * @param MongoClientAsyncConnection $conn 
18 20
 	 * @return void
19 21
 	 */
20 22
 	public function __construct($id, $col, $conn) {
@@ -26,7 +28,7 @@  discard block
 block discarded – undo
26 28
 	/**
27 29
 	 * Asks for more objects
28 30
 	 * @param integer Number of objects
29
-	 * @return void
31
+	 * @return boolean
30 32
 	 */
31 33
 	public function getMore($number = 0) {
32 34
 		//if ($this->tailable && $this->await) {return true;}
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
1 1
 <?php
2 2
 class MongoClientAsyncCursor {
3
-	public $id;                 // Cursor's ID.
4
-	public $col;                // Collection's name.
5
-	public $items = array();    // Array of objects
6
-	public $item;               // Current object
7
-	public $conn;     	        // Network connection
8
-	public $finished = false;   // Is this cursor finished?
9
-	public $failure = false;    // Is this query failured?
10
-	public $await = false;      // awaitCapable?
11
-	public $destroyed = false;  // Is this cursor destroyed?
3
+	public $id; // Cursor's ID.
4
+	public $col; // Collection's name.
5
+	public $items = array(); // Array of objects
6
+	public $item; // Current object
7
+	public $conn; // Network connection
8
+	public $finished = false; // Is this cursor finished?
9
+	public $failure = false; // Is this query failured?
10
+	public $await = false; // awaitCapable?
11
+	public $destroyed = false; // Is this cursor destroyed?
12 12
 
13 13
 	/**
14 14
 	 * Constructor
Please login to merge, or discard this patch.
lib/MySQLClientConnection.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -59,6 +59,7 @@  discard block
 block discarded – undo
59 59
 	 * Converts binary string to integer
60 60
 	 * @param string Binary string
61 61
 	 * @param boolean Optional. Little endian. Default value - true.
62
+	 * @param string $str
62 63
 	 * @return integer Resulting integer
63 64
 	 */
64 65
 	public function bytes2int($str, $l = TRUE)
@@ -82,6 +83,7 @@  discard block
 block discarded – undo
82 83
 	 * @param integer Length
83 84
 	 * @param integer Integer
84 85
 	 * @param boolean Optional. Little endian. Default value - true.
86
+	 * @param integer $len
85 87
 	 * @return string Resulting binary string
86 88
 	 */
87 89
 	function int2bytes($len, $int = 0, $l = TRUE) {
@@ -108,6 +110,7 @@  discard block
 block discarded – undo
108 110
 	/**
109 111
 	 * Sends a packet
110 112
 	 * @param string Data
113
+	 * @param string $packet
111 114
 	 * @return boolean Success
112 115
 	 */
113 116
 	public function sendPacket($packet) { 
@@ -118,6 +121,7 @@  discard block
 block discarded – undo
118 121
 	/**
119 122
 	 * Builds length-encoded binary string
120 123
 	 * @param string String
124
+	 * @param string $s
121 125
 	 * @return string Resulting binary string
122 126
 	 */
123 127
 	public function buildLenEncodedBinary($s) {
@@ -209,6 +213,7 @@  discard block
 block discarded – undo
209 213
 	 * Generates auth. token
210 214
 	 * @param string Scramble string
211 215
 	 * @param string Password
216
+	 * @param string $password
212 217
 	 * @return string Result
213 218
 	 */
214 219
 	public function getAuthToken($scramble, $password) {
@@ -261,6 +266,7 @@  discard block
 block discarded – undo
261 266
 	 * Sends SQL-query
262 267
 	 * @param string Query
263 268
 	 * @param callback Optional. Callback called when response received.
269
+	 * @param string $q
264 270
 	 * @return boolean Success
265 271
 	 */
266 272
 	public function query($q, $callback = NULL) {
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class MySQLClientConnection extends NetworkClientConnection {
3 3
 
4
-	public $url;                        // Connection's URL.
5
-	public $seq           = 0;          // Pointer of packet sequence.
6
-	public $clientFlags   = 239237;     // Flags of this MySQL client.
7
-	public $maxPacketSize = 0x1000000;  // Maximum packet size.
8
-	public $charsetNumber = 0x21;       // Charset number.
9
-	public $path        = ''; 	        // Default database name.
10
-	public $user          = 'root';     // Username
11
-	public $password      = '';         // Password
12
-	public $state        = 0;          // Connection's state. 0 - start, 1 - got initial packet, 2 - auth. packet sent, 3 - auth. error, 4 - handshaked OK
4
+	public $url; // Connection's URL.
5
+	public $seq           = 0; // Pointer of packet sequence.
6
+	public $clientFlags   = 239237; // Flags of this MySQL client.
7
+	public $maxPacketSize = 0x1000000; // Maximum packet size.
8
+	public $charsetNumber = 0x21; // Charset number.
9
+	public $path = ''; // Default database name.
10
+	public $user          = 'root'; // Username
11
+	public $password      = ''; // Password
12
+	public $state        = 0; // Connection's state. 0 - start, 1 - got initial packet, 2 - auth. packet sent, 3 - auth. error, 4 - handshaked OK
13 13
 	const STATE_GOT_INIT = 1;
14 14
 	const STATE_AUTH_SENT = 2;
15 15
 	const STATE_AUTH_ERR = 3;
16 16
 	const STATE_HANDSHAKED = 4;
17
-	public $instate       = 0;          // State of pointer of incoming data. 0 - Result Set Header Packet, 1 - Field Packet, 2 - Row Packet
17
+	public $instate       = 0; // State of pointer of incoming data. 0 - Result Set Header Packet, 1 - Field Packet, 2 - Row Packet
18 18
 	const INSTATE_HEADER = 0;
19 19
 	const INSTATE_FIELD = 1;
20 20
 	const INSTATE_ROW = 2;
21
-	public $resultRows    = array();    // Resulting rows
22
-	public $resultFields  = array();    // Resulting fields
23
-	public $context;                    // Property holds a reference to user's object
24
-	public $insertId;                   // INSERT_ID()
25
-	public $affectedRows;               // Affected rows number
21
+	public $resultRows    = array(); // Resulting rows
22
+	public $resultFields  = array(); // Resulting fields
23
+	public $context; // Property holds a reference to user's object
24
+	public $insertId; // INSERT_ID()
25
+	public $affectedRows; // Affected rows number
26 26
 	public $protover = 0;
27 27
 	public $timeout = 120;
28 28
 	public $errno = 0;
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		$dec = 0;
71 71
 		$len = strlen($str);
72 72
 		
73
-		for($i = 0; $i < $len; ++$i) {
73
+		for ($i = 0; $i < $len; ++$i) {
74 74
 			$dec += ord(binarySubstr($str, $i, 1)) * pow(0x100, $len - $i - 1);
75 75
 		}
76 76
 		
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 
90 90
 		if ($len === NULL) {
91 91
 			if (strlen($hexstr) % 2) {
92
-				$hexstr = "0".$hexstr;
92
+				$hexstr = "0" . $hexstr;
93 93
 			}
94 94
 		} else {
95 95
 			$hexstr = str_repeat('0', $len * 2 - strlen($hexstr)) . $hexstr;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		$bytes = strlen($hexstr) / 2;
99 99
 		$bin = '';
100 100
 		
101
-		for($i = 0; $i < $bytes; ++$i) {
101
+		for ($i = 0; $i < $bytes; ++$i) {
102 102
 			$bin .= chr(hexdec(substr($hexstr, $i * 2, 2)));
103 103
 		}
104 104
 		
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	public function sendPacket($packet) { 
114 114
 		//Daemon::log('Client --> Server: ' . Debug::exportBytes($packet) . "\n\n");
115
-		return $this->write($this->int2bytes(3, strlen($packet)) . chr($this->seq++) . $packet);;
115
+		return $this->write($this->int2bytes(3, strlen($packet)) . chr($this->seq++) . $packet); ;
116 116
 	}
117 117
 
118 118
 	/**
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 		}
179 179
 		
180 180
 		$o = $p;
181
-		$p =+ 8;
181
+		$p = + 8;
182 182
 		
183 183
 		return $this->bytes2int(binarySubstr($s, $o, 8));
184 184
 	}
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @param integer Reference to pointer
190 190
 	 * @return integer Result
191 191
 	 */
192
-	public function parseEncodedString(&$s,&$p) {
192
+	public function parseEncodedString(&$s, &$p) {
193 193
 		$l = $this->parseEncodedBinary($s, $p);
194 194
 
195 195
 		if (
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 		
296 296
 		$this->onResponse->push($callback);
297 297
 		$this->seq = 0;
298
-		$this->sendPacket(chr($cmd).$q);
298
+		$this->sendPacket(chr($cmd) . $q);
299 299
 		
300 300
 		return TRUE;
301 301
 	}
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 				
396 396
 				$this->errno = $u[1];
397 397
 				$state = binarySubstr($this->buf, $p, 6);
398
-				$p =+ 6;
398
+				$p = + 6;
399 399
 
400 400
 				$this->errmsg = binarySubstr($this->buf, $p, $packet[0] + 4 - $p);
401 401
 				$this->onError();
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 				
422 422
 				$this->serverStatus = $u[1];
423 423
 
424
-				$u = unpack('v',binarySubstr($this->buf, $p, 2));
424
+				$u = unpack('v', binarySubstr($this->buf, $p, 2));
425 425
 				$p += 2;
426 426
 				
427 427
 				$this->warnCount = $u[1];
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 					// Row Packet
484 484
 					$row = array();
485 485
 
486
-					for ($i = 0,$nf = sizeof($this->resultFields); $i < $nf; ++$i) {
486
+					for ($i = 0, $nf = sizeof($this->resultFields); $i < $nf; ++$i) {
487 487
 						$row[$this->resultFields[$i]['name']] = $this->parseEncodedString($this->buf, $p);
488 488
 					}
489 489
 		
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -36,11 +36,9 @@  discard block
 block discarded – undo
36 36
 	public function onConnected($cb) {
37 37
 		if ($this->state == self::STATE_AUTH_ERR) {
38 38
 			call_user_func($cb, $this, FALSE);
39
-		}
40
-		elseif ($this->state === self::STATE_HANDSHAKED) {
39
+		} elseif ($this->state === self::STATE_HANDSHAKED) {
41 40
 			call_user_func($cb, $this, TRUE);
42
-		}
43
-		else {
41
+		} else {
44 42
 			if (!$this->onConnected) {
45 43
 				$this->onConnected = new StackCallbacks;
46 44
 			}
@@ -401,8 +399,7 @@  discard block
 block discarded – undo
401 399
 				$this->onError();
402 400
 				$this->errno = 0;
403 401
 				$this->errmsg = '';
404
-			}
405
-			elseif ($fieldCount === 0x00) {
402
+			} elseif ($fieldCount === 0x00) {
406 403
 				// OK Packet Empty
407 404
 				if ($this->state === self::STATE_AUTH_SENT) {
408 405
 					$this->state = self::STATE_HANDSHAKED;
@@ -428,13 +425,11 @@  discard block
 block discarded – undo
428 425
 
429 426
 				$this->message = binarySubstr($this->buf, $p, $packet[0] + 4 - $p);
430 427
 				$this->onResultDone();
431
-			}
432
-			elseif ($fieldCount === 0xFE) { 
428
+			} elseif ($fieldCount === 0xFE) { 
433 429
 				// EOF Packet		
434 430
 				if ($this->instate === self::INSTATE_ROW) {
435 431
 					$this->onResultDone();
436
-				}
437
-				else {
432
+				} else {
438 433
 					++$this->instate;
439 434
 				}
440 435
 			} else {
@@ -445,8 +440,7 @@  discard block
 block discarded – undo
445 440
 					// Result Set Header Packet
446 441
 					$extra = $this->parseEncodedBinary($this->buf, $p);
447 442
 					$this->instate = self::INSTATE_FIELD;
448
-				}
449
-				elseif ($this->instate === self::INSTATE_FIELD) {
443
+				} elseif ($this->instate === self::INSTATE_FIELD) {
450 444
 					// Field Packet
451 445
 					$field = array(
452 446
 						'catalog'    => $this->parseEncodedString($this->buf, $p),
@@ -478,8 +472,7 @@  discard block
 block discarded – undo
478 472
 					++$p;
479 473
 
480 474
 					$this->resultFields[] = $field;
481
-				}
482
-				elseif ($this->instate === self::INSTATE_ROW) {
475
+				} elseif ($this->instate === self::INSTATE_ROW) {
483 476
 					// Row Packet
484 477
 					$row = array();
485 478
 
Please login to merge, or discard this patch.
lib/NetworkClient.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param string Address
63 63
 	 * @param callback onConnected
64 64
 	 * @param integer Optional. Priority.
65
-	 * @return mixed Success|Connection.
65
+	 * @return boolean Success|Connection.
66 66
 	 */
67 67
 	public function getConnection($url = null, $cb = null, $pri = 0) {
68 68
 		if (!is_string($url) && $url !== null && $cb === null) { // if called getConnection(function....)
@@ -135,6 +135,7 @@  discard block
 block discarded – undo
135 135
 	/**
136 136
 	 * Returns available connection from the pool by key
137 137
 	 * @param string Key
138
+	 * @param Closure $cb
138 139
 	 * @return boolean Success.
139 140
 	 */
140 141
 	public function getConnectionByKey($key, $cb = null) {
@@ -161,6 +162,7 @@  discard block
 block discarded – undo
161 162
 	 * @param string Server
162 163
 	 * @param string Request
163 164
 	 * @param mixed Callback called when the request complete
165
+	 * @param string $data
164 166
 	 * @return boolean Success.
165 167
 	 */
166 168
 	public function requestByServer($server, $data, $onResponse = null) {
@@ -189,6 +191,7 @@  discard block
 block discarded – undo
189 191
 	 * @param string Key
190 192
 	 * @param string Request
191 193
 	 * @param mixed Callback called when the request complete
194
+	 * @param string $data
192 195
 	 * @return boolean Success
193 196
 	 */
194 197
 	public function requestByKey($key, $data, $onResponse = null) {
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,11 +9,11 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class NetworkClient extends ConnectionPool {
11 11
 	
12
-	public $servers = array();      // Array of servers 
13
-	public $dtags_enabled = false;   // Enables tags for distribution
14
-	public $servConn = array();      // Active connections
12
+	public $servers = array(); // Array of servers 
13
+	public $dtags_enabled = false; // Enables tags for distribution
14
+	public $servConn = array(); // Active connections
15 15
 	public $servConnFree = array();
16
-	public $prefix = '';             // Prefix for all keys
16
+	public $prefix = ''; // Prefix for all keys
17 17
 	public $maxConnPerServ = 32;
18 18
 	public $acquireOnGet = false;
19 19
 	public $noSAF = false;
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	public function applyConfig() {
38 38
 		parent::applyConfig();
39 39
 		if (isset($this->config->servers)) {
40
-			$servers = array_filter(array_map('trim',explode(',', $this->config->servers->value)), 'strlen');
40
+			$servers = array_filter(array_map('trim', explode(',', $this->config->servers->value)), 'strlen');
41 41
 			$this->servers = array();
42 42
 			foreach ($servers as $s) {
43 43
 				$this->addServer($s);
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 			srand();
170 170
 			$server = array_rand($this->servers);
171 171
 		}
172
-		$this->getConnection($server, function ($conn) use ($data, $onResponse) {
172
+		$this->getConnection($server, function($conn) use ($data, $onResponse) {
173 173
 			if (!$conn->connected) {
174 174
 				return;
175 175
 			}
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 * @return boolean Success
193 193
 	 */
194 194
 	public function requestByKey($key, $data, $onResponse = null) {
195
-		 $this->getConnectionByKey($key, function ($conn) use ($data, $onResponse) {
195
+		 $this->getConnectionByKey($key, function($conn) use ($data, $onResponse) {
196 196
 		 	if (!$conn->connected) {
197 197
 				return;
198 198
 			}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,7 @@
 block discarded – undo
91 91
 				if ($this->acquireOnGet) {
92 92
 					$free->detach($conn);			
93 93
 				}
94
-			}
95
-			elseif ($storage->count() >= $this->maxConnPerServ) {
94
+			} elseif ($storage->count() >= $this->maxConnPerServ) {
96 95
 				if (!isset($this->pending[$url])) {
97 96
 					$this->pending[$url] = new PriorityQueueCallbacks;
98 97
 				}
Please login to merge, or discard this patch.