@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function setType(string $type) |
| 68 | 68 | { |
| 69 | - if(!in_array($type, ['auth', 'cancel', 'continue', 'modify', 'wait'])) { |
|
| 69 | + if (!in_array($type, ['auth', 'cancel', 'continue', 'modify', 'wait'])) { |
|
| 70 | 70 | throw new InvalidArgumentException( |
| 71 | 71 | format("Error type must be 'auth', 'cancel', 'continue', 'modify' or 'wait', '{type}' given.", [ |
| 72 | 72 | 'type' => $type |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function setText(string $text) |
| 114 | 114 | { |
| 115 | - if(!$this->text) { |
|
| 115 | + if (!$this->text) { |
|
| 116 | 116 | $this->append(new XmlElement('text', self::XMLNS)); |
| 117 | 117 | } |
| 118 | 118 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | !$condition instanceof XmlElement ? $this->_definedCondition($condition) : $condition |
| 135 | 135 | ]; |
| 136 | 136 | |
| 137 | - if($description !== null) { |
|
| 137 | + if ($description !== null) { |
|
| 138 | 138 | $content[] = new XmlElement('text', self::XMLNS, ['content' => $description]); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | private function _definedCondition(string $condition) : XmlElement |
| 147 | 147 | { |
| 148 | - if(!in_array($condition, [ |
|
| 148 | + if (!in_array($condition, [ |
|
| 149 | 149 | 'bad-request', 'conflict', 'feature-not-implemented', 'forbidden', |
| 150 | 150 | 'gone', 'internal-server-error', 'item-not-found', 'jid-malformed', |
| 151 | 151 | 'not-acceptable', 'not-allowed', 'not-authorized', 'policy-violation', |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function __construct(array $features = []) |
| 40 | 40 | { |
| 41 | - parent::__construct('stream:features', XmlStream::NAMESPACE_URI, [ 'content' => $features ]); |
|
| 41 | + parent::__construct('stream:features', XmlStream::NAMESPACE_URI, ['content' => $features]); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | public function getMechanisms() |
| 53 | 53 | { |
| 54 | - return array_map(function (XmlElement $element) { |
|
| 54 | + return array_map(function(XmlElement $element) { |
|
| 55 | 55 | return $element->innerXml; |
| 56 | 56 | }, $this->get(\Kadet\Xmpp\Utils\filter\tag('mechanisms'))->children ?? []); |
| 57 | 57 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function getInnerXml() |
| 137 | 137 | { |
| 138 | - return implode('', array_map(function ($element) { |
|
| 138 | + return implode('', array_map(function($element) { |
|
| 139 | 139 | if (is_string($element)) { |
| 140 | 140 | return htmlspecialchars($element); |
| 141 | 141 | } elseif ($element instanceof XmlElement) { |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | $attributes = $this->attributes(); |
| 181 | 181 | |
| 182 | 182 | $result = "<{$this->name}"; |
| 183 | - $result .= ' ' . implode(' ', array_map(function ($key, $value) { |
|
| 183 | + $result .= ' ' . implode(' ', array_map(function($key, $value) { |
|
| 184 | 184 | return $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; |
| 185 | 185 | }, array_keys($attributes), array_values($attributes))); |
| 186 | 186 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | public function lookupPrefix(string $uri = null) |
| 203 | 203 | { |
| 204 | - return $this->getNamespaces()[ $uri ] ?? false; |
|
| 204 | + return $this->getNamespaces()[$uri] ?? false; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -245,12 +245,12 @@ discard block |
||
| 245 | 245 | { |
| 246 | 246 | $attribute = $this->_prefix($attribute, $uri); |
| 247 | 247 | if ($value === null) { |
| 248 | - unset($this->_attributes[ $attribute ]); |
|
| 248 | + unset($this->_attributes[$attribute]); |
|
| 249 | 249 | |
| 250 | 250 | return; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - $this->_attributes[ $attribute ] = $value; |
|
| 253 | + $this->_attributes[$attribute] = $value; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | public function getAttribute(string $attribute, string $uri = null) |
| 264 | 264 | { |
| 265 | - return $this->_attributes[ $this->_prefix($attribute, $uri) ] ?? false; |
|
| 265 | + return $this->_attributes[$this->_prefix($attribute, $uri)] ?? false; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | public function hasAttribute(string $attribute, string $uri = null) |
| 277 | 277 | { |
| 278 | - return isset($this->_attributes[ $this->_prefix($attribute, $uri) ]); |
|
| 278 | + return isset($this->_attributes[$this->_prefix($attribute, $uri)]); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | */ |
| 285 | 285 | public function getParents() |
| 286 | 286 | { |
| 287 | - return $this->_parent ? array_merge([ $this->_parent ], $this->_parent->getParents()) : []; |
|
| 287 | + return $this->_parent ? array_merge([$this->_parent], $this->_parent->getParents()) : []; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | protected function setParent(XmlElement $parent) |
| 304 | 304 | { |
| 305 | 305 | if (!$this->_prefix && ($prefix = $parent->lookupPrefix($this->namespace)) !== false) { |
| 306 | - $this->_namespaces[ $this->namespace ] = $prefix; |
|
| 306 | + $this->_namespaces[$this->namespace] = $prefix; |
|
| 307 | 307 | $this->_prefix = $prefix; |
| 308 | 308 | } |
| 309 | 309 | |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | return false; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if(is_array($element)) { |
|
| 329 | + if (is_array($element)) { |
|
| 330 | 330 | array_walk($element, [$this, 'append']); |
| 331 | 331 | return $element; |
| 332 | 332 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | $prefix = $this->_prefix; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - $this->_namespaces[ $uri ] = $prefix; |
|
| 373 | + $this->_namespaces[$uri] = $prefix; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | public function getName() |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | public function element(string $name, string $uri = null, int $index = 0) |
| 420 | 420 | { |
| 421 | - return array_values($this->elements($name, $uri))[ $index ] ?? false; |
|
| 421 | + return array_values($this->elements($name, $uri))[$index] ?? false; |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | /** |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | private function attributes(): array |
| 493 | 493 | { |
| 494 | 494 | $namespaces = $this->getNamespaces(false); |
| 495 | - $namespaces = array_map(function ($prefix, $uri) { |
|
| 495 | + $namespaces = array_map(function($prefix, $uri) { |
|
| 496 | 496 | return [$prefix ? "xmlns:{$prefix}" : 'xmlns', $uri]; |
| 497 | 497 | }, array_values($namespaces), array_keys($namespaces)); |
| 498 | 498 | |
@@ -258,7 +258,7 @@ |
||
| 258 | 258 | * |
| 259 | 259 | * @param string $attribute Attribute name, optionally with prefix |
| 260 | 260 | * @param string|null $uri XML Namespace URI of attribute, prefix will be automatically looked up |
| 261 | - * @return bool|mixed |
|
| 261 | + * @return string |
|
| 262 | 262 | */ |
| 263 | 263 | public function getAttribute(string $attribute, string $uri = null) |
| 264 | 264 | { |
@@ -42,13 +42,13 @@ |
||
| 42 | 42 | |
| 43 | 43 | private static function _conditionDescription(Error $error) |
| 44 | 44 | { |
| 45 | - if(!empty($error->text)) { |
|
| 45 | + if (!empty($error->text)) { |
|
| 46 | 46 | return $error->text; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | return [ |
| 50 | 50 | 'bad-request' => 'Bad Request: "{resource}" is not valid XMPP resource identifier.', |
| 51 | 51 | 'conflict' => 'Conflict: {bare}/{resource} is already in use.' |
| 52 | - ][$error->condition] ?? 'Unknown reason: '.$error->condition; |
|
| 52 | + ][$error->condition] ?? 'Unknown reason: ' . $error->condition; |
|
| 53 | 53 | } |
| 54 | 54 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | $predicate = $uri instanceof \Closure ? $uri : \Kadet\Xmpp\Utils\filter\same($uri); |
| 43 | 43 | |
| 44 | - return function ($element) use ($predicate) { |
|
| 44 | + return function($element) use ($predicate) { |
|
| 45 | 45 | if (!$element instanceof XmlElement) { |
| 46 | 46 | return false; |
| 47 | 47 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | $predicate = $name instanceof \Closure ? $name : \Kadet\Xmpp\Utils\filter\same($name); |
| 76 | 76 | |
| 77 | - return function ($element) use ($predicate) { |
|
| 77 | + return function($element) use ($predicate) { |
|
| 78 | 78 | if (!$element instanceof XmlElement) { |
| 79 | 79 | return false; |
| 80 | 80 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | $predicate = $value instanceof \Closure ? $value : \Kadet\Xmpp\Utils\filter\equals($value); |
| 110 | 110 | |
| 111 | - return function ($element) use ($name, $predicate) { |
|
| 111 | + return function($element) use ($name, $predicate) { |
|
| 112 | 112 | if (!$element instanceof XmlElement) { |
| 113 | 113 | return false; |
| 114 | 114 | } |
@@ -31,18 +31,18 @@ discard block |
||
| 31 | 31 | { |
| 32 | 32 | parent::setClient($client); |
| 33 | 33 | |
| 34 | - $client->on('features', function (Features $features) { |
|
| 34 | + $client->on('features', function(Features $features) { |
|
| 35 | 35 | return !$this->bind($features); |
| 36 | 36 | }); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function bind(Features $features) |
| 40 | 40 | { |
| 41 | - if($features->has(with\element('bind', self::XMLNS))) { |
|
| 41 | + if ($features->has(with\element('bind', self::XMLNS))) { |
|
| 42 | 42 | $stanza = new Stanza('iq', ['attributes' => ['type' => 'set']]); |
| 43 | 43 | $bind = $stanza->append(new XmlElement('bind', self::XMLNS)); |
| 44 | 44 | |
| 45 | - if(!$this->_client->jid->isBare()) { |
|
| 45 | + if (!$this->_client->jid->isBare()) { |
|
| 46 | 46 | $bind->append(new XmlElement('resource', null, ['content' => $this->_client->jid->resource])); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | public function handleResult(Stanza $stanza) |
| 61 | 61 | { |
| 62 | - if($stanza->type === 'error') { |
|
| 62 | + if ($stanza->type === 'error') { |
|
| 63 | 63 | throw BindingException::fromError($this->_client->jid, $stanza->error); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | public function getFrom() |
| 55 | 55 | { |
| 56 | - if((string)$this->_from !== $this->hasAttribute('from')) { |
|
| 56 | + if ((string)$this->_from !== $this->hasAttribute('from')) { |
|
| 57 | 57 | $this->_from = $this->hasAttribute('from') ? new Jid($this->_from) : null; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | public function getTo() |
| 64 | 64 | { |
| 65 | - if((string)$this->_to !== $this->hasAttribute('to')) { |
|
| 65 | + if ((string)$this->_to !== $this->hasAttribute('to')) { |
|
| 66 | 66 | $this->_to = $this->hasAttribute('to') ? new Jid($this->_to) : null; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | public function setFrom($from) |
| 88 | 88 | { |
| 89 | - if($from instanceof Jid) { |
|
| 89 | + if ($from instanceof Jid) { |
|
| 90 | 90 | $this->_from = $from instanceof Jid ? $from : new Jid($from); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | public function setTo($to) |
| 97 | 97 | { |
| 98 | - if($to instanceof Jid) { |
|
| 98 | + if ($to instanceof Jid) { |
|
| 99 | 99 | $this->_to = $to instanceof Jid ? $to : new Jid($to); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | public static function getXmlCollocations() : array |
| 132 | 132 | { |
| 133 | 133 | return [ |
| 134 | - [ Error::class, 'name' => 'error', 'uri' => 'jabber:client' ], |
|
| 134 | + [Error::class, 'name' => 'error', 'uri' => 'jabber:client'], |
|
| 135 | 135 | ]; |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -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 () { |
|
| 76 | + }, function() { |
|
| 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 | |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | return 'http://www.w3.org/2000/xmlns/'; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if (isset($namespaces[ $prefix ])) { |
|
| 115 | - return $namespaces[ $prefix ]; |
|
| 114 | + if (isset($namespaces[$prefix])) { |
|
| 115 | + return $namespaces[$prefix]; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | return !empty($this->_stack) ? end($this->_stack)->lookupUri($prefix) : null; |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | list($attributes, $namespaces) = $this->_attributes($attrs); |
| 124 | 124 | list($tag, $prefix) = XmlElement::resolve($name); |
| 125 | 125 | |
| 126 | - $uri = $this->_lookup($prefix, $namespaces); |
|
| 126 | + $uri = $this->_lookup($prefix, $namespaces); |
|
| 127 | 127 | |
| 128 | 128 | /** @var XmlElement $element */ |
| 129 | - $element = $this->factory->create($uri, $tag, [ $name, $uri ], $this->_getCollocations()); |
|
| 129 | + $element = $this->factory->create($uri, $tag, [$name, $uri], $this->_getCollocations()); |
|
| 130 | 130 | |
| 131 | 131 | foreach ($namespaces as $prefix => $uri) { |
| 132 | 132 | $element->setNamespace($uri, $prefix); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | private function _getCollocations() |
| 142 | 142 | { |
| 143 | - if(empty($this->_stack)) { |
|
| 143 | + if (empty($this->_stack)) { |
|
| 144 | 144 | return []; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | if (count($this->_stack) > 0) { |
| 160 | 160 | end($this->_stack)->append($element); |
| 161 | 161 | } |
| 162 | - $this->emit('parse.begin', [ $element, count($this->_stack) ]); |
|
| 162 | + $this->emit('parse.begin', [$element, count($this->_stack)]); |
|
| 163 | 163 | |
| 164 | 164 | $this->_stack[] = $element; |
| 165 | 165 | } |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | |
| 173 | 173 | $element = array_pop($this->_stack); |
| 174 | 174 | if (count($this->_stack) == 1) { |
| 175 | - $this->emit('element', [ $element, count($this->_stack) ]); |
|
| 175 | + $this->emit('element', [$element, count($this->_stack)]); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - $this->emit('parse.end', [ $element, count($this->_stack) ]); |
|
| 178 | + $this->emit('parse.end', [$element, count($this->_stack)]); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | private function handleTextData($data) |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function equals($value) : \Closure |
| 36 | 36 | { |
| 37 | - return function ($argument) use ($value) { |
|
| 37 | + return function($argument) use ($value) { |
|
| 38 | 38 | return $argument == $value; |
| 39 | 39 | }; |
| 40 | 40 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function same($value) : \Closure |
| 57 | 57 | { |
| 58 | - return function ($argument) use ($value) { |
|
| 58 | + return function($argument) use ($value) { |
|
| 59 | 59 | return $argument === $value; |
| 60 | 60 | }; |
| 61 | 61 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function instance($expected) : \Closure |
| 79 | 79 | { |
| 80 | - return function ($object) use ($expected) { |
|
| 80 | + return function($object) use ($expected) { |
|
| 81 | 81 | return $expected instanceof \Closure ? $expected(get_class($object)) : $object instanceof $expected; |
| 82 | 82 | }; |
| 83 | 83 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | function matches($regex, ...$options) : \Closure |
| 105 | 105 | { |
| 106 | - return function ($value) use ($regex, $options) { |
|
| 106 | + return function($value) use ($regex, $options) { |
|
| 107 | 107 | return preg_match($regex, $value, $null, ...$options) > 0; |
| 108 | 108 | }; |
| 109 | 109 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @return \Closure |
| 123 | 123 | */ |
| 124 | 124 | function in(...$options) { |
| 125 | - return function ($value) use ($options) { |
|
| 125 | + return function($value) use ($options) { |
|
| 126 | 126 | return in_array($value, $options); |
| 127 | 127 | }; |
| 128 | 128 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | function all(callable ...$functions) : \Closure |
| 198 | 198 | { |
| 199 | - return function (...$args) use ($functions) { |
|
| 199 | + return function(...$args) use ($functions) { |
|
| 200 | 200 | foreach ($functions as $function) { |
| 201 | 201 | if (!$function(...$args)) { |
| 202 | 202 | return false; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | function any(callable ...$functions) : \Closure |
| 227 | 227 | { |
| 228 | - return function (...$args) use ($functions) { |
|
| 228 | + return function(...$args) use ($functions) { |
|
| 229 | 229 | foreach ($functions as $function) { |
| 230 | 230 | if ($function(...$args)) { |
| 231 | 231 | return true; |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | */ |
| 270 | 270 | function not(callable $predicate) : \Closure |
| 271 | 271 | { |
| 272 | - return function (...$arguments) use ($predicate) { |
|
| 272 | + return function(...$arguments) use ($predicate) { |
|
| 273 | 273 | return !$predicate(...$arguments); |
| 274 | 274 | }; |
| 275 | 275 | } |
@@ -297,13 +297,13 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | function argument(int $offset, callable $predicate, $length = true) : \Closure |
| 299 | 299 | { |
| 300 | - if($length === true) { |
|
| 300 | + if ($length === true) { |
|
| 301 | 301 | $length = 1; |
| 302 | - } elseif($length === false) { |
|
| 302 | + } elseif ($length === false) { |
|
| 303 | 303 | $length = null; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - return function (...$arguments) use ($predicate, $offset, $length) { |
|
| 306 | + return function(...$arguments) use ($predicate, $offset, $length) { |
|
| 307 | 307 | return $predicate(...array_slice($arguments, $offset, $length, false)); |
| 308 | 308 | }; |
| 309 | 309 | } |
@@ -326,9 +326,9 @@ discard block |
||
| 326 | 326 | */ |
| 327 | 327 | function consecutive(callable ...$predicates) |
| 328 | 328 | { |
| 329 | - return function (...$arguments) use ($predicates) { |
|
| 329 | + return function(...$arguments) use ($predicates) { |
|
| 330 | 330 | foreach ($arguments as $index => $value) { |
| 331 | - if(!$predicates[$index]($value)) { |
|
| 331 | + if (!$predicates[$index]($value)) { |
|
| 332 | 332 | return false; |
| 333 | 333 | } |
| 334 | 334 | } |