Completed
Push — 123 ( d13f38 )
by Vasily
05:11
created
old-code-for-refactoring/AsteriskDriver.php 4 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -417,6 +417,7 @@  discard block
 block discarded – undo
417 417
 	 * Synopsis: Generate Challenge for MD5 Auth
418 418
 	 * Privilege: <none>
419 419
 	 *
420
+	 * @param Closure $callback
420 421
 	 * @return void
421 422
 	 */
422 423
 	protected function challenge($callback) {
@@ -629,7 +630,7 @@  discard block
 block discarded – undo
629 630
 
630 631
 	/**
631 632
 	 * Generate a unique ID.
632
-	 * @return Returns the unique identifier, as a string. 
633
+	 * @return string the unique identifier, as a string. 
633 634
 	 */
634 635
 	protected function uniqid() {
635 636
 		return uniqid(Daemon::$process->pid, true);
@@ -637,7 +638,7 @@  discard block
 block discarded – undo
637 638
 	
638 639
 	/**
639 640
 	 * Sends a packet.
640
-	 * @param string $pacekt Data
641
+	 * @param string $packet Data
641 642
 	 * @return void
642 643
 	 */
643 644
 	public function sendPacket($packet) {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -532,7 +532,7 @@
 block discarded – undo
532 532
 	 * Privilege: system,call,reporting,all
533 533
 	 * Description: Lists channel status along with requested channel vars.
534 534
 	 * Variables: (Names marked with * are required)
535
-		*Channel: Name of the channel to query for status
535
+	 *Channel: Name of the channel to query for status
536 536
 	 *	Variables: Comma ',' separated list of variables to include
537 537
 	 * ActionID: Optional ID for this transaction
538 538
 	 * Will return the status information of each channel along with the
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
 			return; // Not enough data buffered yet
264 264
 		}
265 265
 		elseif (strpos($this->buf, "\r\n\r\n") !== false) {
266
-			while(($line = $this->gets()) !== false) {
266
+			while (($line = $this->gets()) !== false) {
267 267
 				if ($line == "\r\n") {
268 268
 					$this->instate = AsteriskDriver::INPUT_STATE_END_OF_PACKET;
269
-					$packet =& $this->packets[$this->cnt];
269
+					$packet = & $this->packets[$this->cnt];
270 270
 					$this->cnt++;
271 271
 				} else {
272 272
 					$this->instate = AsteriskDriver::INPUT_STATE_PROCESSING;
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 					$this->packets[$this->cnt][$header] = $value;
275 275
 				}
276 276
 
277
-				if ((int)$this->cstate === AsteriskDriver::CONN_STATE_AUTH) {
277
+				if ((int) $this->cstate === AsteriskDriver::CONN_STATE_AUTH) {
278 278
 					if ($this->instate == AsteriskDriver::INPUT_STATE_END_OF_PACKET) {
279 279
 						if ($packet['response'] == 'success') {
280 280
 							if (
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 						}
318 318
 						// Response
319 319
 						elseif (isset($packet['actionid'])) {
320
-							$action_id =& $packet['actionid'];
320
+							$action_id = & $packet['actionid'];
321 321
 
322 322
 							if (isset($this->callbacks[$action_id])) {
323 323
 								if (isset($this->assertions[$action_id])) {
@@ -503,10 +503,10 @@  discard block
 block discarded – undo
503 503
 	 */
504 504
 	public function setVar($channel, $variable, $value, $callback) {
505 505
 		$cmd = "Action: SetVar\r\n";
506
-		if($channel) {
506
+		if ($channel) {
507 507
 			$cmd .= "Channel: " . trim($channel) . "\r\n";
508 508
 		}
509
-		if(isset($variable, $value)) {
509
+		if (isset($variable, $value)) {
510 510
 			$cmd .= "Variable: " . trim($variable) . "\r\n";
511 511
 			$cmd .= "Value: " . trim($value) . "\r\n";
512 512
 			$this->command($cmd, $callback);
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 	 */
541 541
 	public function status($callback, $channel = null) {
542 542
 		$cmd = "Action: Status\r\n";
543
-		if($channel !== null) {
543
+		if ($channel !== null) {
544 544
 			$cmd .= "Channel: " . trim($channel) . "\r\n";
545 545
 		}
546 546
 		$this->command($cmd, $callback, array('event' => 'statuscomplete'));
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 		}
661 661
 
662 662
 		$action_id = $this->uniqid();
663
-		if(!is_callable($callback, true)) {
663
+		if (!is_callable($callback, true)) {
664 664
 			$callback = false;
665 665
 		}
666 666
 		$this->callbacks[$action_id] = $callback;
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
 	 */
680 680
 	protected function implodeParams(array $params) {
681 681
 		$s = '';
682
-		foreach($params as $header => $value) {
682
+		foreach ($params as $header => $value) {
683 683
 			$s .= trim($header) . ": " . trim($value) . "\r\n";
684 684
 		}
685 685
 		return $s;
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -258,11 +258,9 @@  discard block
 block discarded – undo
258 258
 			$this->cstate = AsteriskDriver::CONN_STATE_GOT_INITIAL_PACKET;
259 259
 			$this->appInstance->amiVersions[$this->addr] = trim($this->buf);
260 260
 			$this->auth();
261
-		}
262
-		elseif (strlen($this->buf) < 4) {
261
+		} elseif (strlen($this->buf) < 4) {
263 262
 			return; // Not enough data buffered yet
264
-		}
265
-		elseif (strpos($this->buf, "\r\n\r\n") !== false) {
263
+		} elseif (strpos($this->buf, "\r\n\r\n") !== false) {
266 264
 			while(($line = $this->gets()) !== false) {
267 265
 				if ($line == "\r\n") {
268 266
 					$this->instate = AsteriskDriver::INPUT_STATE_END_OF_PACKET;
@@ -303,8 +301,7 @@  discard block
 block discarded – undo
303 301
 						}
304 302
 						$this->packets = array();
305 303
 					}
306
-				}
307
-				elseif ($this->cstate === AsteriskDriver::CONN_STATE_HANDSHAKED_OK) {
304
+				} elseif ($this->cstate === AsteriskDriver::CONN_STATE_HANDSHAKED_OK) {
308 305
 					if ($this->instate == AsteriskDriver::INPUT_STATE_END_OF_PACKET) {
309 306
 						// Event
310 307
 						if (
@@ -361,8 +358,7 @@  discard block
 block discarded – undo
361 358
 			&& is_callable($this->onConnected)
362 359
 		) {
363 360
 			call_user_func($this->onConnected, $this, false);
364
-		}
365
-		elseif (
361
+		} elseif (
366 362
 			$this->cstate === AsteriskDriver::CONN_STATE_HANDSHAKED_OK
367 363
 			&& is_callable($this->onConnected)
368 364
 		) {
Please login to merge, or discard this patch.
app-examples/ExampleIRCBot.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
 	 * @return array|false
19 19
 	 */
20 20
 	protected function getConfigDefaults() {
21
-		$random = sprintf('%x', crc32(posix_getpid() . "\x00". microtime(true)));
21
+		$random = sprintf('%x', crc32(posix_getpid() . "\x00" . microtime(true)));
22 22
 		return array(
23
-			'url' => 'irc://guest_'.$random.':[email protected]/Bot_phpDaemon'
23
+			'url' => 'irc://guest_' . $random . ':[email protected]/Bot_phpDaemon'
24 24
 		);
25 25
 	}
26 26
 	/**
@@ -46,24 +46,24 @@  discard block
 block discarded – undo
46 46
 	
47 47
 	public function connect() {
48 48
 		$app = $this;
49
-		$r = $this->client->getConnection($this->config->url->value, function ($conn) use ($app) {
49
+		$r = $this->client->getConnection($this->config->url->value, function($conn) use ($app) {
50 50
 			$app->conn = $conn;
51 51
 			if ($conn->connected) {
52
-				Daemon::log('IRC bot connected at '.$this->config->url->value);
52
+				Daemon::log('IRC bot connected at ' . $this->config->url->value);
53 53
 				$conn->join('#botwar_phpdaemon');
54 54
 				$conn->bind('motd', function($conn) {
55 55
 					//Daemon::log($conn->motd);
56 56
 				});
57 57
 				$conn->bind('privateMsg', function($conn, $msg) {
58
-					Daemon::log('IRCBot: got private message \''.$msg['body'].'\' from \''.$msg['from']['orig'].'\'');
59
-					$conn->message($msg['from']['nick'], 'You just wrote: '.$msg['body']); // send the message back
58
+					Daemon::log('IRCBot: got private message \'' . $msg['body'] . '\' from \'' . $msg['from']['orig'] . '\'');
59
+					$conn->message($msg['from']['nick'], 'You just wrote: ' . $msg['body']); // send the message back
60 60
 				});
61 61
 				$conn->bind('disconnect', function() use ($app) {
62 62
 					$app->connect();
63 63
 				});
64 64
 			}
65 65
 			else {
66
-				Daemon::log('IRCBot: unable to connect ('.$this->config->url->value.')');
66
+				Daemon::log('IRCBot: unable to connect (' . $this->config->url->value . ')');
67 67
 			}
68 68
 		});
69 69
 	}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,8 +61,7 @@
 block discarded – undo
61 61
 				$conn->bind('disconnect', function() use ($app) {
62 62
 					$app->connect();
63 63
 				});
64
-			}
65
-			else {
64
+			} else {
66 65
 				Daemon::log('IRCBot: unable to connect ('.$this->config->url->value.')');
67 66
 			}
68 67
 		});
Please login to merge, or discard this patch.
app-examples/TelnetHoneypot.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,8 +41,7 @@
 block discarded – undo
41 41
 
42 42
 			if ($cmd === 'ping') {
43 43
 				$this->writeln('pong');
44
-			}
45
-			elseif (
44
+			} elseif (
46 45
 				($cmd === 'exit') 
47 46
 				|| ($cmd === 'quit')
48 47
 			) {
Please login to merge, or discard this patch.
app-examples/ExampleJabberbot.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,21 +45,21 @@
 block discarded – undo
45 45
 	
46 46
 	public function connect() {
47 47
 		$app = $this;
48
-		$this->xmppclient->getConnection($this->config->url->value, function ($conn) use ($app) {
48
+		$this->xmppclient->getConnection($this->config->url->value, function($conn) use ($app) {
49 49
 			$app->xmppconn = $conn;
50 50
 			if ($conn->connected) {
51
-				Daemon::log('Jabberbot connected at '.$this->config->url->value);
51
+				Daemon::log('Jabberbot connected at ' . $this->config->url->value);
52 52
 				$conn->presence('I\'m a robot.', 'chat');
53 53
 				$conn->addEventHandler('message', function($msg) use ($conn) {
54
-					Daemon::log('JabberBot: got message \''.$msg['body'].'\'');
55
-					$conn->message($msg['from'], 'You just wrote: '.$msg['body']); // send the message back
54
+					Daemon::log('JabberBot: got message \'' . $msg['body'] . '\'');
55
+					$conn->message($msg['from'], 'You just wrote: ' . $msg['body']); // send the message back
56 56
 				});
57 57
 				$conn->addEventHandler('disconnect', function() use ($app) {
58 58
 					$app->connect();
59 59
 				});
60 60
 			}
61 61
 			else {
62
-				Daemon::log('Jabberbot: unable to connect ('.$this->config->url->value.')');
62
+				Daemon::log('Jabberbot: unable to connect (' . $this->config->url->value . ')');
63 63
 			}
64 64
 		});
65 65
 	}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,8 +57,7 @@
 block discarded – undo
57 57
 				$conn->addEventHandler('disconnect', function() use ($app) {
58 58
 					$app->connect();
59 59
 				});
60
-			}
61
-			else {
60
+			} else {
62 61
 				Daemon::log('Jabberbot: unable to connect ('.$this->config->url->value.')');
63 62
 			}
64 63
 		});
Please login to merge, or discard this patch.
app-examples/ExampleLockClient.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 			$LockClient->job(
34 34
 					'ExampleJobName', // name of the job
35 35
 					false, //wait?
36
-					function($command,$jobname,$client) use ($req) {
36
+					function($command, $jobname, $client) use ($req) {
37 37
 						if ($command === 'RUN') {
38 38
 							Daemon_TimedEvent::add(function($event) use ($req, $jobname, $client) {
39 39
 							Daemon::log('done');
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 								$req->out(':-)');
42 42
 								$req->wakeup();
43 43
 								$event->finish();
44
-							}, pow(10,6) * 1);
44
+							}, pow(10, 6) * 1);
45 45
 						}
46 46
 						else {
47 47
 						 $req->out(':-(');
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,8 +42,7 @@
 block discarded – undo
42 42
 								$req->wakeup();
43 43
 								$event->finish();
44 44
 							}, pow(10,6) * 1);
45
-						}
46
-						else {
45
+						} else {
47 46
 						 $req->out(':-(');
48 47
 						 $req->wakeup();
49 48
 						}
Please login to merge, or discard this patch.
app-examples/ExampleBroadcastCall.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 	
13 13
 	public function hello($pid) {
14 14
 	
15
-		Daemon::$process->log('I got hello from '.$pid.'!');
15
+		Daemon::$process->log('I got hello from ' . $pid . '!');
16 16
 	
17 17
 	}
18 18
 	
Please login to merge, or discard this patch.
app-examples/ExampleComplexJob.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -14,13 +14,13 @@  discard block
 block discarded – undo
14 14
 	 * 
15 15
 	 * @return void
16 16
 	 */
17
-    public function onReady() {
17
+	public function onReady() {
18 18
 
19
-        // Adding listener
20
-        // ComplexJob - STATE_WAITING
21
-        $job = new ComplexJob(function($job) {
22
-        	// ComplexJob - STATE_DONE
23
-            /*array (
19
+		// Adding listener
20
+		// ComplexJob - STATE_WAITING
21
+		$job = new ComplexJob(function($job) {
22
+			// ComplexJob - STATE_DONE
23
+			/*array (
24 24
               'bar' =>
25 25
               array (
26 26
                     'job' => 'bar',
@@ -44,62 +44,62 @@  discard block
 block discarded – undo
44 44
                     'line' => 94,
45 45
               ),
46 46
             )*/
47
-            Daemon::log($job->results);
48
-        });
47
+			Daemon::log($job->results);
48
+		});
49 49
 
50
-        // Adding listener
51
-        // ComplexJob - STATE_WAITING
52
-        $job->addListener(function($job) {
50
+		// Adding listener
51
+		// ComplexJob - STATE_WAITING
52
+		$job->addListener(function($job) {
53 53
 			// ComplexJob - STATE_DONE
54
-        });
54
+		});
55 55
 
56
-        // Incapsulate some property in job
57
-        $job->appInstance = $this;
56
+		// Incapsulate some property in job
57
+		$job->appInstance = $this;
58 58
 
59
-        // Adding async job foo
60
-        $job('foo', $this->foo(array('param' => 'value')));
59
+		// Adding async job foo
60
+		$job('foo', $this->foo(array('param' => 'value')));
61 61
 
62
-        // Adding with 1 sec delay
63
-        Timer::add(function($event) use ($job) {
62
+		// Adding with 1 sec delay
63
+		Timer::add(function($event) use ($job) {
64 64
 
65
-            // Adding async job bar
66
-            $job('bar', function($jobname, $job) {
67
-                Timer::add(function($event) use($jobname, $job) {
68
-                    // Job done
69
-                    $job->setResult($jobname, array('job' => 'bar', 'success' => false, 'line' => __LINE__));
70
-                    $event->finish();
71
-                }, 1e3 * 50);
72
-            });
65
+			// Adding async job bar
66
+			$job('bar', function($jobname, $job) {
67
+				Timer::add(function($event) use($jobname, $job) {
68
+					// Job done
69
+					$job->setResult($jobname, array('job' => 'bar', 'success' => false, 'line' => __LINE__));
70
+					$event->finish();
71
+				}, 1e3 * 50);
72
+			});
73 73
 
74
-            // Adding async job baz. Equal $job('baz', $job->appInstance->baz());
75
-            $job->addJob('baz', $job->appInstance->baz());
74
+			// Adding async job baz. Equal $job('baz', $job->appInstance->baz());
75
+			$job->addJob('baz', $job->appInstance->baz());
76 76
 
77
-            // Run jobs. All listeners will be called when the jobs done
78
-            // ComplexJob - STATE_RUNNING
79
-            $job();
77
+			// Run jobs. All listeners will be called when the jobs done
78
+			// ComplexJob - STATE_RUNNING
79
+			$job();
80 80
                 
81
-            $event->finish();
82
-        }, 1e6 * 1);
81
+			$event->finish();
82
+		}, 1e6 * 1);
83 83
 
84
-    }
84
+	}
85 85
 
86
-    final public function foo($arg) {
87
-        return function($jobname, $job) use ($arg) {
88
-            Timer::add(function($event) use($jobname, $job, $arg) {
89
-                // Job done
90
-                $job->setResult($jobname, array('job' => 'foo', 'success' => true, 'line' => __LINE__, 'arg' => $arg));
91
-                $event->finish();
92
-            }, 1e3 * 100);
93
-        };
94
-    }
86
+	final public function foo($arg) {
87
+		return function($jobname, $job) use ($arg) {
88
+			Timer::add(function($event) use($jobname, $job, $arg) {
89
+				// Job done
90
+				$job->setResult($jobname, array('job' => 'foo', 'success' => true, 'line' => __LINE__, 'arg' => $arg));
91
+				$event->finish();
92
+			}, 1e3 * 100);
93
+		};
94
+	}
95 95
 
96
-    final public function baz() {
97
-        return function($jobname, $job) {
98
-            Timer::add(function($event) use($jobname, $job) {
99
-                // Job done
100
-                $job->setResult($jobname, array('job' => 'baz', 'success' => false, 'line' => __LINE__));
101
-                $event->finish();
102
-            }, 1e3 * 300);
103
-        };
104
-    }
96
+	final public function baz() {
97
+		return function($jobname, $job) {
98
+			Timer::add(function($event) use($jobname, $job) {
99
+				// Job done
100
+				$job->setResult($jobname, array('job' => 'baz', 'success' => false, 'line' => __LINE__));
101
+				$event->finish();
102
+			}, 1e3 * 300);
103
+		};
104
+	}
105 105
 }
Please login to merge, or discard this patch.
lib/MemcacheClientConnection.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
 	 * Called when new data received
22 22
 	 * @param string New data
23 23
 	 * @return void
24
-	*/
24
+	 */
25 25
 	public function stdin($buf) {
26 26
 		$this->buf .= $buf;
27 27
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -8,12 +8,12 @@  discard block
 block discarded – undo
8 8
 
9 9
 class MemcacheClientConnection extends NetworkClientConnection {
10 10
 
11
-	public $result;                // current result
12
-	public $valueFlags;            // flags of incoming value
13
-	public $valueLength;           // length of incoming value
14
-	public $valueSize = 0;         // size of received part of the value
15
-	public $error;                 // error message
16
-	public $key;                   // current incoming key
11
+	public $result; // current result
12
+	public $valueFlags; // flags of incoming value
13
+	public $valueLength; // length of incoming value
14
+	public $valueSize = 0; // size of received part of the value
15
+	public $error; // error message
16
+	public $key; // current incoming key
17 17
 	const STATE_DATA = 1;
18 18
 	public $EOL = "\r\n";
19 19
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
 		if ($this->state === self::STATE_DATA) {
72 72
 			if ($this->valueSize < $this->valueLength) {
73
-				$n = $this->valueLength-$this->valueSize;
73
+				$n = $this->valueLength - $this->valueSize;
74 74
 				$buflen = strlen($this->buf);
75 75
 
76 76
 				if ($buflen > $n) {
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -38,15 +38,13 @@
 block discarded – undo
38 38
 					$this->result = '';
39 39
 					$this->state = self::STATE_DATA;
40 40
 					break;
41
-				}
42
-				elseif ($e[0] == 'STAT') {
41
+				} elseif ($e[0] == 'STAT') {
43 42
 					if ($this->result === NULL) {
44 43
 						$this->result = array();
45 44
 					}
46 45
 
47 46
 					$this->result[$e[1]] = $e[2];
48
-				}
49
-				elseif (
47
+				} elseif (
50 48
 					($e[0] === 'STORED') 
51 49
 					|| ($e[0] === 'END') 
52 50
 					|| ($e[0] === 'DELETED') 
Please login to merge, or discard this patch.
lib/XMPPRoster.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
 	}
102 102
 
103 103
 		/**
104
-	 *
105
-	 * Add given contact to roster
106
-	 *
107
-	 * @param string $jid
108
-	 * @param string $subscription
109
-	 * @param string $name
110
-	 * @param array $groups
111
-	 */
104
+		 *
105
+		 * Add given contact to roster
106
+		 *
107
+		 * @param string $jid
108
+		 * @param string $subscription
109
+		 * @param string $name
110
+		 * @param array $groups
111
+		 */
112 112
 	public function _addContact($jid, $subscription, $name='', $groups=array()) {
113 113
 		$contact = array('jid' => $jid, 'subscription' => $subscription, 'name' => $name, 'groups' => $groups);
114 114
 		if ($this->isContact($jid)) {
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 * @param integer $priority
149 149
 	 * @param string $show
150 150
 	 * @param string $status
151
-	*/
151
+	 */
152 152
 	public function setPresence($presence, $priority, $show, $status) {
153 153
 		list($jid, $resource) = explode('/', $presence . '/');
154 154
 		if ($show != 'unavailable') {
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 	public function __construct($xmpp) {
11 11
 		$this->xmpp = $xmpp;
12 12
 
13
-		$this->xmpp->xml->addXPathHandler('{jabber:client}presence', function ($xml) {
13
+		$this->xmpp->xml->addXPathHandler('{jabber:client}presence', function($xml) {
14 14
 			$payload = array();
15 15
 			$payload['type'] = (isset($xml->attrs['type'])) ? $xml->attrs['type'] : 'available';
16 16
 			$payload['show'] = (isset($xml->sub('show')->data)) ? $xml->sub('show')->data : $payload['type'];
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
 				$this->setPresence($payload['from'], $payload['priority'], $payload['show'], $payload['status']);
26 26
 			}
27 27
 			//Daemon::log("Presence: {$payload['from']} [{$payload['show']}] {$payload['status']}");
28
-			if(array_key_exists('type', $xml->attrs) and $xml->attrs['type'] == 'subscribe') {
29
-				if($this->auto_subscribe) {
28
+			if (array_key_exists('type', $xml->attrs) and $xml->attrs['type'] == 'subscribe') {
29
+				if ($this->auto_subscribe) {
30 30
 					$this->xmpp->sendXML("<presence type='subscribed' to='{$xml->attrs['from']}' from='{$this->xmpp->fulljid}' />");
31 31
 					$this->xmpp->sendXML("<presence type='subscribe' to='{$xml->attrs['from']}' from='{$this->xmpp->fulljid}' />");
32 32
 				}
33 33
 				$this->event('subscription_requested', $payload);
34
-			} elseif(array_key_exists('type', $xml->attrs) and $xml->attrs['type'] == 'subscribed') {
34
+			} elseif (array_key_exists('type', $xml->attrs) and $xml->attrs['type'] == 'subscribed') {
35 35
 				$this->event('subscription_accepted', $payload);
36 36
 			} else {
37 37
 				$this->event('presence', $payload);
@@ -46,20 +46,20 @@  discard block
 block discarded – undo
46 46
 	}
47 47
 
48 48
 	public function setSubscription($jid, $type, $cb = null) {
49
-		$this->rosterSet('<item jid="'.htmlspecialchars($jid).'" subscription="'.htmlspecialchars($type).'" />', $cb);
49
+		$this->rosterSet('<item jid="' . htmlspecialchars($jid) . '" subscription="' . htmlspecialchars($type) . '" />', $cb);
50 50
 	} 
51 51
 	public function fetch($cb = null) {
52
-		$this->xmpp->queryGet($this->ns, function ($xml) use ($cb) {
52
+		$this->xmpp->queryGet($this->ns, function($xml) use ($cb) {
53 53
 			$status = "result";
54 54
 			$xmlroster = $xml->sub('query');
55 55
 			$contacts = array();
56
-			foreach($xmlroster->subs as $item) {
56
+			foreach ($xmlroster->subs as $item) {
57 57
 				$groups = array();
58 58
 				if ($item->name == 'item') {
59 59
 					$jid = $item->attrs['jid']; //REQUIRED
60 60
 					$name = isset($item->attrs['name']) ? $item->attrs['name'] : ''; //MAY
61 61
 					$subscription = $item->attrs['subscription'];
62
-					foreach($item->subs as $subitem) {
62
+					foreach ($item->subs as $subitem) {
63 63
 						if ($subitem->name == 'group') {
64 64
 							$groups[] = $subitem->data;
65 65
 						}
@@ -70,12 +70,12 @@  discard block
 block discarded – undo
70 70
 				}
71 71
 			}
72 72
 			if ($status == "result") { //No errors, add contacts
73
-				foreach($contacts as $contact) {
73
+				foreach ($contacts as $contact) {
74 74
 					$this->_addContact($contact[0], $contact[1], $contact[2], $contact[3]);
75 75
 				}
76 76
 			}
77 77
 			if ($xml->attrs['type'] == 'set') {
78
-				$this->xmpp->sendXML('<iq type="reply" id="'.$xml->attrs['id'].'" to="'.$xml->attrs['from'].'" />');
78
+				$this->xmpp->sendXML('<iq type="reply" id="' . $xml->attrs['id'] . '" to="' . $xml->attrs['from'] . '" />');
79 79
 			}
80 80
 			if ($cb) {
81 81
 				call_user_func($cb, $status);
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @param string $name
110 110
 	 * @param array $groups
111 111
 	 */
112
-	public function _addContact($jid, $subscription, $name='', $groups=array()) {
112
+	public function _addContact($jid, $subscription, $name = '', $groups = array()) {
113 113
 		$contact = array('jid' => $jid, 'subscription' => $subscription, 'name' => $name, 'groups' => $groups);
114 114
 		if ($this->isContact($jid)) {
115 115
 			$this->roster_array[$jid]['contact'] = $contact;
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	public function getPresence($jid) {
171 171
 		$split = split("/", $jid);
172 172
 		$jid = $split[0];
173
-		if($this->isContact($jid)) {
173
+		if ($this->isContact($jid)) {
174 174
 			$current = array('resource' => '', 'active' => '', 'priority' => -129, 'show' => '', 'status' => ''); //Priorities can only be -128 = 127
175
-			foreach($this->roster_array[$jid]['presence'] as $resource => $presence) {
175
+			foreach ($this->roster_array[$jid]['presence'] as $resource => $presence) {
176 176
 				//Highest available priority or just highest priority
177 177
 				if ($presence['priority'] > $current['priority'] and (($presence['show'] == "chat" or $presence['show'] == "available") or ($current['show'] != "chat" or $current['show'] != "available"))) {
178 178
 					$current = $presence;
Please login to merge, or discard this patch.