@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | -class Document extends DOMDocument{ |
|
| 29 | +class Document extends DOMDocument { |
|
| 30 | 30 | |
| 31 | 31 | protected const NODE_CLASSES = [ |
| 32 | 32 | 'DOMAttr' => Attr::class, |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | * @param string|null $version |
| 57 | 57 | * @param string|null $encoding |
| 58 | 58 | */ |
| 59 | - public function __construct($content = null, bool $xml = null, string $version = null, string $encoding = null){ |
|
| 59 | + public function __construct($content = null, bool $xml = null, string $version = null, string $encoding = null) { |
|
| 60 | 60 | parent::__construct($version ?? '1.0', $encoding ?? 'UTF-8'); |
| 61 | 61 | |
| 62 | - foreach($this::NODE_CLASSES as $baseClass => $extendedClass){ |
|
| 62 | + foreach ($this::NODE_CLASSES as $baseClass => $extendedClass) { |
|
| 63 | 63 | $this->registerNodeClass($baseClass, $extendedClass); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if($content !== null){ |
|
| 66 | + if ($content !== null) { |
|
| 67 | 67 | $this->loadDocument($content, $xml); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -79,19 +79,19 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function loadDocument($content, bool $xml = null):Document{ |
| 81 | 81 | |
| 82 | - if($content instanceof NodeList){ |
|
| 82 | + if ($content instanceof NodeList) { |
|
| 83 | 83 | return $this->insertNodeList($content); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if($content instanceof DOMNodeList){ |
|
| 86 | + if ($content instanceof DOMNodeList) { |
|
| 87 | 87 | return $this->insertNodeList(new NodeList($content)); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if(!is_string($content)){ |
|
| 90 | + if (!is_string($content)) { |
|
| 91 | 91 | throw new DOMException('invalid document content'); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if(is_file($content) && is_readable($content)){ |
|
| 94 | + if (is_file($content) && is_readable($content)) { |
|
| 95 | 95 | return $this->loadDocumentFile($content, $xml); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | ? $this->load($file, $options) |
| 109 | 109 | : $this->loadHTMLFile($file, $options); |
| 110 | 110 | |
| 111 | - if($result === false){ |
|
| 111 | + if ($result === false) { |
|
| 112 | 112 | throw new DOMException('failed to load document from file: '.$file); // @codeCoverageIgnore |
| 113 | 113 | } |
| 114 | 114 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | ? $this->loadXML($documentSource, $options) |
| 126 | 126 | : $this->loadHTML($documentSource, $options); |
| 127 | 127 | |
| 128 | - if($result === false){ |
|
| 128 | + if ($result === false) { |
|
| 129 | 129 | throw new DOMException('failed to load document from string'); // @codeCoverageIgnore |
| 130 | 130 | } |
| 131 | 131 | |
@@ -139,19 +139,19 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function toNodeList($content):NodeList{ |
| 141 | 141 | |
| 142 | - if($content instanceof NodeList){ |
|
| 142 | + if ($content instanceof NodeList) { |
|
| 143 | 143 | return $content; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if($content instanceof DOMNode || $content instanceof PrototypeNode){ |
|
| 146 | + if ($content instanceof DOMNode || $content instanceof PrototypeNode) { |
|
| 147 | 147 | return new NodeList([$content]); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if($content instanceof DOMNodeList || is_iterable($content)){ |
|
| 150 | + if ($content instanceof DOMNodeList || is_iterable($content)) { |
|
| 151 | 151 | return new NodeList($content); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if(is_string($content)){ |
|
| 154 | + if (is_string($content)) { |
|
| 155 | 155 | $document = new self; |
| 156 | 156 | $document->loadHTML('<html lang="en"><body id="-import-content">'.$content.'</body></html>'); |
| 157 | 157 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | /** |
| 176 | 176 | * |
| 177 | 177 | */ |
| 178 | - public function query(string $xpath, DOMNode $contextNode = null):?NodeList{ |
|
| 178 | + public function query(string $xpath, DOMNode $contextNode = null): ?NodeList{ |
|
| 179 | 179 | $q = (new DOMXPath($this))->query($xpath, $contextNode); |
| 180 | 180 | |
| 181 | 181 | return $q !== false ? new NodeList($q) : null; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | /** |
| 185 | 185 | * |
| 186 | 186 | */ |
| 187 | - public function querySelectorAll(string $selector, DOMNode $contextNode = null, string $axis = null):?NodeList{ |
|
| 187 | + public function querySelectorAll(string $selector, DOMNode $contextNode = null, string $axis = null): ?NodeList{ |
|
| 188 | 188 | return $this->query($this->cssSelectorConverter->toXPath($selector, $axis ?? 'descendant-or-self::'), $contextNode); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | public function removeElementsBySelector(array $selectors, DOMNode $contextNode = null, string $axis = null):Document{ |
| 195 | 195 | $nodes = $this->select($selectors, $contextNode, $axis ?? 'descendant-or-self::'); |
| 196 | 196 | |
| 197 | - if(count($nodes) > 0){ |
|
| 197 | + if (count($nodes) > 0) { |
|
| 198 | 198 | |
| 199 | - foreach($nodes as $node){ |
|
| 199 | + foreach ($nodes as $node) { |
|
| 200 | 200 | $node->removeNode(); |
| 201 | 201 | } |
| 202 | 202 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | public function insertNodeList(NodeList $nodeList):Document{ |
| 212 | 212 | |
| 213 | - foreach($nodeList as $node){ |
|
| 213 | + foreach ($nodeList as $node) { |
|
| 214 | 214 | $this->appendChild($this->importNode($node->cloneNode(true), true)); |
| 215 | 215 | } |
| 216 | 216 | |
@@ -223,9 +223,9 @@ discard block |
||
| 223 | 223 | * @return \chillerlan\PrototypeDOM\Node\PrototypeHTMLElement|\DOMNode|null |
| 224 | 224 | * @throws \DOMException |
| 225 | 225 | */ |
| 226 | - public function getElementById($elementId):?DOMNode{ |
|
| 226 | + public function getElementById($elementId): ?DOMNode{ |
|
| 227 | 227 | |
| 228 | - if(!is_string($elementId)){ |
|
| 228 | + if (!is_string($elementId)) { |
|
| 229 | 229 | throw new DOMException('invalid element id'); |
| 230 | 230 | } |
| 231 | 231 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function inspect(DOMNode $context = null, bool $xml = null):string{ |
| 250 | 250 | |
| 251 | - if($xml === true){ |
|
| 251 | + if ($xml === true) { |
|
| 252 | 252 | return $this->saveXML($context); |
| 253 | 253 | } |
| 254 | 254 | |
@@ -263,15 +263,15 @@ discard block |
||
| 263 | 263 | $nodeType = $nodeType ?? XML_ELEMENT_NODE; |
| 264 | 264 | $elements = new NodeList; |
| 265 | 265 | |
| 266 | - foreach($selectors ?? ['*'] as $selector){ |
|
| 266 | + foreach ($selectors ?? ['*'] as $selector) { |
|
| 267 | 267 | |
| 268 | - if(!is_string($selector)){ |
|
| 268 | + if (!is_string($selector)) { |
|
| 269 | 269 | continue; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - foreach($this->querySelectorAll($selector, $contextNode, $axis ?? 'descendant-or-self::') as $element){ |
|
| 272 | + foreach ($this->querySelectorAll($selector, $contextNode, $axis ?? 'descendant-or-self::') as $element) { |
|
| 273 | 273 | |
| 274 | - if($element->nodeType === $nodeType){ |
|
| 274 | + if ($element->nodeType === $nodeType) { |
|
| 275 | 275 | $elements[] = $element; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -291,15 +291,15 @@ discard block |
||
| 291 | 291 | $maxLength = $maxLength ?? -1; |
| 292 | 292 | $nodes = new NodeList; |
| 293 | 293 | |
| 294 | - if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){ |
|
| 294 | + if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) { |
|
| 295 | 295 | |
| 296 | - while($element = $element->{$property}){ |
|
| 296 | + while ($element = $element->{$property}) { |
|
| 297 | 297 | |
| 298 | - if($element->nodeType === $nodeType){ |
|
| 298 | + if ($element->nodeType === $nodeType) { |
|
| 299 | 299 | $nodes[] = $element; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if(count($nodes) === $maxLength){ |
|
| 302 | + if (count($nodes) === $maxLength) { |
|
| 303 | 303 | break; |
| 304 | 304 | } |
| 305 | 305 | |
@@ -313,15 +313,15 @@ discard block |
||
| 313 | 313 | /** |
| 314 | 314 | * @see https://secure.php.net/manual/dom.constants.php |
| 315 | 315 | */ |
| 316 | - public function recursivelyFind(PrototypeNode $element, string $property = null, string $selector = null, int $index = null, int $nodeType = null):?DOMNode{ |
|
| 316 | + public function recursivelyFind(PrototypeNode $element, string $property = null, string $selector = null, int $index = null, int $nodeType = null): ?DOMNode{ |
|
| 317 | 317 | $nodeType = $nodeType ?? XML_ELEMENT_NODE; |
| 318 | 318 | $index = $index ?? 0; |
| 319 | 319 | |
| 320 | - if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){ |
|
| 320 | + if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) { |
|
| 321 | 321 | |
| 322 | - while($element = $element->{$property}){ |
|
| 322 | + while ($element = $element->{$property}) { |
|
| 323 | 323 | |
| 324 | - if($element->nodeType !== $nodeType || $selector !== null && !$element->match($selector) || --$index >= 0){ |
|
| 324 | + if ($element->nodeType !== $nodeType || $selector !== null && !$element->match($selector) || --$index >= 0) { |
|
| 325 | 325 | continue; |
| 326 | 326 | } |
| 327 | 327 | |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | */ |
| 339 | 339 | public function match(DOMNode $element, string $selector):bool{ |
| 340 | 340 | |
| 341 | - foreach($this->select([$selector]) as $match){ |
|
| 341 | + foreach ($this->select([$selector]) as $match) { |
|
| 342 | 342 | |
| 343 | - if($element->isSameNode($match)){ |
|
| 343 | + if ($element->isSameNode($match)) { |
|
| 344 | 344 | return true; |
| 345 | 345 | } |
| 346 | 346 | |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | /** @var \chillerlan\PrototypeDOM\Node\PrototypeHTMLElement $element */ |
| 357 | 357 | $element = $this->createElement($tag); |
| 358 | 358 | |
| 359 | - if($attributes !== null){ |
|
| 359 | + if ($attributes !== null) { |
|
| 360 | 360 | $element->setAttributes($attributes); |
| 361 | 361 | } |
| 362 | 362 | |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | /** |
| 29 | 29 | * NodeList constructor. |
| 30 | 30 | */ |
| 31 | - public function __construct(iterable $nodes = null){ |
|
| 31 | + public function __construct(iterable $nodes = null) { |
|
| 32 | 32 | |
| 33 | - if($nodes !== null){ |
|
| 33 | + if ($nodes !== null) { |
|
| 34 | 34 | $this->fromIterable($nodes); |
| 35 | 35 | } |
| 36 | 36 | |
@@ -43,15 +43,15 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | public function fromIterable(iterable $nodes):NodeList{ |
| 45 | 45 | |
| 46 | - if($nodes instanceof DOMNodeList){ |
|
| 46 | + if ($nodes instanceof DOMNodeList) { |
|
| 47 | 47 | $this->array = iterator_to_array($nodes); |
| 48 | 48 | } |
| 49 | - elseif($nodes instanceof NodeList){ |
|
| 49 | + elseif ($nodes instanceof NodeList) { |
|
| 50 | 50 | $this->array = $nodes->toArray(); |
| 51 | 51 | } |
| 52 | - elseif(is_iterable($nodes)){ |
|
| 53 | - foreach($nodes as $node){ |
|
| 54 | - if($node instanceof DOMNode || $node instanceof PrototypeNode){ |
|
| 52 | + elseif (is_iterable($nodes)) { |
|
| 53 | + foreach ($nodes as $node) { |
|
| 54 | + if ($node instanceof DOMNode || $node instanceof PrototypeNode) { |
|
| 55 | 55 | $this->array[] = $node; |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function match(DOMNode $node):bool{ |
| 69 | 69 | |
| 70 | - foreach($this->array as $element){ |
|
| 70 | + foreach ($this->array as $element) { |
|
| 71 | 71 | |
| 72 | - if($element->isSameNode($node)){ |
|
| 72 | + if ($element->isSameNode($node)) { |
|
| 73 | 73 | return true; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return \DOMNode|\chillerlan\PrototypeDOM\Node\PrototypeHTMLElement|null |
| 94 | 94 | */ |
| 95 | - public function item(int $offset):?DOMNode{ |
|
| 95 | + public function item(int $offset): ?DOMNode{ |
|
| 96 | 96 | return $this->offsetGet($offset); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @return \DOMNode|\chillerlan\PrototypeDOM\Node\PrototypeHTMLElement|null |
| 118 | 118 | */ |
| 119 | - public function current():?DOMNode{ |
|
| 119 | + public function current(): ?DOMNode{ |
|
| 120 | 120 | return $this->array[$this->offset] ?? null; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | public function seek($offset):void{ |
| 159 | 159 | $this->rewind(); |
| 160 | 160 | |
| 161 | - for( ; $this->offset < $offset; ){ |
|
| 161 | + for (; $this->offset < $offset;) { |
|
| 162 | 162 | |
| 163 | - if(!\next($this->array)) { |
|
| 163 | + if (!\next($this->array)) { |
|
| 164 | 164 | throw new OutOfBoundsException('invalid seek position: '.$offset); |
| 165 | 165 | } |
| 166 | 166 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * @return \DOMNode|\chillerlan\PrototypeDOM\Node\PrototypeHTMLElement|null |
| 187 | 187 | */ |
| 188 | - public function offsetGet($offset):?DOMNode{ |
|
| 188 | + public function offsetGet($offset): ?DOMNode{ |
|
| 189 | 189 | return $this->array[$offset] ?? null; |
| 190 | 190 | } |
| 191 | 191 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function offsetSet($offset, $value):void{ |
| 198 | 198 | |
| 199 | - if($value instanceof DOMNode){ |
|
| 199 | + if ($value instanceof DOMNode) { |
|
| 200 | 200 | |
| 201 | 201 | is_int($offset) |
| 202 | 202 | ? $this->array[$offset] = $value |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * |
| 234 | 234 | * @return \DOMNode|\chillerlan\PrototypeDOM\Node\PrototypeHTMLElement|null |
| 235 | 235 | */ |
| 236 | - public function first():?DOMNode{ |
|
| 236 | + public function first(): ?DOMNode{ |
|
| 237 | 237 | return $this->array[0] ?? null; |
| 238 | 238 | } |
| 239 | 239 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @return \DOMNode|\chillerlan\PrototypeDOM\Node\PrototypeHTMLElement|null |
| 246 | 246 | */ |
| 247 | - public function last():?DOMNode{ |
|
| 247 | + public function last(): ?DOMNode{ |
|
| 248 | 248 | return $this->array[count($this->array) - 1] ?? null; |
| 249 | 249 | } |
| 250 | 250 | |
@@ -303,13 +303,13 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function map($iterator):array{ |
| 305 | 305 | |
| 306 | - if(!is_callable($iterator)){ |
|
| 306 | + if (!is_callable($iterator)) { |
|
| 307 | 307 | throw new InvalidArgumentException('invalid callback'); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | $return = []; |
| 311 | 311 | |
| 312 | - foreach($this->array as $index => $element){ |
|
| 312 | + foreach ($this->array as $index => $element) { |
|
| 313 | 313 | $return[$index] = call_user_func_array($iterator, [$element, $index]); |
| 314 | 314 | } |
| 315 | 315 | |
@@ -341,15 +341,15 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | public function findAll($iterator):array{ |
| 343 | 343 | |
| 344 | - if(!is_callable($iterator)){ |
|
| 344 | + if (!is_callable($iterator)) { |
|
| 345 | 345 | throw new InvalidArgumentException('invalid callback'); |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | $return = []; |
| 349 | 349 | |
| 350 | - foreach($this->array as $index => $element){ |
|
| 350 | + foreach ($this->array as $index => $element) { |
|
| 351 | 351 | |
| 352 | - if(call_user_func_array($iterator, [$element, $index]) === true){ |
|
| 352 | + if (call_user_func_array($iterator, [$element, $index]) === true) { |
|
| 353 | 353 | $return[] = $element; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -371,15 +371,15 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | public function reject($iterator):array{ |
| 373 | 373 | |
| 374 | - if(!is_callable($iterator)){ |
|
| 374 | + if (!is_callable($iterator)) { |
|
| 375 | 375 | throw new InvalidArgumentException('invalid callback'); |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | $return = []; |
| 379 | 379 | |
| 380 | - foreach($this->array as $index => $element){ |
|
| 380 | + foreach ($this->array as $index => $element) { |
|
| 381 | 381 | |
| 382 | - if(call_user_func_array($iterator, [$element, $index]) !== true){ |
|
| 382 | + if (call_user_func_array($iterator, [$element, $index]) !== true) { |
|
| 383 | 383 | $return[] = $element; |
| 384 | 384 | } |
| 385 | 385 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * @implements \chillerlan\PrototypeDOM\Node\PrototypeElement |
| 22 | 22 | */ |
| 23 | -trait PrototypeElementTrait{ |
|
| 23 | +trait PrototypeElementTrait { |
|
| 24 | 24 | use PrototypeTraversalTrait; |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -42,28 +42,28 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function insert($content):PrototypeElement{ |
| 44 | 44 | |
| 45 | - if(!is_array($content)){ |
|
| 45 | + if (!is_array($content)) { |
|
| 46 | 46 | |
| 47 | - foreach($this->ownerDocument->toNodeList($content) as $node){ |
|
| 47 | + foreach ($this->ownerDocument->toNodeList($content) as $node) { |
|
| 48 | 48 | $this->insert_bottom($node); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | return $this; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - foreach(['before', 'after', 'top', 'bottom'] as $pos){ |
|
| 54 | + foreach (['before', 'after', 'top', 'bottom'] as $pos) { |
|
| 55 | 55 | |
| 56 | - if(!array_key_exists($pos, $content)){ |
|
| 56 | + if (!array_key_exists($pos, $content)) { |
|
| 57 | 57 | continue; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $nodes = $this->ownerDocument->toNodeList($content[$pos]); |
| 61 | 61 | |
| 62 | - if($pos === 'top' && $this->hasChildNodes() || $pos === 'after' && $this->nextSibling){ |
|
| 62 | + if ($pos === 'top' && $this->hasChildNodes() || $pos === 'after' && $this->nextSibling) { |
|
| 63 | 63 | $nodes->reverse(); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - foreach($nodes as $node){ |
|
| 66 | + foreach ($nodes as $node) { |
|
| 67 | 67 | call_user_func_array([$this, 'insert_'.$pos], [$node]); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public function insert_before(PrototypeElement $node, PrototypeElement $refNode = null):PrototypeElement{ |
| 79 | 79 | |
| 80 | - if($this->parentNode){ |
|
| 80 | + if ($this->parentNode) { |
|
| 81 | 81 | $this->parentNode->insertBefore($this->importNode($node), $refNode ?? $this); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function insert_after(PrototypeElement $node):PrototypeElement{ |
| 91 | 91 | |
| 92 | - if(!$this->nextSibling && $this->parentNode){ |
|
| 92 | + if (!$this->nextSibling && $this->parentNode) { |
|
| 93 | 93 | return $this->parentNode->insert_bottom($node); // @codeCoverageIgnore |
| 94 | 94 | } |
| 95 | 95 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | public function insert_top(PrototypeElement $node):PrototypeElement{ |
| 103 | 103 | |
| 104 | - if($this->hasChildNodes()){ |
|
| 104 | + if ($this->hasChildNodes()) { |
|
| 105 | 105 | return $this->firstChild->insert_before($node, $this->firstChild); |
| 106 | 106 | } |
| 107 | 107 | |
@@ -14,6 +14,6 @@ |
||
| 14 | 14 | |
| 15 | 15 | use DOMEntityReference; |
| 16 | 16 | |
| 17 | -class EntityReference extends DOMEntityReference implements PrototypeNode{ |
|
| 17 | +class EntityReference extends DOMEntityReference implements PrototypeNode { |
|
| 18 | 18 | use PrototypeNodeTrait; |
| 19 | 19 | } |
@@ -14,6 +14,6 @@ |
||
| 14 | 14 | |
| 15 | 15 | use DOMCdataSection; |
| 16 | 16 | |
| 17 | -class CdataSection extends DOMCdataSection implements PrototypeNode{ |
|
| 17 | +class CdataSection extends DOMCdataSection implements PrototypeNode { |
|
| 18 | 18 | use PrototypeNodeTrait; |
| 19 | 19 | } |
@@ -14,6 +14,6 @@ |
||
| 14 | 14 | |
| 15 | 15 | use DOMComment; |
| 16 | 16 | |
| 17 | -class Comment extends DOMComment implements PrototypeNode{ |
|
| 17 | +class Comment extends DOMComment implements PrototypeNode { |
|
| 18 | 18 | use PrototypeNodeTrait; |
| 19 | 19 | } |
@@ -14,6 +14,6 @@ |
||
| 14 | 14 | |
| 15 | 15 | use DOMDocumentType; |
| 16 | 16 | |
| 17 | -class DocumentType extends DOMDocumentType implements PrototypeNode{ |
|
| 17 | +class DocumentType extends DOMDocumentType implements PrototypeNode { |
|
| 18 | 18 | use PrototypeNodeTrait; |
| 19 | 19 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | use DOMNode; |
| 17 | 17 | use const XML_ELEMENT_NODE; |
| 18 | 18 | |
| 19 | -interface PrototypeTraversal extends PrototypeNode{ |
|
| 19 | +interface PrototypeTraversal extends PrototypeNode { |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * This method is very similar to $$ but can be used within the context of one element, rather than the whole document. |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return \chillerlan\PrototypeDOM\Node\PrototypeTraversal|null |
| 40 | 40 | */ |
| 41 | - public function down($expression = null, int $index = null):?PrototypeTraversal; |
|
| 41 | + public function down($expression = null, int $index = null): ?PrototypeTraversal; |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Returns element's first ancestor (or the Nth ancestor, if index is specified) that matches expression. |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return \chillerlan\PrototypeDOM\Node\PrototypeTraversal|null |
| 54 | 54 | */ |
| 55 | - public function up($expression = null, int $index = null):?PrototypeTraversal; |
|
| 55 | + public function up($expression = null, int $index = null): ?PrototypeTraversal; |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Returns element's first previous sibling (or the Nth, if index is specified) that matches expression. |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return \chillerlan\PrototypeDOM\Node\PrototypeTraversal|null |
| 68 | 68 | */ |
| 69 | - public function previous($expression = null, int $index = null):?PrototypeTraversal; |
|
| 69 | + public function previous($expression = null, int $index = null): ?PrototypeTraversal; |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * Returns element's first following sibling (or the Nth, if index is specified) that matches expression. |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return \chillerlan\PrototypeDOM\Node\PrototypeTraversal|null |
| 82 | 82 | */ |
| 83 | - public function next($expression = null, int $index = null):?PrototypeTraversal; |
|
| 83 | + public function next($expression = null, int $index = null): ?PrototypeTraversal; |
|
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * Collects all of the element's children and returns them as an array of Element.extended elements, in document order. |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @link http://api.prototypejs.org/dom/Element/firstDescendant/ |
| 127 | 127 | */ |
| 128 | - public function firstDescendant():?PrototypeTraversal; |
|
| 128 | + public function firstDescendant(): ?PrototypeTraversal; |
|
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * Collects all of element's previous siblings and returns them as an Array of elements. |
@@ -151,5 +151,5 @@ discard block |
||
| 151 | 151 | int $index = null, |
| 152 | 152 | string $property = null, |
| 153 | 153 | int $nodeType = XML_ELEMENT_NODE |
| 154 | - ):?PrototypeTraversal; |
|
| 154 | + ): ?PrototypeTraversal; |
|
| 155 | 155 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * @implements \chillerlan\PrototypeDOM\Node\PrototypeElement |
| 21 | 21 | */ |
| 22 | -trait PrototypeHTMLElementTrait{ |
|
| 22 | +trait PrototypeHTMLElementTrait { |
|
| 23 | 23 | use PrototypeElementTrait; |
| 24 | 24 | |
| 25 | 25 | public function getClassName():string{ |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | public function identify(string $newID = null):string{ |
| 63 | 63 | $oldID = trim($this->getAttribute('id')); |
| 64 | 64 | |
| 65 | - if($newID !== null){ |
|
| 65 | + if ($newID !== null) { |
|
| 66 | 66 | $this->setAttribute('id', trim($newID)); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -74,17 +74,17 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function classNames():array{ |
| 76 | 76 | |
| 77 | - if(!$this->hasAttributes()){ |
|
| 77 | + if (!$this->hasAttributes()) { |
|
| 78 | 78 | return []; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $classnames = explode(' ', $this->getClassName()); |
| 82 | 82 | $currentClassnames = []; |
| 83 | 83 | |
| 84 | - foreach($classnames as $classname){ |
|
| 84 | + foreach ($classnames as $classname) { |
|
| 85 | 85 | $classname = trim($classname); |
| 86 | 86 | |
| 87 | - if(!empty($classname)){ |
|
| 87 | + if (!empty($classname)) { |
|
| 88 | 88 | $currentClassnames[] = $classname; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public function toggleClassName(string $classname):PrototypeHTMLElement{ |
| 121 | 121 | |
| 122 | - if($this->hasClassName($classname)){ |
|
| 122 | + if ($this->hasClassName($classname)) { |
|
| 123 | 123 | return $this->removeClassName($classname); |
| 124 | 124 | } |
| 125 | 125 | |
@@ -129,10 +129,10 @@ discard block |
||
| 129 | 129 | /** |
| 130 | 130 | * @inheritDoc |
| 131 | 131 | */ |
| 132 | - public function getStyle(string $property):?string{ |
|
| 132 | + public function getStyle(string $property): ?string{ |
|
| 133 | 133 | $currentStyle = $this->getStyles(); |
| 134 | 134 | |
| 135 | - if(array_key_exists(strtolower($property), $currentStyle)){ |
|
| 135 | + if (array_key_exists(strtolower($property), $currentStyle)) { |
|
| 136 | 136 | return $currentStyle[$property]; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -145,11 +145,11 @@ discard block |
||
| 145 | 145 | public function setStyle(array $style, bool $replace = null):PrototypeHTMLElement{ |
| 146 | 146 | $currentStyle = $this->getStyles(); |
| 147 | 147 | |
| 148 | - if($replace !== true){ |
|
| 148 | + if ($replace !== true) { |
|
| 149 | 149 | $style = array_merge($currentStyle, $style); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - foreach($style as $property => $value){ |
|
| 152 | + foreach ($style as $property => $value) { |
|
| 153 | 153 | $style[$property] = $property.': '.$value.';'; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | public function getAttributes():array{ |
| 169 | 169 | $attributes = []; |
| 170 | 170 | |
| 171 | - foreach($this->attributes as $attribute){ |
|
| 171 | + foreach ($this->attributes as $attribute) { |
|
| 172 | 172 | $attributes[$attribute->nodeName] = $attribute->nodeValue; |
| 173 | 173 | } |
| 174 | 174 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public function setAttributes(array $attributes):PrototypeHTMLElement{ |
| 182 | 182 | |
| 183 | - foreach($attributes as $name => $value){ |
|
| 183 | + foreach ($attributes as $name => $value) { |
|
| 184 | 184 | $this->setAttribute($name, $value); |
| 185 | 185 | } |
| 186 | 186 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function removeAttributes(array $attributes):PrototypeHTMLElement{ |
| 194 | 194 | |
| 195 | - foreach($attributes as $name){ |
|
| 195 | + foreach ($attributes as $name) { |
|
| 196 | 196 | $this->removeAttribute($name); |
| 197 | 197 | } |
| 198 | 198 | |
@@ -205,9 +205,9 @@ discard block |
||
| 205 | 205 | public function addClassNames(array $classnames):PrototypeHTMLElement{ |
| 206 | 206 | $currentClassnames = $this->classNames(); |
| 207 | 207 | |
| 208 | - foreach($classnames as $classname){ |
|
| 208 | + foreach ($classnames as $classname) { |
|
| 209 | 209 | |
| 210 | - if(!in_array($classname, $currentClassnames, true)){ |
|
| 210 | + if (!in_array($classname, $currentClassnames, true)) { |
|
| 211 | 211 | $currentClassnames[] = $classname; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | public function removeClassNames(array $classnames):PrototypeHTMLElement{ |
| 223 | 223 | $currentClassnames = $this->classNames(); |
| 224 | 224 | |
| 225 | - foreach($classnames as $classname){ |
|
| 225 | + foreach ($classnames as $classname) { |
|
| 226 | 226 | $keys = array_keys($currentClassnames, $classname); |
| 227 | 227 | |
| 228 | - foreach($keys as $key){ |
|
| 228 | + foreach ($keys as $key) { |
|
| 229 | 229 | unset($currentClassnames[$key]); |
| 230 | 230 | } |
| 231 | 231 | |
@@ -239,17 +239,17 @@ discard block |
||
| 239 | 239 | */ |
| 240 | 240 | public function getStyles():array{ |
| 241 | 241 | |
| 242 | - if(!$this->hasAttributes()){ |
|
| 242 | + if (!$this->hasAttributes()) { |
|
| 243 | 243 | return []; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | $styles = explode(';', trim($this->getAttribute('style'))); |
| 247 | 247 | $currentStyle = []; |
| 248 | 248 | |
| 249 | - foreach($styles as $style){ |
|
| 249 | + foreach ($styles as $style) { |
|
| 250 | 250 | $s = explode(':', $style); |
| 251 | 251 | |
| 252 | - if(count($s) === 2){ |
|
| 252 | + if (count($s) === 2) { |
|
| 253 | 253 | $currentStyle[strtolower(trim($s[0]))] = trim($s[1]); |
| 254 | 254 | } |
| 255 | 255 | |