| @@ -40,6 +40,6 @@ | ||
| 40 | 40 | |
| 41 | 41 | private function generateMessage(Error $error) : string | 
| 42 | 42 |      { | 
| 43 | -        return 'Stream error: '.str_replace('-', ' ', $error->kind).($error->text ? " ({$error->text})" : null); | |
| 43 | +        return 'Stream error: ' . str_replace('-', ' ', $error->kind) . ($error->text ? " ({$error->text})" : null); | |
| 44 | 44 | } | 
| 45 | 45 | } | 
| @@ -54,7 +54,7 @@ | ||
| 54 | 54 | continue; | 
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | -            $this->_results = array_merge($this->_results, array_map(function ($record) { | |
| 57 | +            $this->_results = array_merge($this->_results, array_map(function($record) { | |
| 58 | 58 | return [$record['target'], $record['port']]; | 
| 59 | 59 | }, $result)); | 
| 60 | 60 | } | 
| @@ -42,13 +42,13 @@ | ||
| 42 | 42 | |
| 43 | 43 |              if ($stream = @stream_socket_client("tcp://$ip:$port")) { | 
| 44 | 44 | $stream = new TcpStream($stream, $this->_loop); | 
| 45 | -                $this->emit('connect', [ $stream ]); | |
| 45 | +                $this->emit('connect', [$stream]); | |
| 46 | 46 | |
| 47 | 47 | return $stream; | 
| 48 | 48 | } | 
| 49 | 49 | } | 
| 50 | 50 | |
| 51 | -        throw new \RuntimeException('Cannot connect to '.$this->_host); | |
| 51 | +        throw new \RuntimeException('Cannot connect to ' . $this->_host); | |
| 52 | 52 | } | 
| 53 | 53 | |
| 54 | 54 | public function __construct(string $host, LoopInterface $loop) | 
| @@ -72,9 +72,9 @@ discard block | ||
| 72 | 72 |      { | 
| 73 | 73 | $console = Console::get(); | 
| 74 | 74 | |
| 75 | - $result = $console->styled(['color' => 'yellow'], 'array').' with '.$console->styled(['color' => 'magenta'], count($array)).' elements:'.PHP_EOL; | |
| 75 | + $result = $console->styled(['color' => 'yellow'], 'array') . ' with ' . $console->styled(['color' => 'magenta'], count($array)) . ' elements:' . PHP_EOL; | |
| 76 | 76 |          foreach ($array as $key => $value) { | 
| 77 | -            $result .= "\t".str_replace("\n", "\n\t", '['.$this->dump($key).']: '.$this->dump($value)).PHP_EOL; | |
| 77 | +            $result .= "\t" . str_replace("\n", "\n\t", '[' . $this->dump($key) . ']: ' . $this->dump($value)) . PHP_EOL; | |
| 78 | 78 | } | 
| 79 | 79 | |
| 80 | 80 | return $result; | 
| @@ -82,7 +82,7 @@ discard block | ||
| 82 | 82 | |
| 83 | 83 | public function init() | 
| 84 | 84 |      { | 
| 85 | -        $this->register('array',  [$this, '_dumpArray']); | |
| 85 | +        $this->register('array', [$this, '_dumpArray']); | |
| 86 | 86 |          $this->register('object', [$this, '_dumpObject']); | 
| 87 | 87 | } | 
| 88 | 88 | } | 
| @@ -107,7 +107,7 @@ | ||
| 107 | 107 |      { | 
| 108 | 108 |          foreach ($events as $event) { | 
| 109 | 109 |              if (!isset($this->_redirectors[$event])) { | 
| 110 | -                $this->_redirectors[$event] = function (...$arguments) use ($event) { | |
| 110 | +                $this->_redirectors[$event] = function(...$arguments) use ($event) { | |
| 111 | 111 | $this->emit($event, $arguments); | 
| 112 | 112 | }; | 
| 113 | 113 | } | 
| @@ -61,7 +61,7 @@ discard block | ||
| 61 | 61 | |
| 62 | 62 | public function remove($value) | 
| 63 | 63 |      { | 
| 64 | -        $this->_collection = array_filter($this->_collection, function ($e) use ($value) { | |
| 64 | +        $this->_collection = array_filter($this->_collection, function($e) use ($value) { | |
| 65 | 65 | return $e[1] !== $value; | 
| 66 | 66 | }); | 
| 67 | 67 | |
| @@ -70,7 +70,7 @@ discard block | ||
| 70 | 70 | |
| 71 | 71 | private function rebuildCache() | 
| 72 | 72 |      { | 
| 73 | -        usort($this->_collection, function ($a, $b) { | |
| 73 | +        usort($this->_collection, function($a, $b) { | |
| 74 | 74 | return $b[0] <=> $a[0]; | 
| 75 | 75 | }); | 
| 76 | 76 | |
| @@ -26,9 +26,9 @@ discard block | ||
| 26 | 26 | function typeof($value) : string | 
| 27 | 27 |  { | 
| 28 | 28 |      if (is_object($value)) { | 
| 29 | - return "object of type ".get_class($value); | |
| 29 | + return "object of type " . get_class($value); | |
| 30 | 30 |      } elseif (is_resource($value)) { | 
| 31 | - return get_resource_type($value).' resource'; | |
| 31 | + return get_resource_type($value) . ' resource'; | |
| 32 | 32 |      } else { | 
| 33 | 33 | return gettype($value); | 
| 34 | 34 | } | 
| @@ -36,10 +36,10 @@ discard block | ||
| 36 | 36 | |
| 37 | 37 | function partial(callable $callable, $argument, int $position = 0) : callable | 
| 38 | 38 |  { | 
| 39 | -    return function (...$arguments) use ($callable, $argument, $position) { | |
| 39 | +    return function(...$arguments) use ($callable, $argument, $position) { | |
| 40 | 40 | $arguments = array_merge( | 
| 41 | 41 | array_slice($arguments, 0, $position), | 
| 42 | - [ $argument ], | |
| 42 | + [$argument], | |
| 43 | 43 | array_slice($arguments, $position) | 
| 44 | 44 | ); | 
| 45 | 45 | |
| @@ -49,10 +49,10 @@ discard block | ||
| 49 | 49 | |
| 50 | 50 | function dd($value) | 
| 51 | 51 |  { | 
| 52 | - echo Dumper::get()->dump($value).PHP_EOL.PHP_EOL; | |
| 52 | + echo Dumper::get()->dump($value) . PHP_EOL . PHP_EOL; | |
| 53 | 53 | } | 
| 54 | 54 | |
| 55 | 55 | function format($string, array $arguments = []) | 
| 56 | 56 |  { | 
| 57 | -    return str_replace(array_map(function ($e) { return "{{$e}}"; }, array_keys($arguments)), $arguments, $string); | |
| 57 | +    return str_replace(array_map(function($e) { return "{{$e}}"; }, array_keys($arguments)), $arguments, $string); | |
| 58 | 58 | } | 
| @@ -32,6 +32,10 @@ | ||
| 32 | 32 | return $this->addListener($event, $this->getConditionalCallable($listener, $condition), $priority); | 
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | + /** | |
| 36 | + * @param string $event | |
| 37 | + * @param \Closure $condition | |
| 38 | + */ | |
| 35 | 39 | public function once($event, callable $listener, $condition = null, int $priority = 0) | 
| 36 | 40 |      { | 
| 37 | 41 | return $this->on($event, $this->getOnceCallable($this->getConditionalCallable($listener, $condition), $event), null, $priority); | 
| @@ -56,7 +56,7 @@ discard block | ||
| 56 | 56 | return false; | 
| 57 | 57 | } | 
| 58 | 58 |              } catch (\Throwable $exception) { | 
| 59 | -                if($this->emit('exception', [ $exception, $event ])) { | |
| 59 | +                if ($this->emit('exception', [$exception, $event])) { | |
| 60 | 60 | throw $exception; | 
| 61 | 61 | } | 
| 62 | 62 | } | 
| @@ -89,7 +89,7 @@ discard block | ||
| 89 | 89 | |
| 90 | 90 | $condition = with\predicate($condition); | 
| 91 | 91 | |
| 92 | -        return function (...$arguments) use ($listener, $condition) { | |
| 92 | +        return function(...$arguments) use ($listener, $condition) { | |
| 93 | 93 |              if ($condition(...$arguments)) { | 
| 94 | 94 | return (bool)$listener(...$arguments); | 
| 95 | 95 | } | 
| @@ -100,8 +100,8 @@ discard block | ||
| 100 | 100 | |
| 101 | 101 | private function getOnceCallable(callable $listener, $event) : callable | 
| 102 | 102 |      { | 
| 103 | -        return $onceListener = function (...$arguments) use (&$onceListener, $event, $listener) { | |
| 104 | -            if(($result = $listener(...$arguments)) !== null) { | |
| 103 | +        return $onceListener = function(...$arguments) use (&$onceListener, $event, $listener) { | |
| 104 | +            if (($result = $listener(...$arguments)) !== null) { | |
| 105 | 105 | $this->removeListener($event, $onceListener); | 
| 106 | 106 | return $result; | 
| 107 | 107 | } | 
| @@ -59,7 +59,7 @@ discard block | ||
| 59 | 59 |      { | 
| 60 | 60 | parent::setClient($client); | 
| 61 | 61 | |
| 62 | -        $client->on('features', function (Features $features) { | |
| 62 | +        $client->on('features', function(Features $features) { | |
| 63 | 63 | return !$this->auth($features); | 
| 64 | 64 | }); | 
| 65 | 65 | } | 
| @@ -68,7 +68,7 @@ discard block | ||
| 68 | 68 |      { | 
| 69 | 69 |          if (!empty($features->mechanisms)) { | 
| 70 | 70 |              foreach ($features->mechanisms as $name) { | 
| 71 | -                if($this->tryMechanism($name)) { | |
| 71 | +                if ($this->tryMechanism($name)) { | |
| 72 | 72 | return true; | 
| 73 | 73 | } | 
| 74 | 74 | } | 
| @@ -112,11 +112,11 @@ discard block | ||
| 112 | 112 | $response = '='; | 
| 113 | 113 | } | 
| 114 | 114 | |
| 115 | -        $callback = $this->_client->on('element', function (XmlElement $challenge) use ($mechanism) { | |
| 115 | +        $callback = $this->_client->on('element', function(XmlElement $challenge) use ($mechanism) { | |
| 116 | 116 | $this->handleChallenge($challenge, $mechanism); | 
| 117 | 117 |          }, with\all(with\tag('challenge'), with\xmlns(self::XMLNS))); | 
| 118 | 118 | |
| 119 | -        $this->_client->once('element', function (XmlElement $result) use ($callback) { | |
| 119 | +        $this->_client->once('element', function(XmlElement $result) use ($callback) { | |
| 120 | 120 |              $this->_client->removeListener('element', $callback); | 
| 121 | 121 | $this->handleAuthResult($result); | 
| 122 | 122 |          }, with\all(with\any(with\tag('success'), with\tag('failure')), with\xmlns(self::XMLNS))); | 
| @@ -126,7 +126,7 @@ discard block | ||
| 126 | 126 | |
| 127 | 127 | private function mechanismWithoutChallenge(AuthenticationInterface $mechanism) | 
| 128 | 128 |      { | 
| 129 | -        $this->_client->once('element', function (XmlElement $result) { | |
| 129 | +        $this->_client->once('element', function(XmlElement $result) { | |
| 130 | 130 | $this->handleAuthResult($result); | 
| 131 | 131 |          }, with\all(with\any(with\tag('success'), with\tag('failure')), with\xmlns(self::XMLNS))); | 
| 132 | 132 | |
| @@ -144,7 +144,7 @@ discard block | ||
| 144 | 144 | private function handleAuthResult(XmlElement $result) | 
| 145 | 145 |      { | 
| 146 | 146 |          if ($result->localName === 'failure') { | 
| 147 | -            throw new AuthenticationException('Unable to auth. '.trim($result->innerXml)); | |
| 147 | +            throw new AuthenticationException('Unable to auth. ' . trim($result->innerXml)); | |
| 148 | 148 | } | 
| 149 | 149 | |
| 150 | 150 |          $this->_client->getLogger()->info('Successfully authorized as {name}.', ['name' => (string)$this->_client->jid]); |