@@ -485,7 +485,7 @@ |
||
| 485 | 485 | */ |
| 486 | 486 | public static function isA($name, $mask) |
| 487 | 487 | { |
| 488 | - if (! static::isElement($name)) { |
|
| 488 | + if (!static::isElement($name)) { |
|
| 489 | 489 | return false; |
| 490 | 490 | } |
| 491 | 491 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | $lname = $this->normalizeTagName($name); |
| 263 | 263 | |
| 264 | 264 | // Make sure we have an html element. |
| 265 | - if (! $this->doc->documentElement && $name !== 'html' && ! $this->frag) { |
|
| 265 | + if (!$this->doc->documentElement && $name !== 'html' && !$this->frag) { |
|
| 266 | 266 | $this->startTag('html'); |
| 267 | 267 | } |
| 268 | 268 | |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | array_unshift($this->nsStack, array( |
| 323 | 323 | '' => $this->nsRoots[$lname] |
| 324 | 324 | ) + $this->nsStack[0]); |
| 325 | - $pushes ++; |
|
| 325 | + $pushes++; |
|
| 326 | 326 | } |
| 327 | 327 | $needsWorkaround = false; |
| 328 | 328 | if (isset($this->options["xmlNamespaces"]) && $this->options["xmlNamespaces"]) { |
@@ -333,12 +333,12 @@ discard block |
||
| 333 | 333 | array_unshift($this->nsStack, array( |
| 334 | 334 | '' => $aVal |
| 335 | 335 | ) + $this->nsStack[0]); |
| 336 | - $pushes ++; |
|
| 336 | + $pushes++; |
|
| 337 | 337 | } elseif ((($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : '') === 'xmlns') { |
| 338 | 338 | array_unshift($this->nsStack, array( |
| 339 | 339 | substr($aName, $pos + 1) => $aVal |
| 340 | 340 | ) + $this->nsStack[0]); |
| 341 | - $pushes ++; |
|
| 341 | + $pushes++; |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | } |
@@ -352,9 +352,9 @@ discard block |
||
| 352 | 352 | $prefix = ($pos = strpos($lname, ':')) ? substr($lname, 0, $pos) : ''; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - if ($needsWorkaround!==false) { |
|
| 355 | + if ($needsWorkaround !== false) { |
|
| 356 | 356 | |
| 357 | - $xml = "<$lname xmlns=\"$needsWorkaround\" ".(strlen($prefix) && isset($this->nsStack[0][$prefix])?("xmlns:$prefix=\"".$this->nsStack[0][$prefix]."\""):"")."/>"; |
|
| 357 | + $xml = "<$lname xmlns=\"$needsWorkaround\" " . (strlen($prefix) && isset($this->nsStack[0][$prefix]) ? ("xmlns:$prefix=\"" . $this->nsStack[0][$prefix] . "\"") : "") . "/>"; |
|
| 358 | 358 | |
| 359 | 359 | $frag = new \DOMDocument('1.0', 'UTF-8'); |
| 360 | 360 | $frag->loadXML($xml); |
@@ -407,9 +407,9 @@ discard block |
||
| 407 | 407 | try { |
| 408 | 408 | $prefix = ($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : false; |
| 409 | 409 | |
| 410 | - if ($prefix==='xmlns') { |
|
| 410 | + if ($prefix === 'xmlns') { |
|
| 411 | 411 | $ele->setAttributeNs(self::NAMESPACE_XMLNS, $aName, $aVal); |
| 412 | - } elseif ($prefix!==false && isset($this->nsStack[0][$prefix])) { |
|
| 412 | + } elseif ($prefix !== false && isset($this->nsStack[0][$prefix])) { |
|
| 413 | 413 | $ele->setAttributeNs($this->nsStack[0][$prefix], $aName, $aVal); |
| 414 | 414 | } else { |
| 415 | 415 | $ele->setAttribute($aName, $aVal); |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | $this->current->appendChild($ele); |
| 434 | 434 | |
| 435 | 435 | // XXX: Need to handle self-closing tags and unary tags. |
| 436 | - if (! Elements::isA($name, Elements::VOID_TAG)) { |
|
| 436 | + if (!Elements::isA($name, Elements::VOID_TAG)) { |
|
| 437 | 437 | $this->current = $ele; |
| 438 | 438 | } |
| 439 | 439 | } |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | // but we have to remove the namespaces pushed to $nsStack. |
| 449 | 449 | if ($pushes > 0 && Elements::isA($name, Elements::VOID_TAG)) { |
| 450 | 450 | // remove the namespaced definded by current node |
| 451 | - for ($i = 0; $i < $pushes; $i ++) { |
|
| 451 | + for ($i = 0; $i < $pushes; $i++) { |
|
| 452 | 452 | array_shift($this->nsStack); |
| 453 | 453 | } |
| 454 | 454 | } |
@@ -512,13 +512,13 @@ discard block |
||
| 512 | 512 | |
| 513 | 513 | // remove the namespaced definded by current node |
| 514 | 514 | if (isset($this->pushes[$cid])) { |
| 515 | - for ($i = 0; $i < $this->pushes[$cid][0]; $i ++) { |
|
| 515 | + for ($i = 0; $i < $this->pushes[$cid][0]; $i++) { |
|
| 516 | 516 | array_shift($this->nsStack); |
| 517 | 517 | } |
| 518 | 518 | unset($this->pushes[$cid]); |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - if (! $this->autoclose($lname)) { |
|
| 521 | + if (!$this->autoclose($lname)) { |
|
| 522 | 522 | $this->parseError('Could not find closing tag for ' . $lname); |
| 523 | 523 | } |
| 524 | 524 | |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | // practical as most documents contain these characters. Other text is not |
| 554 | 554 | // expected here so recording a parse error is necessary. |
| 555 | 555 | $dataTmp = trim($data, " \t\n\r\f"); |
| 556 | - if (! empty($dataTmp)) { |
|
| 556 | + if (!empty($dataTmp)) { |
|
| 557 | 557 | // fprintf(STDOUT, "Unexpected insert mode: %d", $this->insertMode); |
| 558 | 558 | $this->parseError("Unexpected text. Ignoring: " . $dataTmp); |
| 559 | 559 | } |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | // it sees fit. |
| 598 | 598 | if (isset($this->processor)) { |
| 599 | 599 | $res = $this->processor->process($this->current, $name, $data); |
| 600 | - if (! empty($res)) { |
|
| 600 | + if (!empty($res)) { |
|
| 601 | 601 | $this->current = $res; |
| 602 | 602 | } |
| 603 | 603 | |
@@ -188,7 +188,7 @@ |
||
| 188 | 188 | */ |
| 189 | 189 | public function next() |
| 190 | 190 | { |
| 191 | - $this->char ++; |
|
| 191 | + $this->char++; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -71,8 +71,9 @@ |
||
| 71 | 71 | public function __construct($data, $encoding = 'UTF-8', $debug = '') |
| 72 | 72 | { |
| 73 | 73 | $data = UTF8Utils::convertToUTF8($data, $encoding); |
| 74 | - if ($debug) |
|
| 75 | - fprintf(STDOUT, $debug, $data, strlen($data)); |
|
| 74 | + if ($debug) { |
|
| 75 | + fprintf(STDOUT, $debug, $data, strlen($data)); |
|
| 76 | + } |
|
| 76 | 77 | |
| 77 | 78 | // There is good reason to question whether it makes sense to |
| 78 | 79 | // do this here, since most of these checks are done during |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $tok = $this->scanner->current(); |
| 206 | 206 | |
| 207 | 207 | $caseSensitive = !Elements::isHtml5Element($this->untilTag); |
| 208 | - while ($tok !== false && ! ($tok == '<' && ($this->sequenceMatches($sequence, $caseSensitive)))) { |
|
| 208 | + while ($tok !== false && !($tok == '<' && ($this->sequenceMatches($sequence, $caseSensitive)))) { |
|
| 209 | 209 | if ($tok == '&') { |
| 210 | 210 | $txt .= $this->decodeCharacterReference(); |
| 211 | 211 | $tok = $this->scanner->current(); |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | // > -> parse error |
| 331 | 331 | // EOF -> parse error |
| 332 | 332 | // -> parse error |
| 333 | - if (! ctype_alpha($tok)) { |
|
| 333 | + if (!ctype_alpha($tok)) { |
|
| 334 | 334 | $this->parseError("Expected tag name, got '%s'", $tok); |
| 335 | 335 | if ($tok == "\0" || $tok === false) { |
| 336 | 336 | return false; |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | protected function tagName() |
| 361 | 361 | { |
| 362 | 362 | $tok = $this->scanner->current(); |
| 363 | - if (! ctype_alpha($tok)) { |
|
| 363 | + if (!ctype_alpha($tok)) { |
|
| 364 | 364 | return false; |
| 365 | 365 | } |
| 366 | 366 | |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | do { |
| 376 | 376 | $this->scanner->whitespace(); |
| 377 | 377 | $this->attribute($attributes); |
| 378 | - } while (! $this->isTagEnd($selfClose)); |
|
| 378 | + } while (!$this->isTagEnd($selfClose)); |
|
| 379 | 379 | } catch (ParseError $e) { |
| 380 | 380 | $selfClose = false; |
| 381 | 381 | } |
@@ -629,7 +629,7 @@ discard block |
||
| 629 | 629 | if ($tok == "\0") { |
| 630 | 630 | $tok = UTF8Utils::FFFD; |
| 631 | 631 | } |
| 632 | - while (! $this->isCommentEnd()) { |
|
| 632 | + while (!$this->isCommentEnd()) { |
|
| 633 | 633 | $comment .= $tok; |
| 634 | 634 | $this->scanner->next(); |
| 635 | 635 | $tok = $this->scanner->current(); |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | $cdata .= $tok; |
| 838 | 838 | $this->scanner->next(); |
| 839 | 839 | $tok = $this->scanner->current(); |
| 840 | - } while (! $this->sequenceMatches(']]>')); |
|
| 840 | + } while (!$this->sequenceMatches(']]>')); |
|
| 841 | 841 | |
| 842 | 842 | // Consume ]]> |
| 843 | 843 | $this->scanner->consume(3); |
@@ -877,7 +877,7 @@ discard block |
||
| 877 | 877 | |
| 878 | 878 | $data = ''; |
| 879 | 879 | // As long as it's not the case that the next two chars are ? and >. |
| 880 | - while (! ($this->scanner->current() == '?' && $this->scanner->peek() == '>')) { |
|
| 880 | + while (!($this->scanner->current() == '?' && $this->scanner->peek() == '>')) { |
|
| 881 | 881 | $data .= $this->scanner->current(); |
| 882 | 882 | |
| 883 | 883 | $this->scanner->next(); |
@@ -298,13 +298,9 @@ |
||
| 298 | 298 | $this->scanner->next(); // Consume the other '-' |
| 299 | 299 | $this->scanner->next(); // Next char. |
| 300 | 300 | return $this->comment(); |
| 301 | - } |
|
| 302 | - |
|
| 303 | - elseif ($tok == 'D' || $tok == 'd') { // Doctype |
|
| 301 | + } elseif ($tok == 'D' || $tok == 'd') { // Doctype |
|
| 304 | 302 | return $this->doctype(); |
| 305 | - } |
|
| 306 | - |
|
| 307 | - elseif ($tok == '[') { // CDATA section |
|
| 303 | + } elseif ($tok == '[') { // CDATA section |
|
| 308 | 304 | return $this->cdataSection(); |
| 309 | 305 | } |
| 310 | 306 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public static function checkForIllegalCodepoints($data) |
| 132 | 132 | { |
| 133 | - if (! function_exists('preg_match_all')) { |
|
| 133 | + if (!function_exists('preg_match_all')) { |
|
| 134 | 134 | throw\Exception('The PCRE library is not loaded or is not available.'); |
| 135 | 135 | } |
| 136 | 136 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | /* |
| 141 | 141 | * All U+0000 null characters in the input must be replaced by U+FFFD REPLACEMENT CHARACTERs. Any occurrences of such characters is a parse error. |
| 142 | 142 | */ |
| 143 | - for ($i = 0, $count = substr_count($data, "\0"); $i < $count; $i ++) { |
|
| 143 | + for ($i = 0, $count = substr_count($data, "\0"); $i < $count; $i++) { |
|
| 144 | 144 | $errors[] = 'null-character'; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | | |
| 163 | 163 | [\xF0-\xF4][\x8F-\xBF]\xBF[\xBE\xBF] # U+nFFFE and U+nFFFF (1 <= n <= 10_{16}) |
| 164 | 164 | )/x', $data, $matches); |
| 165 | - for ($i = 0; $i < $count; $i ++) { |
|
| 165 | + for ($i = 0; $i < $count; $i++) { |
|
| 166 | 166 | $errors[] = 'invalid-codepoint'; |
| 167 | 167 | } |
| 168 | 168 | |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // If not unary, add a closing tag. |
| 239 | - if (! Elements::isA($name, Elements::VOID_TAG)) { |
|
| 239 | + if (!Elements::isA($name, Elements::VOID_TAG)) { |
|
| 240 | 240 | $this->closeTag($ele); |
| 241 | 241 | } |
| 242 | 242 | } |
@@ -288,11 +288,11 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | protected function namespaceAttrs($ele) |
| 290 | 290 | { |
| 291 | - if (!$this->xpath || $this->xpath->document !== $ele->ownerDocument){ |
|
| 291 | + if (!$this->xpath || $this->xpath->document !== $ele->ownerDocument) { |
|
| 292 | 292 | $this->xpath = new \DOMXPath($ele->ownerDocument); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - foreach( $this->xpath->query('namespace::*[not(.=../../namespace::*)]', $ele ) as $nsNode ) { |
|
| 295 | + foreach ($this->xpath->query('namespace::*[not(.=../../namespace::*)]', $ele) as $nsNode) { |
|
| 296 | 296 | if (!in_array($nsNode->nodeValue, $this->implicitNamespaces)) { |
| 297 | 297 | $this->wr(' ')->wr($nsNode->nodeName)->wr('="')->wr($nsNode->nodeValue)->wr('"'); |
| 298 | 298 | } |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | protected function attrs($ele) |
| 334 | 334 | { |
| 335 | 335 | // FIXME: Needs support for xml, xmlns, xlink, and namespaced elements. |
| 336 | - if (! $ele->hasAttributes()) { |
|
| 336 | + if (!$ele->hasAttributes()) { |
|
| 337 | 337 | return $this; |
| 338 | 338 | } |
| 339 | 339 | |
@@ -371,35 +371,35 @@ discard block |
||
| 371 | 371 | protected function nonBooleanAttribute(\DOMAttr $attr) |
| 372 | 372 | { |
| 373 | 373 | $ele = $attr->ownerElement; |
| 374 | - foreach($this->nonBooleanAttributes as $rule){ |
|
| 374 | + foreach ($this->nonBooleanAttributes as $rule) { |
|
| 375 | 375 | |
| 376 | - if(isset($rule['nodeNamespace']) && $rule['nodeNamespace']!==$ele->namespaceURI){ |
|
| 376 | + if (isset($rule['nodeNamespace']) && $rule['nodeNamespace'] !== $ele->namespaceURI) { |
|
| 377 | 377 | continue; |
| 378 | 378 | } |
| 379 | - if(isset($rule['attNamespace']) && $rule['attNamespace']!==$attr->namespaceURI){ |
|
| 379 | + if (isset($rule['attNamespace']) && $rule['attNamespace'] !== $attr->namespaceURI) { |
|
| 380 | 380 | continue; |
| 381 | 381 | } |
| 382 | - if(isset($rule['nodeName']) && !is_array($rule['nodeName']) && $rule['nodeName']!==$ele->localName){ |
|
| 382 | + if (isset($rule['nodeName']) && !is_array($rule['nodeName']) && $rule['nodeName'] !== $ele->localName) { |
|
| 383 | 383 | continue; |
| 384 | 384 | } |
| 385 | - if(isset($rule['nodeName']) && is_array($rule['nodeName']) && !in_array($ele->localName, $rule['nodeName'], true)){ |
|
| 385 | + if (isset($rule['nodeName']) && is_array($rule['nodeName']) && !in_array($ele->localName, $rule['nodeName'], true)) { |
|
| 386 | 386 | continue; |
| 387 | 387 | } |
| 388 | - if(isset($rule['attrName']) && !is_array($rule['attrName']) && $rule['attrName']!==$attr->localName){ |
|
| 388 | + if (isset($rule['attrName']) && !is_array($rule['attrName']) && $rule['attrName'] !== $attr->localName) { |
|
| 389 | 389 | continue; |
| 390 | 390 | } |
| 391 | - if(isset($rule['attrName']) && is_array($rule['attrName']) && !in_array($attr->localName, $rule['attrName'], true)){ |
|
| 391 | + if (isset($rule['attrName']) && is_array($rule['attrName']) && !in_array($attr->localName, $rule['attrName'], true)) { |
|
| 392 | 392 | continue; |
| 393 | 393 | } |
| 394 | - if(isset($rule['xpath'])){ |
|
| 394 | + if (isset($rule['xpath'])) { |
|
| 395 | 395 | |
| 396 | 396 | $xp = $this->getXPath($attr); |
| 397 | - if(isset($rule['prefixes'])){ |
|
| 398 | - foreach($rule['prefixes'] as $nsPrefix => $ns){ |
|
| 397 | + if (isset($rule['prefixes'])) { |
|
| 398 | + foreach ($rule['prefixes'] as $nsPrefix => $ns) { |
|
| 399 | 399 | $xp->registerNamespace($nsPrefix, $ns); |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | - if(!$xp->evaluate($rule['xpath'], $attr)){ |
|
| 402 | + if (!$xp->evaluate($rule['xpath'], $attr)) { |
|
| 403 | 403 | continue; |
| 404 | 404 | } |
| 405 | 405 | } |
@@ -410,8 +410,8 @@ discard block |
||
| 410 | 410 | return false; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - private function getXPath(\DOMNode $node){ |
|
| 414 | - if(!$this->xpath){ |
|
| 413 | + private function getXPath(\DOMNode $node) { |
|
| 414 | + if (!$this->xpath) { |
|
| 415 | 415 | $this->xpath = new \DOMXPath($node->ownerDocument); |
| 416 | 416 | } |
| 417 | 417 | return $this->xpath; |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | { |
| 492 | 492 | |
| 493 | 493 | // Escape the text rather than convert to named character references. |
| 494 | - if (! $this->encode) { |
|
| 494 | + if (!$this->encode) { |
|
| 495 | 495 | return $this->escape($text, $attribute); |
| 496 | 496 | } |
| 497 | 497 | |