@@ -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 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public function removeListener($event, callable $listener) |
42 | 42 | { |
43 | - if(!isset($this->listeners[$event])) { |
|
43 | + if (!isset($this->listeners[$event])) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | |
67 | 67 | private function addListener($event, callable $listener, int $priority = 0) |
68 | 68 | { |
69 | - if(!isset($this->listeners[$event])) { |
|
69 | + if (!isset($this->listeners[$event])) { |
|
70 | 70 | $this->listeners[$event] = new PriorityCollection(); |
71 | 71 | } |
72 | 72 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | $condition = $this->emitterResolveCondition($condition); |
83 | - return function (...$arguments) use ($listener, $condition) { |
|
83 | + return function(...$arguments) use ($listener, $condition) { |
|
84 | 84 | if ($condition(...$arguments)) { |
85 | 85 | $listener(...$arguments); |
86 | 86 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | private function getOnceCallable(callable $listener, $event) : callable |
91 | 91 | { |
92 | - return $onceListener = function (...$arguments) use (&$onceListener, $event, $listener) { |
|
92 | + return $onceListener = function(...$arguments) use (&$onceListener, $event, $listener) { |
|
93 | 93 | $this->removeListener($event, $onceListener); |
94 | 94 | |
95 | 95 | $listener(...$arguments); |
@@ -19,28 +19,28 @@ discard block |
||
19 | 19 | |
20 | 20 | function xmlns($uri) |
21 | 21 | { |
22 | - return function (XmlElement $element) use ($uri) { |
|
22 | + return function(XmlElement $element) use ($uri) { |
|
23 | 23 | return $element->namespaceURI === $uri; |
24 | 24 | }; |
25 | 25 | } |
26 | 26 | |
27 | 27 | function tag($name) |
28 | 28 | { |
29 | - return function (XmlElement $element) use ($name) { |
|
29 | + return function(XmlElement $element) use ($name) { |
|
30 | 30 | return $element->localName === $name; |
31 | 31 | }; |
32 | 32 | } |
33 | 33 | |
34 | 34 | function ofType($class) |
35 | 35 | { |
36 | - return function ($object) use ($class) { |
|
36 | + return function($object) use ($class) { |
|
37 | 37 | return $object instanceof $class; |
38 | 38 | }; |
39 | 39 | } |
40 | 40 | |
41 | 41 | function all(callable ...$functions) |
42 | 42 | { |
43 | - return function (...$args) use ($functions) { |
|
43 | + return function(...$args) use ($functions) { |
|
44 | 44 | foreach ($functions as $function) { |
45 | 45 | if (!$function(...$args)) { |
46 | 46 | return false; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | function any(callable ...$functions) |
55 | 55 | { |
56 | - return function (...$args) use ($functions) { |
|
56 | + return function(...$args) use ($functions) { |
|
57 | 57 | foreach ($functions as $function) { |
58 | 58 | if ($function(...$args)) { |
59 | 59 | return true; |
@@ -39,7 +39,7 @@ |
||
39 | 39 | |
40 | 40 | public function getText() |
41 | 41 | { |
42 | - if($text = $this->query(".//xmpp:text")->with('xmpp', 'urn:ietf:params:xml:ns:xmpp-streams')->query()->item(0)) { |
|
42 | + if ($text = $this->query(".//xmpp:text")->with('xmpp', 'urn:ietf:params:xml:ns:xmpp-streams')->query()->item(0)) { |
|
43 | 43 | return $text; |
44 | 44 | } |
45 | 45 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public function query(string $query = null) |
34 | 34 | { |
35 | 35 | /** @var \DOMNode $element */ |
36 | - foreach($this->_xpath->query($query ?: $this->_query) as $element) { |
|
36 | + foreach ($this->_xpath->query($query ?: $this->_query) as $element) { |
|
37 | 37 | yield $this->getElementFromPath($element->getNodePath()); |
38 | 38 | } |
39 | 39 | } |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | array_shift($path); |
71 | 71 | |
72 | 72 | $current = $this->_context; |
73 | - foreach($path as $chunk) { |
|
73 | + foreach ($path as $chunk) { |
|
74 | 74 | // Chunk is in format node-name[index], parse it with regex |
75 | 75 | preg_match('/([\w\*]+)(?:\[([0-9]+)\])?/', $chunk, $matches); |
76 | 76 | |
77 | 77 | $name = $matches[1]; |
78 | 78 | $index = isset($matches[2]) ? $matches[2] - 1 : 0; |
79 | 79 | |
80 | - if($name == '*') { |
|
80 | + if ($name == '*') { |
|
81 | 81 | // Path returns * if namespace occurs so we need to obtain index-th child |
82 | 82 | $current = $current->children[$index]; |
83 | 83 | } else { |
@@ -76,25 +76,25 @@ discard block |
||
76 | 76 | |
77 | 77 | $this->_parser = $parser; |
78 | 78 | |
79 | - $this->on('element', function (Error $element) { |
|
79 | + $this->on('element', function(Error $element) { |
|
80 | 80 | $this->handleError($element); |
81 | 81 | }, with\ofType(Error::class)); |
82 | 82 | |
83 | - $this->_parser->on('parse.begin', function (XmlElement $stream) { |
|
83 | + $this->_parser->on('parse.begin', function(XmlElement $stream) { |
|
84 | 84 | $this->_stream = $stream; |
85 | - $this->emit('stream.open', [ $stream ]); |
|
85 | + $this->emit('stream.open', [$stream]); |
|
86 | 86 | }, with\all(with\tag('stream'), with\xmlns(self::NAMESPACE_URI))); |
87 | 87 | |
88 | - $this->_parser->on('parse.end', function (XmlElement $stream) { |
|
89 | - $this->emit('stream.close', [ $stream ]); |
|
88 | + $this->_parser->on('parse.end', function(XmlElement $stream) { |
|
89 | + $this->emit('stream.close', [$stream]); |
|
90 | 90 | $this->_stream = null; |
91 | 91 | }, with\all(with\tag('stream'), with\xmlns(self::NAMESPACE_URI))); |
92 | 92 | |
93 | 93 | $this->on('data', [$this->_parser, 'parse']); |
94 | - $this->_parser->on('element', function (...$arguments) { |
|
94 | + $this->_parser->on('element', function(...$arguments) { |
|
95 | 95 | $this->emit('element', $arguments); |
96 | 96 | }); |
97 | - $this->on('close', function () { $this->_isOpened = false; }); |
|
97 | + $this->on('close', function() { $this->_isOpened = false; }); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function write($data) |
108 | 108 | { |
109 | - $this->emit('send.'.($data instanceof XmlElement ? 'element' : 'text'), [ $data ]); |
|
109 | + $this->emit('send.' . ($data instanceof XmlElement ? 'element' : 'text'), [$data]); |
|
110 | 110 | |
111 | 111 | return parent::write($data); |
112 | 112 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function close() |
138 | 138 | { |
139 | - if($this->isOpened()) { |
|
139 | + if ($this->isOpened()) { |
|
140 | 140 | $this->write('</stream:stream>'); |
141 | 141 | $this->_isOpened = false; |
142 | 142 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | private function handleError(Error $element) |
173 | 173 | { |
174 | - if($this->emit('stream.error', [ $element ])) { |
|
174 | + if ($this->emit('stream.error', [$element])) { |
|
175 | 175 | throw new StreamErrorException($element); |
176 | 176 | } |
177 | 177 |
@@ -41,14 +41,14 @@ |
||
41 | 41 | 'port' => $port |
42 | 42 | ]); |
43 | 43 | |
44 | - if($stream = @stream_socket_client("tcp://$ip:$port")) { |
|
44 | + if ($stream = @stream_socket_client("tcp://$ip:$port")) { |
|
45 | 45 | $stream = new TcpStream($stream, $this->_loop); |
46 | - $this->emit('connect', [ $stream ]); |
|
46 | + $this->emit('connect', [$stream]); |
|
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) |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * XMPP Library |
4 | 4 | * |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __construct(DuplexStreamInterface $decorated = null) |
38 | 38 | { |
39 | - if($decorated !== null) { |
|
39 | + if ($decorated !== null) { |
|
40 | 40 | $this->exchangeStream($decorated); |
41 | 41 | } |
42 | 42 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | { |
86 | 86 | static $events = ['data', 'end', 'drain', 'error', 'close', 'pipe']; |
87 | 87 | |
88 | - if($this->_decorated !== null) { |
|
88 | + if ($this->_decorated !== null) { |
|
89 | 89 | $this->unsubscribe($this->_decorated, $events); |
90 | 90 | } |
91 | 91 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | private function unsubscribe(DuplexStreamInterface $stream, array $events) |
97 | 97 | { |
98 | 98 | foreach ($events as $event) { |
99 | - if(!isset($this->_redirectors[$event])) { |
|
99 | + if (!isset($this->_redirectors[$event])) { |
|
100 | 100 | continue; |
101 | 101 | } |
102 | 102 | |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | private function subscribe(DuplexStreamInterface $stream, array $events) |
108 | 108 | { |
109 | 109 | foreach ($events as $event) { |
110 | - if(!isset($this->_redirectors[$event])) { |
|
111 | - $this->_redirectors[$event] = function (...$arguments) use ($event) { |
|
110 | + if (!isset($this->_redirectors[$event])) { |
|
111 | + $this->_redirectors[$event] = function(...$arguments) use ($event) { |
|
112 | 112 | $this->emit($event, $arguments); |
113 | 113 | }; |
114 | 114 | } |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | |
38 | 38 | private function getDumper($value) |
39 | 39 | { |
40 | - if(is_object($value)) { |
|
40 | + if (is_object($value)) { |
|
41 | 41 | $class = get_class($value); |
42 | 42 | foreach (array_merge([$class], class_parents($class), class_implements($class)) as $class) { |
43 | - if(isset($this->_dumpers[$class])) { |
|
43 | + if (isset($this->_dumpers[$class])) { |
|
44 | 44 | return $this->_dumpers[$class]; |
45 | 45 | } |
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | - if(isset($this->_dumpers[gettype($value)])) { |
|
49 | + if (isset($this->_dumpers[gettype($value)])) { |
|
50 | 50 | return $this->_dumpers[gettype($value)]; |
51 | 51 | } |
52 | 52 | |
@@ -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; |
|
76 | - foreach($array as $key => $value) { |
|
77 | - $result .= "\t".str_replace("\n", "\n\t", '['.$this->dump($key).']: '.$this->dump($value)).PHP_EOL; |
|
75 | + $result = $console->styled(['color' => 'yellow'], 'array') . ' with ' . $console->styled(['color' => 'magenta'], count($array)) . ' elements:' . PHP_EOL; |
|
76 | + foreach ($array as $key => $value) { |
|
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 | } |