Completed
Pull Request — master (#56)
by Maciej
40s
created
Tests/Samples/php/huge.php 1 patch
Braces   +100 added lines, -56 removed lines patch added patch discarded remove patch
@@ -204,8 +204,9 @@  discard block
 block discarded – undo
204 204
      */
205 205
     public function __construct(Jid $jid, $password, AbstractConnector $connector = null)
206 206
     {
207
-        if(!$connector)
208
-            $connector = new TcpConnector($jid->server);
207
+        if(!$connector) {
208
+                    $connector = new TcpConnector($jid->server);
209
+        }
209 210
 
210 211
         $this->connector = $connector;
211 212
         $this->connector->client = $this;
@@ -262,27 +263,31 @@  discard block
 block discarded – undo
262 263
         $this->connector->onSend->add(function ($socket, $packet) use ($settings) {
263 264
             $len = strlen($packet);
264 265
 
265
-            if (function_exists('tidy_repair_string'))
266
-                $packet = trim(tidy_repair_string($packet, $settings));
266
+            if (function_exists('tidy_repair_string')) {
267
+                            $packet = trim(tidy_repair_string($packet, $settings));
268
+            }
267 269
 
268
-            if (isset($this->logger))
269
-                $this->logger->debug("Sent {length} bytes: \n{packet}", [
270
+            if (isset($this->logger)) {
271
+                            $this->logger->debug("Sent {length} bytes: \n{packet}", [
270 272
                     'length' => $len,
271 273
                     'packet' => $packet
272 274
                 ]);
275
+            }
273 276
         });
274 277
 
275 278
         $this->connector->onReceive->add(function ($socket, $packet) use ($settings) {
276 279
             $len = strlen($packet);
277 280
 
278
-            if (function_exists('tidy_repair_string'))
279
-                $packet = trim(tidy_repair_string($packet, $settings));
281
+            if (function_exists('tidy_repair_string')) {
282
+                            $packet = trim(tidy_repair_string($packet, $settings));
283
+            }
280 284
 
281
-            if (isset($this->logger))
282
-                $this->logger->debug("Received {length} bytes: \n{packet}", [
285
+            if (isset($this->logger)) {
286
+                            $this->logger->debug("Received {length} bytes: \n{packet}", [
283 287
                     'length' => $len,
284 288
                     'packet' => $packet
285 289
                 ]);
290
+            }
286 291
         });
287 292
 
288 293
         XmlBranch::$bind['iq']       = 'Kadet\\Xmpp\\Stanza\\Iq';
@@ -375,7 +380,9 @@  discard block
 block discarded – undo
375 380
 
376 381
     private function startTls()
377 382
     {
378
-        if ($this->logger) $this->logger->notice('Starting TLS negotiation.');
383
+        if ($this->logger) {
384
+            $this->logger->notice('Starting TLS negotiation.');
385
+        }
379 386
 
380 387
         $xml = new XmlBranch('starttls');
381 388
         $xml->addAttribute('xmlns', 'urn:ietf:params:xml:ns:xmpp-tls');
@@ -389,10 +396,11 @@  discard block
 block discarded – undo
389 396
      */
390 397
     private function auth()
391 398
     {
392
-        if ($this->logger)
393
-            $this->logger->notice('SASL Auth, available mechanisms: {mechanisms}', [
399
+        if ($this->logger) {
400
+                    $this->logger->notice('SASL Auth, available mechanisms: {mechanisms}', [
394 401
                 'mechanisms' => implode(', ', array_map(function (XmlBranch $item) {
395 402
                     return $item->content;
403
+        }
396 404
                 }, (array)$this->connector->features->mechanisms[0]->mechanism))
397 405
             ]);
398 406
 
@@ -402,15 +410,18 @@  discard block
 block discarded – undo
402 410
         $mechanism = null;
403 411
         $this->connector->features->mechanisms[0]->mechanism->getIterator();
404 412
         foreach ($this->connector->features->mechanisms[0]->mechanism as $current) {
405
-            if ($mechanism = SaslFactory::get($current->content, $this->jid, $this->password))
406
-                break;
413
+            if ($mechanism = SaslFactory::get($current->content, $this->jid, $this->password)) {
414
+                            break;
415
+            }
407 416
         }
408 417
 
409
-        if (!$mechanism)
410
-            throw new \RuntimeException('This client is not supporting any of server auth mechanisms.');
418
+        if (!$mechanism) {
419
+                    throw new \RuntimeException('This client is not supporting any of server auth mechanisms.');
420
+        }
411 421
 
412
-        if ($this->logger)
413
-            $this->logger->notice('Chosen mechanism: {mechanism}', ['mechanism' => $current->content]);
422
+        if ($this->logger) {
423
+                    $this->logger->notice('Chosen mechanism: {mechanism}', ['mechanism' => $current->content]);
424
+        }
414 425
 
415 426
         $this->_mechanism = $mechanism;
416 427
 
@@ -433,13 +444,15 @@  discard block
 block discarded – undo
433 444
     public function _onAuth(XmppClient $client, Stanza $result)
434 445
     {
435 446
         if ($result->xml->getName() == 'success') {
436
-            if ($this->logger)
437
-                $this->logger->info('SASL Auth successful.');
447
+            if ($this->logger) {
448
+                            $this->logger->info('SASL Auth successful.');
449
+            }
438 450
 
439 451
             $this->connector->streamRestart($this->jid);
440 452
             $this->_bind();
441
-        } elseif ($this->logger)
442
-            $this->logger->error('SASL Auth failed, reason: {reason}', ['reason' => $result->text[0]]);
453
+        } elseif ($this->logger) {
454
+                    $this->logger->error('SASL Auth failed, reason: {reason}', ['reason' => $result->text[0]]);
455
+        }
443 456
     }
444 457
 
445 458
     /**
@@ -476,13 +489,15 @@  discard block
 block discarded – undo
476 489
     public function _onTls(XmppClient $client, Stanza $result)
477 490
     {
478 491
         if ($result->tag == 'proceed') {
479
-            if ($this->logger)
480
-                $this->logger->info('TLS Connection established.');
492
+            if ($this->logger) {
493
+                            $this->logger->info('TLS Connection established.');
494
+            }
481 495
 
482 496
             $this->connector->startTls();
483 497
             $this->connector->streamRestart($this->jid);
484
-        } else
485
-            throw new \RuntimeException('Tls negotiation failed.');
498
+        } else {
499
+                    throw new \RuntimeException('Tls negotiation failed.');
500
+        }
486 501
     }
487 502
 
488 503
     /**
@@ -504,8 +519,9 @@  discard block
 block discarded – undo
504 519
             $this->write($iq->asXml());
505 520
             $this->isReady = true;
506 521
             $this->onReady->run($this);
507
-        } else
508
-            throw new \RuntimeException('Resource binding error.');
522
+        } else {
523
+                    throw new \RuntimeException('Resource binding error.');
524
+        }
509 525
     }
510 526
 
511 527
     /**
@@ -593,10 +609,11 @@  discard block
 block discarded – undo
593 609
             case 'success':
594 610
             case 'failure':
595 611
             case 'proceed':
596
-                if ($stanza['xmlns'] == 'urn:ietf:params:xml:ns:xmpp-sasl')
597
-                    $this->onAuth->run($this, $stanza);
598
-                elseif ($stanza['xmlns'] == 'urn:ietf:params:xml:ns:xmpp-tls')
599
-                    $this->onTls->run($this, $stanza);
612
+                if ($stanza['xmlns'] == 'urn:ietf:params:xml:ns:xmpp-sasl') {
613
+                                    $this->onAuth->run($this, $stanza);
614
+                } elseif ($stanza['xmlns'] == 'urn:ietf:params:xml:ns:xmpp-tls') {
615
+                                    $this->onTls->run($this, $stanza);
616
+                }
600 617
 
601 618
                 break;
602 619
             case 'challenge':
@@ -635,7 +652,9 @@  discard block
 block discarded – undo
635 652
         $channelJid = $packet->from->bare();
636 653
         $jid        = new Jid($channelJid);
637 654
 
638
-        if (!$jid->isChannel()) return;
655
+        if (!$jid->isChannel()) {
656
+            return;
657
+        }
639 658
 
640 659
         if ($packet->type != 'unavailable') {
641 660
             if (isset($this->rooms[$channelJid]->users[$packet->from->resource])) {
@@ -645,7 +664,9 @@  discard block
 block discarded – undo
645 664
                 if (
646 665
                     (string)$user->jid == (string)$this->jid ||
647 666
                     $this->rooms[$channelJid]->nick == $packet->from->resource
648
-                ) $user->self = true;
667
+                ) {
668
+                    $user->self = true;
669
+                }
649 670
 
650 671
                 $this->onJoin->run(
651 672
                     $this,
@@ -659,7 +680,9 @@  discard block
 block discarded – undo
659 680
         } elseif (isset($this->rooms[$channelJid])) {
660 681
             $item = $packet->xpath('//user:item', ['user' => 'http://jabber.org/protocol/muc#user']);
661 682
 
662
-            if (!isset($item[0])) return;
683
+            if (!isset($item[0])) {
684
+                return;
685
+            }
663 686
             $item = $item[0];
664 687
 
665 688
             // Nickname change
@@ -700,13 +723,18 @@  discard block
 block discarded – undo
700 723
      */
701 724
     public function _onMessage(XmppClient $client, Message $packet)
702 725
     {
703
-        if ($packet->type != 'groupchat' || !isset($this->rooms[$packet->from->bare()])) return;
726
+        if ($packet->type != 'groupchat' || !isset($this->rooms[$packet->from->bare()])) {
727
+            return;
728
+        }
704 729
 
705
-        if (isset($packet->subject))
706
-            $this->rooms[$packet->from->bare()]->subject = $packet->subject;
730
+        if (isset($packet->subject)) {
731
+                    $this->rooms[$packet->from->bare()]->subject = $packet->subject;
732
+        }
707 733
 
708
-        if (!isset($packet->delay) && $this->rooms[$packet->from->bare()]->subject === false)
709
-            $this->rooms[$packet->from->bare()]->subject = ''; // Some strange workaround, servers doesn't meet specification... ;(
734
+        if (!isset($packet->delay) && $this->rooms[$packet->from->bare()]->subject === false) {
735
+                    $this->rooms[$packet->from->bare()]->subject = '';
736
+        }
737
+        // Some strange workaround, servers doesn't meet specification... ;(
710 738
     }
711 739
 
712 740
     /**
@@ -714,8 +742,9 @@  discard block
 block discarded – undo
714 742
      */
715 743
     public function process()
716 744
     {
717
-        if ($this->isReady)
718
-            $this->onTick->run($this);
745
+        if ($this->isReady) {
746
+                    $this->onTick->run($this);
747
+        }
719 748
 
720 749
         Timer::update();
721 750
         $this->connector->read();
@@ -738,7 +767,9 @@  discard block
 block discarded – undo
738 767
      */
739 768
     public function getUserByJid(Jid $user)
740 769
     {
741
-        if (!$user->fromChannel()) return null;
770
+        if (!$user->fromChannel()) {
771
+            return null;
772
+        }
742 773
 
743 774
         return isset($this->rooms[$user->bare()]->users[$user->resource]) ?
744 775
             $this->rooms[$user->bare()]->users[$user->resource] :
@@ -819,7 +850,10 @@  discard block
 block discarded – undo
819 850
      */
820 851
     public function join(Jid $room, $nick)
821 852
     {
822
-        if (!$room->isChannel()) throw new \InvalidArgumentException('room'); // YOU SHALL NOT PASS
853
+        if (!$room->isChannel()) {
854
+            throw new \InvalidArgumentException('room');
855
+        }
856
+        // YOU SHALL NOT PASS
823 857
 
824 858
         $xml = new xmlBranch("presence");
825 859
         $xml->addAttribute("from", $this->jid->__toString())
@@ -845,7 +879,9 @@  discard block
 block discarded – undo
845 879
      */
846 880
     public function leave(Jid $room)
847 881
     {
848
-        if (!$room->isChannel() || !isset($this->rooms[$room->bare()])) throw new \InvalidArgumentException('room');
882
+        if (!$room->isChannel() || !isset($this->rooms[$room->bare()])) {
883
+            throw new \InvalidArgumentException('room');
884
+        }
849 885
 
850 886
         $xml = new xmlBranch("presence");
851 887
         $xml->addAttribute("from", $this->jid->__toString())
@@ -875,8 +911,9 @@  discard block
 block discarded – undo
875 911
      */
876 912
     public function role(Jid $room, $nick, $role, $reason = '')
877 913
     {
878
-        if (!in_array($role, array('visitor', 'none', 'participant', 'moderator')))
879
-            throw new \InvalidArgumentException('role');
914
+        if (!in_array($role, array('visitor', 'none', 'participant', 'moderator'))) {
915
+                    throw new \InvalidArgumentException('role');
916
+        }
880 917
 
881 918
         $xml = new xmlBranch("iq");
882 919
         $xml->addAttribute("type", "set")
@@ -889,7 +926,9 @@  discard block
 block discarded – undo
889 926
         $xml->query[0]->item[0]->addAttribute("nick", $nick);
890 927
         $xml->query[0]->item[0]->addAttribute("role", $role);
891 928
 
892
-        if (!empty($reason)) $xml->query[0]->item[0]->addChild(new xmlBranch("reason"))->setContent($reason);
929
+        if (!empty($reason)) {
930
+            $xml->query[0]->item[0]->addChild(new xmlBranch("reason"))->setContent($reason);
931
+        }
893 932
 
894 933
         $this->write($xml->asXml());
895 934
     }
@@ -909,8 +948,9 @@  discard block
 block discarded – undo
909 948
      */
910 949
     public function affiliate(Jid $room, Jid $user, $affiliation, $reason = '')
911 950
     {
912
-        if (!in_array($affiliation, array('none', 'outcast', 'member', 'admin', 'owner')))
913
-            throw new \InvalidArgumentException('affiliation');
951
+        if (!in_array($affiliation, array('none', 'outcast', 'member', 'admin', 'owner'))) {
952
+                    throw new \InvalidArgumentException('affiliation');
953
+        }
914 954
 
915 955
         $xml = new xmlBranch("iq");
916 956
         $xml->addAttribute("type", "set")
@@ -923,7 +963,9 @@  discard block
 block discarded – undo
923 963
         $xml->query[0]->item[0]->addAttribute("jid", $user->bare());
924 964
         $xml->query[0]->item[0]->addAttribute("affiliation", $affiliation);
925 965
 
926
-        if (!empty($reason)) $xml->query[0]->item[0]->addChild(new xmlBranch("reason"))->setContent($reason);
966
+        if (!empty($reason)) {
967
+            $xml->query[0]->item[0]->addChild(new xmlBranch("reason"))->setContent($reason);
968
+        }
927 969
 
928 970
         $this->write($xml->asXml());
929 971
     }
@@ -960,8 +1002,9 @@  discard block
 block discarded – undo
960 1002
      */
961 1003
     public function affiliationList(Jid $room, $affiliation, callable $delegate)
962 1004
     {
963
-        if (!in_array($affiliation, array('none', 'outcast', 'member', 'admin', 'owner')))
964
-            throw new \InvalidArgumentException('affiliation');
1005
+        if (!in_array($affiliation, array('none', 'outcast', 'member', 'admin', 'owner'))) {
1006
+                    throw new \InvalidArgumentException('affiliation');
1007
+        }
965 1008
 
966 1009
         $xml = new xmlBranch("iq");
967 1010
         $id  = uniqid('affiliate_');
@@ -1009,7 +1052,8 @@  discard block
 block discarded – undo
1009 1052
     }
1010 1053
 
1011 1054
     public function __destruct() {
1012
-        if($this->connector->connected)
1013
-            $this->disconnect();
1055
+        if($this->connector->connected) {
1056
+                    $this->disconnect();
1057
+        }
1014 1058
     }
1015 1059
 }
1016 1060
\ No newline at end of file
Please login to merge, or discard this patch.