Completed
Pull Request — master (#107)
by Asmir
03:02
created
src/Html5/Elements.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -485,7 +485,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Html5/Parser/DOMTreeBuilder.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
         }
345 345
 
346 346
         if ($this->onlyInline && Elements::isA($lname, Elements::BLOCK_TAG)) {
347
-        	$this->autoclose($this->onlyInline);
348
-        	$this->onlyInline = null;
347
+            $this->autoclose($this->onlyInline);
348
+            $this->onlyInline = null;
349 349
         }
350 350
 
351 351
         try {
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
         }
376 376
 
377 377
         if (Elements::isA($lname, Elements::BLOCK_ONLY_INLINE)) {
378
-        	$this->onlyInline = $lname;
378
+            $this->onlyInline = $lname;
379 379
         }
380 380
 
381 381
         // When we add some namespacess, we have to track them. Later, when "endElement" is invoked, we have to remove them.
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         $this->quirks = $quirks;
250 250
 
251 251
         if ($this->insertMode > static::IM_INITIAL) {
252
-            $this->parseError("Illegal placement of DOCTYPE tag. Ignoring: " . $name);
252
+            $this->parseError("Illegal placement of DOCTYPE tag. Ignoring: ".$name);
253 253
 
254 254
             return;
255 255
         }
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
         $lname = $this->normalizeTagName($name);
271 271
 
272 272
         // Make sure we have an html element.
273
-        if (! $this->doc->documentElement && $name !== 'html' && ! $this->frag) {
273
+        if (!$this->doc->documentElement && $name !== 'html' && !$this->frag) {
274 274
             $this->startTag('html');
275 275
         }
276 276
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
             array_unshift($this->nsStack, array(
331 331
                 '' => $this->nsRoots[$lname]
332 332
             ) + $this->nsStack[0]);
333
-            $pushes ++;
333
+            $pushes++;
334 334
         }
335 335
         $needsWorkaround = false;
336 336
         if (isset($this->options["xmlNamespaces"]) && $this->options["xmlNamespaces"]) {
@@ -341,12 +341,12 @@  discard block
 block discarded – undo
341 341
                     array_unshift($this->nsStack, array(
342 342
                         '' => $aVal
343 343
                     ) + $this->nsStack[0]);
344
-                    $pushes ++;
344
+                    $pushes++;
345 345
                 } elseif ((($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : '') === 'xmlns') {
346 346
                     array_unshift($this->nsStack, array(
347 347
                         substr($aName, $pos + 1) => $aVal
348 348
                     ) + $this->nsStack[0]);
349
-                    $pushes ++;
349
+                    $pushes++;
350 350
                 }
351 351
             }
352 352
         }
@@ -360,9 +360,9 @@  discard block
 block discarded – undo
360 360
             $prefix = ($pos = strpos($lname, ':')) ? substr($lname, 0, $pos) : '';
361 361
 
362 362
 
363
-            if ($needsWorkaround!==false) {
363
+            if ($needsWorkaround !== false) {
364 364
 
365
-                $xml = "<$lname xmlns=\"$needsWorkaround\" ".(strlen($prefix) && isset($this->nsStack[0][$prefix])?("xmlns:$prefix=\"".$this->nsStack[0][$prefix]."\""):"")."/>";
365
+                $xml = "<$lname xmlns=\"$needsWorkaround\" ".(strlen($prefix) && isset($this->nsStack[0][$prefix]) ? ("xmlns:$prefix=\"".$this->nsStack[0][$prefix]."\"") : "")."/>";
366 366
 
367 367
                 $frag = new \DOMDocument('1.0', 'UTF-8');
368 368
                 $frag->loadXML($xml);
@@ -415,9 +415,9 @@  discard block
 block discarded – undo
415 415
             try {
416 416
                 $prefix = ($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : false;
417 417
 
418
-                if ($prefix==='xmlns') {
418
+                if ($prefix === 'xmlns') {
419 419
                     $ele->setAttributeNs(self::NAMESPACE_XMLNS, $aName, $aVal);
420
-                } elseif ($prefix!==false && isset($this->nsStack[0][$prefix])) {
420
+                } elseif ($prefix !== false && isset($this->nsStack[0][$prefix])) {
421 421
                     $ele->setAttributeNs($this->nsStack[0][$prefix], $aName, $aVal);
422 422
                 } else {
423 423
                     $ele->setAttribute($aName, $aVal);
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
             $this->current->appendChild($ele);
442 442
 
443 443
             // XXX: Need to handle self-closing tags and unary tags.
444
-            if (! Elements::isA($name, Elements::VOID_TAG)) {
444
+            if (!Elements::isA($name, Elements::VOID_TAG)) {
445 445
                 $this->current = $ele;
446 446
             }
447 447
         }
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
         // but we have to remove the namespaces pushed to $nsStack.
457 457
         if ($pushes > 0 && Elements::isA($name, Elements::VOID_TAG)) {
458 458
             // remove the namespaced definded by current node
459
-            for ($i = 0; $i < $pushes; $i ++) {
459
+            for ($i = 0; $i < $pushes; $i++) {
460 460
                 array_shift($this->nsStack);
461 461
             }
462 462
         }
@@ -520,14 +520,14 @@  discard block
 block discarded – undo
520 520
 
521 521
         // remove the namespaced definded by current node
522 522
         if (isset($this->pushes[$cid])) {
523
-            for ($i = 0; $i < $this->pushes[$cid][0]; $i ++) {
523
+            for ($i = 0; $i < $this->pushes[$cid][0]; $i++) {
524 524
                 array_shift($this->nsStack);
525 525
             }
526 526
             unset($this->pushes[$cid]);
527 527
         }
528 528
 
529
-        if (! $this->autoclose($lname)) {
530
-            $this->parseError('Could not find closing tag for ' . $lname);
529
+        if (!$this->autoclose($lname)) {
530
+            $this->parseError('Could not find closing tag for '.$lname);
531 531
         }
532 532
 
533 533
         // switch ($this->insertMode) {
@@ -561,9 +561,9 @@  discard block
 block discarded – undo
561 561
             // practical as most documents contain these characters. Other text is not
562 562
             // expected here so recording a parse error is necessary.
563 563
             $dataTmp = trim($data, " \t\n\r\f");
564
-            if (! empty($dataTmp)) {
564
+            if (!empty($dataTmp)) {
565 565
                 $this->logger->debug(sprintf("Unexpected insert mode: %d", $this->insertMode));
566
-                $this->parseError("Unexpected text. Ignoring: " . $dataTmp);
566
+                $this->parseError("Unexpected text. Ignoring: ".$dataTmp);
567 567
             }
568 568
 
569 569
             return;
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
         // it sees fit.
606 606
         if (isset($this->processor)) {
607 607
             $res = $this->processor->process($this->current, $name, $data);
608
-            if (! empty($res)) {
608
+            if (!empty($res)) {
609 609
                 $this->current = $res;
610 610
             }
611 611
 
Please login to merge, or discard this patch.
src/Html5/Parser/StringInputStream.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -188,7 +188,7 @@
 block discarded – undo
188 188
      */
189 189
     public function next()
190 190
     {
191
-        $this->char ++;
191
+        $this->char++;
192 192
     }
193 193
 
194 194
     /**
Please login to merge, or discard this patch.
src/Html5/Parser/Tokenizer.php 2 patches
Braces   +2 added lines, -6 removed lines patch added patch discarded remove patch
@@ -298,13 +298,9 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
         if (is_null($this->untilTag)) {
185 185
             return $this->text();
186 186
         }
187
-        $sequence = '</' . $this->untilTag . '>';
187
+        $sequence = '</'.$this->untilTag.'>';
188 188
         $txt = $this->readUntilSequence($sequence);
189 189
         $this->events->text($txt);
190 190
         $this->setTextMode(0);
@@ -199,12 +199,12 @@  discard block
 block discarded – undo
199 199
         if (is_null($this->untilTag)) {
200 200
             return $this->text();
201 201
         }
202
-        $sequence = '</' . $this->untilTag;
202
+        $sequence = '</'.$this->untilTag;
203 203
         $txt = '';
204 204
         $tok = $this->scanner->current();
205 205
 
206 206
         $caseSensitive = !Elements::isHtml5Element($this->untilTag);
207
-        while ($tok !== false && ! ($tok == '<' && ($this->sequenceMatches($sequence, $caseSensitive)))) {
207
+        while ($tok !== false && !($tok == '<' && ($this->sequenceMatches($sequence, $caseSensitive)))) {
208 208
             if ($tok == '&') {
209 209
                 $txt .= $this->decodeCharacterReference();
210 210
                 $tok = $this->scanner->current();
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
         // > -> parse error
329 329
         // EOF -> parse error
330 330
         // -> parse error
331
-        if (! ctype_alpha($tok)) {
331
+        if (!ctype_alpha($tok)) {
332 332
             $this->parseError("Expected tag name, got '%s'", $tok);
333 333
             if ($tok == "\0" || $tok === false) {
334 334
                 return false;
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
     protected function tagName()
359 359
     {
360 360
         $tok = $this->scanner->current();
361
-        if (! ctype_alpha($tok)) {
361
+        if (!ctype_alpha($tok)) {
362 362
             return false;
363 363
         }
364 364
 
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
             do {
374 374
                 $this->scanner->whitespace();
375 375
                 $this->attribute($attributes);
376
-            } while (! $this->isTagEnd($selfClose));
376
+            } while (!$this->isTagEnd($selfClose));
377 377
         } catch (ParseError $e) {
378 378
             $selfClose = false;
379 379
         }
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
      */
532 532
     protected function quotedAttributeValue($quote)
533 533
     {
534
-        $stoplist = "\f" . $quote;
534
+        $stoplist = "\f".$quote;
535 535
         $val = '';
536 536
         $tok = $this->scanner->current();
537 537
         while (strspn($tok, $stoplist) == 0 && $tok !== false) {
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
         } while ($tok !== false && $tok != '>');
598 598
 
599 599
         $this->flushBuffer();
600
-        $this->events->comment($comment . $tok);
600
+        $this->events->comment($comment.$tok);
601 601
         $this->scanner->next();
602 602
 
603 603
         return true;
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
         if ($tok == "\0") {
627 627
             $tok = UTF8Utils::FFFD;
628 628
         }
629
-        while (! $this->isCommentEnd()) {
629
+        while (!$this->isCommentEnd()) {
630 630
             $comment .= $tok;
631 631
             $this->scanner->next();
632 632
             $tok = $this->scanner->current();
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
         $chars = $this->scanner->charsWhile("DOCTYPEdoctype");
683 683
         if (strcasecmp($chars, 'DOCTYPE')) {
684 684
             $this->parseError('Expected DOCTYPE, got %s', $chars);
685
-            return $this->bogusComment('<!' . $chars);
685
+            return $this->bogusComment('<!'.$chars);
686 686
         }
687 687
 
688 688
         $this->scanner->whitespace();
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
         $tok = $this->scanner->current();
795 795
         if ($tok == '"' || $tok == "'") {
796 796
             $this->scanner->next();
797
-            $ret = $this->scanner->charsUntil($tok . $stopchars);
797
+            $ret = $this->scanner->charsUntil($tok.$stopchars);
798 798
             if ($this->scanner->current() == $tok) {
799 799
                 $this->scanner->next();
800 800
             } else {
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
         $chars = $this->scanner->charsWhile('CDAT');
821 821
         if ($chars != 'CDATA' || $this->scanner->current() != '[') {
822 822
             $this->parseError('Expected [CDATA[, got %s', $chars);
823
-            return $this->bogusComment('<![' . $chars);
823
+            return $this->bogusComment('<!['.$chars);
824 824
         }
825 825
 
826 826
         $this->scanner->next();
@@ -828,13 +828,13 @@  discard block
 block discarded – undo
828 828
         do {
829 829
             if ($tok === false) {
830 830
                 $this->parseError('Unexpected EOF inside CDATA.');
831
-                $this->bogusComment('<![CDATA[' . $cdata);
831
+                $this->bogusComment('<![CDATA['.$cdata);
832 832
                 return true;
833 833
             }
834 834
             $cdata .= $tok;
835 835
             $this->scanner->next();
836 836
             $tok = $this->scanner->current();
837
-        } while (! $this->sequenceMatches(']]>'));
837
+        } while (!$this->sequenceMatches(']]>'));
838 838
 
839 839
         // Consume ]]>
840 840
         $this->scanner->consume(3);
@@ -868,13 +868,13 @@  discard block
 block discarded – undo
868 868
         // If not a PI, send to bogusComment.
869 869
         if (strlen($procName) == 0 || $white == 0 || $this->scanner->current() == false) {
870 870
             $this->parseError("Expected processing instruction name, got $tok");
871
-            $this->bogusComment('<?' . $tok . $procName);
871
+            $this->bogusComment('<?'.$tok.$procName);
872 872
             return true;
873 873
         }
874 874
 
875 875
         $data = '';
876 876
         // As long as it's not the case that the next two chars are ? and >.
877
-        while (! ($this->scanner->current() == '?' && $this->scanner->peek() == '>')) {
877
+        while (!($this->scanner->current() == '?' && $this->scanner->peek() == '>')) {
878 878
             $data .= $this->scanner->current();
879 879
 
880 880
             $this->scanner->next();
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
 
1032 1032
         // These indicate not an entity. We return just
1033 1033
         // the &.
1034
-        if (strspn($tok, static::WHITE . "&<") == 1) {
1034
+        if (strspn($tok, static::WHITE."&<") == 1) {
1035 1035
             // $this->scanner->next();
1036 1036
             return '&';
1037 1037
         }
@@ -1106,6 +1106,6 @@  discard block
 block discarded – undo
1106 1106
         }
1107 1107
 
1108 1108
         $this->parseError("Expected &ENTITY;, got &ENTITY%s (no trailing ;) ", $tok);
1109
-        return '&' . $entity;
1109
+        return '&'.$entity;
1110 1110
     }
1111 1111
 }
Please login to merge, or discard this patch.
src/Html5/Parser/UTF8Utils.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Html5/Serializer/OutputRules.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Html5/Parser/CharacterReference.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
      */
48 48
     public static function lookupDecimal($int)
49 49
     {
50
-        $entity = '&#' . $int . ';';
50
+        $entity = '&#'.$int.';';
51 51
         // UNTESTED: This may fail on some planes. Couldn't find full documentation
52 52
         // on the value of the mask array.
53 53
         return mb_decode_numericentity($entity, static::$numeric_mask, 'utf-8');
Please login to merge, or discard this patch.