@@ -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 |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | xml_parser_set_option($this->_parser, XML_OPTION_SKIP_WHITE, 1); |
72 | 72 | xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, 0); |
73 | 73 | |
74 | - xml_set_element_handler($this->_parser, function ($parser, $name, $attrs) { |
|
74 | + xml_set_element_handler($this->_parser, function($parser, $name, $attrs) { |
|
75 | 75 | $this->handleElementStart($name, $attrs); |
76 | - }, function ($parser, $name) { |
|
76 | + }, function($parser, $name) { |
|
77 | 77 | $this->handleElementEnd(); |
78 | 78 | }); |
79 | 79 | |
80 | - xml_set_character_data_handler($this->_parser, function ($parser, $data) { |
|
80 | + xml_set_character_data_handler($this->_parser, function($parser, $data) { |
|
81 | 81 | $this->handleTextData($data); |
82 | 82 | }); |
83 | 83 | |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | list($attributes, $namespaces) = $this->_attributes($attrs); |
120 | 120 | list($tag, $prefix) = XmlElement::resolve($name); |
121 | 121 | |
122 | - $uri = $this->_lookup($prefix, $namespaces); |
|
122 | + $uri = $this->_lookup($prefix, $namespaces); |
|
123 | 123 | |
124 | 124 | /** @var XmlElement $element */ |
125 | - $element = $this->factory->create($uri, $tag, [ $name, $uri ]); |
|
125 | + $element = $this->factory->create($uri, $tag, [$name, $uri]); |
|
126 | 126 | foreach ($attributes as $name => $value) { |
127 | 127 | $element->setAttribute($name, $value); |
128 | 128 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | if (count($this->_stack) > 1) { |
138 | 138 | end($this->_stack)->append($element); |
139 | 139 | } |
140 | - $this->emit('parse.begin', [ $element ]); |
|
140 | + $this->emit('parse.begin', [$element]); |
|
141 | 141 | |
142 | 142 | $this->_stack[] = $element; |
143 | 143 | } |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | |
151 | 151 | $element = array_pop($this->_stack); |
152 | 152 | if (count($this->_stack) == 1) { |
153 | - $this->emit('element', [ $element ]); |
|
153 | + $this->emit('element', [$element]); |
|
154 | 154 | } |
155 | 155 | |
156 | - $this->emit('parse.end', [ $element ]); |
|
156 | + $this->emit('parse.end', [$element]); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | private function handleTextData($data) |
@@ -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) |
@@ -37,15 +37,15 @@ |
||
37 | 37 | parent::__construct($parser, $transport); |
38 | 38 | |
39 | 39 | $this->_parser->factory->register(Features::class, self::NAMESPACE_URI, 'features'); |
40 | - $this->_parser->factory->register(Error::class, self::NAMESPACE_URI, 'error'); |
|
40 | + $this->_parser->factory->register(Error::class, self::NAMESPACE_URI, 'error'); |
|
41 | 41 | |
42 | 42 | $this->_lang = $lang; |
43 | 43 | |
44 | - $this->on('element', function (Features $element) { |
|
44 | + $this->on('element', function(Features $element) { |
|
45 | 45 | $this->handleFeatures($element); |
46 | 46 | }, Features::class); |
47 | 47 | |
48 | - $this->on('element', function (XmlElement $element) { |
|
48 | + $this->on('element', function(XmlElement $element) { |
|
49 | 49 | $this->handleTls($element); |
50 | 50 | }, with\xmlns(self::TLS_NAMESPACE)); |
51 | 51 | } |