Completed
Pull Request — master (#97)
by Asmir
03:47
created
src/Html5/Elements.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Provide general element functions.
4
- */
3
+     * Provide general element functions.
4
+     */
5 5
 namespace Masterminds\Html5;
6 6
 
7 7
 /**
Please login to merge, or discard this 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   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Html5/Parser/StringInputStream.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Loads a string to be parsed.
4
- */
3
+     * Loads a string to be parsed.
4
+     */
5 5
 namespace Masterminds\Html5\Parser;
6 6
 
7 7
 /*
Please login to merge, or discard this 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.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -71,8 +71,9 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Html5/Parser/Tokenizer.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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();
Please login to merge, or discard this patch.
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.
src/Html5/Parser/UTF8Utils.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@
 block discarded – undo
27 27
 
28 28
 */
29 29
 /**
30
- * UTF-8 Utilities
31
- */
30
+     * UTF-8 Utilities
31
+     */
32 32
 class UTF8Utils
33 33
 {
34 34
 
Please login to merge, or discard this 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/Html5Entities.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @file
4
- * This contains HTML5 entities to use with serializing.
5
- *
6
- * The list here is mildly different from the list at \Masterminds\Html5\Entities because
7
- * that list was generated from the w3c. It contains some entities that are
8
- * not entirely proper such as &am; which maps to &. This list is meant to be
9
- * a fallback for PHP versions prior to PHP 5.4 when dealing with encoding.
10
- */
3
+     * @file
4
+     * This contains HTML5 entities to use with serializing.
5
+     *
6
+     * The list here is mildly different from the list at \Masterminds\Html5\Entities because
7
+     * that list was generated from the w3c. It contains some entities that are
8
+     * not entirely proper such as &am; which maps to &. This list is meant to be
9
+     * a fallback for PHP versions prior to PHP 5.4 when dealing with encoding.
10
+     */
11 11
 namespace Masterminds\Html5\Serializer;
12 12
 
13 13
 /**
Please login to merge, or discard this patch.
src/Html5/Serializer/OutputRules.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @file
4
- * The rules for generating output in the serializer.
5
- *
6
- * These output rules are likely to generate output similar to the document that
7
- * was parsed. It is not intended to output exactly the document that was parsed.
8
- */
3
+     * @file
4
+     * The rules for generating output in the serializer.
5
+     *
6
+     * These output rules are likely to generate output similar to the document that
7
+     * was parsed. It is not intended to output exactly the document that was parsed.
8
+     */
9 9
 namespace Masterminds\Html5\Serializer;
10 10
 
11 11
 use Masterminds\Html5\Elements;
Please login to merge, or discard this 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/Serializer/RulesInterface.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @file
4
- * The interface definition for Rules to generate output.
5
- */
3
+     * @file
4
+     * The interface definition for Rules to generate output.
5
+     */
6 6
 namespace Masterminds\Html5\Serializer;
7 7
 
8 8
 /**
Please login to merge, or discard this patch.