Completed
Push — master ( fb0caf...aaabee )
by Lars
02:40
created
src/voku/helper/HtmlMin.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -482,8 +482,8 @@
 block discarded – undo
482 482
   }
483 483
 
484 484
   /**
485
-   * @param $html
486
-   * @param $decodeUtf8Specials
485
+   * @param string $html
486
+   * @param boolean $decodeUtf8Specials
487 487
    *
488 488
    * @return string
489 489
    */
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -497,72 +497,72 @@
 block discarded – undo
497 497
     return \in_array($tag_name, self::$optional_end_tags, true)
498 498
            ||
499 499
            (
500
-               $tag_name == 'li'
500
+                $tag_name == 'li'
501 501
                &&
502 502
                (
503
-                   $nextSibling === null
503
+                    $nextSibling === null
504 504
                    ||
505 505
                    (
506
-                       $nextSibling instanceof \DOMElement
506
+                        $nextSibling instanceof \DOMElement
507 507
                        &&
508 508
                        $nextSibling->tagName == $tag_name
509
-                   )
510
-               )
511
-           )
509
+                    )
510
+                )
511
+            )
512 512
            ||
513 513
            (
514
-               $tag_name == 'p'
514
+                $tag_name == 'p'
515 515
                &&
516 516
                (
517
-                   (
518
-                       $nextSibling === null
517
+                    (
518
+                        $nextSibling === null
519 519
                        &&
520 520
                        (
521
-                           $node->parentNode !== null
521
+                            $node->parentNode !== null
522 522
                            &&
523 523
                            $node->parentNode->tagName != 'a'
524
-                       )
525
-                   )
524
+                        )
525
+                    )
526 526
                    ||
527 527
                    (
528
-                       $nextSibling instanceof \DOMElement
528
+                        $nextSibling instanceof \DOMElement
529 529
                        &&
530 530
                        \in_array(
531
-                           $nextSibling->tagName,
532
-                           [
533
-                               'address',
534
-                               'article',
535
-                               'aside',
536
-                               'blockquote',
537
-                               'dir',
538
-                               'div',
539
-                               'dl',
540
-                               'fieldset',
541
-                               'footer',
542
-                               'form',
543
-                               'h1',
544
-                               'h2',
545
-                               'h3',
546
-                               'h4',
547
-                               'h5',
548
-                               'h6',
549
-                               'header',
550
-                               'hgroup',
551
-                               'hr',
552
-                               'menu',
553
-                               'nav',
554
-                               'ol',
555
-                               'p',
556
-                               'pre',
557
-                               'section',
558
-                               'table',
559
-                               'ul',
560
-                           ],
561
-                           true
562
-                       )
563
-                   )
564
-               )
565
-           );
531
+                            $nextSibling->tagName,
532
+                            [
533
+                                'address',
534
+                                'article',
535
+                                'aside',
536
+                                'blockquote',
537
+                                'dir',
538
+                                'div',
539
+                                'dl',
540
+                                'fieldset',
541
+                                'footer',
542
+                                'form',
543
+                                'h1',
544
+                                'h2',
545
+                                'h3',
546
+                                'h4',
547
+                                'h5',
548
+                                'h6',
549
+                                'header',
550
+                                'hgroup',
551
+                                'hr',
552
+                                'menu',
553
+                                'nav',
554
+                                'ol',
555
+                                'p',
556
+                                'pre',
557
+                                'section',
558
+                                'table',
559
+                                'ul',
560
+                            ],
561
+                            true
562
+                        )
563
+                    )
564
+                )
565
+            );
566 566
   }
567 567
 
568 568
   protected function domNodeToString(\DOMNode $node): string
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace voku\helper;
6 6
 
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         # http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#attributes-0
453 453
         $omitquotes = $attribute->value != '' && 0 == \preg_match('/["\'=<>` \t\r\n\f]+/', $attribute->value);
454 454
         $attr_val = $attribute->value;
455
-        $attrstr .= ($omitquotes ? '' : '"') . $attr_val . ($omitquotes ? '' : '"');
455
+        $attrstr .= ($omitquotes ? '' : '"').$attr_val.($omitquotes ? '' : '"');
456 456
         $attrstr .= ' ';
457 457
       }
458 458
     }
@@ -578,11 +578,11 @@  discard block
 block discarded – undo
578 578
 
579 579
       } else if ($child instanceof \DOMElement) {
580 580
 
581
-        $htmlstr .= trim('<' . $child->tagName . ' ' . $this->domNodeAttributesToString($child));
582
-        $htmlstr .= '>' . $this->domNodeToString($child);
581
+        $htmlstr .= trim('<'.$child->tagName.' '.$this->domNodeAttributesToString($child));
582
+        $htmlstr .= '>'.$this->domNodeToString($child);
583 583
 
584 584
         if (!$this->domNodeClosingTagOptional($child)) {
585
-          $htmlstr .= '</' . $child->tagName . '>';
585
+          $htmlstr .= '</'.$child->tagName.'>';
586 586
         }
587 587
 
588 588
       } else if ($child instanceof \DOMText) {
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 
606 606
       } else {
607 607
 
608
-        throw new \Exception('Error by: ' . print_r($child, true));
608
+        throw new \Exception('Error by: '.print_r($child, true));
609 609
 
610 610
       }
611 611
     }
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
    */
656 656
   public function minify($html, $decodeUtf8Specials = false): string
657 657
   {
658
-    $html = (string)$html;
658
+    $html = (string) $html;
659 659
     if (!isset($html[0])) {
660 660
       return '';
661 661
     }
@@ -691,10 +691,10 @@  discard block
 block discarded – undo
691 691
     // -------------------------------------------------------------------------
692 692
 
693 693
     // Remove extra white-space(s) between HTML attribute(s)
694
-    $html = (string)\preg_replace_callback(
694
+    $html = (string) \preg_replace_callback(
695 695
         '#<([^\/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#',
696
-        function ($matches) {
697
-          return '<' . $matches[1] . (string)\preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]) . $matches[3] . '>';
696
+        function($matches) {
697
+          return '<'.$matches[1].(string) \preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]).$matches[3].'>';
698 698
         },
699 699
         $html
700 700
     );
@@ -702,15 +702,15 @@  discard block
 block discarded – undo
702 702
 
703 703
     if ($this->doRemoveSpacesBetweenTags === true) {
704 704
       // Remove spaces that are between > and <
705
-      $html = (string)\preg_replace('/(>) (<)/', '>$2', $html);
705
+      $html = (string) \preg_replace('/(>) (<)/', '>$2', $html);
706 706
     }
707 707
 
708 708
     // -------------------------------------------------------------------------
709 709
     // Restore protected HTML-code.
710 710
     // -------------------------------------------------------------------------
711 711
 
712
-    $html = (string)\preg_replace_callback(
713
-        '/<(?<element>' . $this->protectedChildNodesHelper . ')(?<attributes> [^>]*)?>(?<value>.*?)<\/' . $this->protectedChildNodesHelper . '>/',
712
+    $html = (string) \preg_replace_callback(
713
+        '/<(?<element>'.$this->protectedChildNodesHelper.')(?<attributes> [^>]*)?>(?<value>.*?)<\/'.$this->protectedChildNodesHelper.'>/',
714 714
         [$this, 'restoreProtectedHtml'],
715 715
         $html
716 716
     );
@@ -731,14 +731,14 @@  discard block
 block discarded – undo
731 731
 
732 732
     $html = \str_replace(
733 733
         [
734
-            'html>' . "\n",
735
-            "\n" . '<html',
736
-            'html/>' . "\n",
737
-            "\n" . '</html',
738
-            'head>' . "\n",
739
-            "\n" . '<head',
740
-            'head/>' . "\n",
741
-            "\n" . '</head',
734
+            'html>'."\n",
735
+            "\n".'<html',
736
+            'html/>'."\n",
737
+            "\n".'</html',
738
+            'head>'."\n",
739
+            "\n".'<head',
740
+            'head/>'."\n",
741
+            "\n".'</head',
742 742
         ],
743 743
         [
744 744
             'html>',
@@ -757,10 +757,10 @@  discard block
 block discarded – undo
757 757
     $replace = [];
758 758
     $replacement = [];
759 759
     foreach (self::$selfClosingTags as $selfClosingTag) {
760
-      $replace[] = '<' . $selfClosingTag . '/>';
761
-      $replacement[] = '<' . $selfClosingTag . '>';
762
-      $replace[] = '<' . $selfClosingTag . ' />';
763
-      $replacement[] = '<' . $selfClosingTag . '>';
760
+      $replace[] = '<'.$selfClosingTag.'/>';
761
+      $replacement[] = '<'.$selfClosingTag.'>';
762
+      $replace[] = '<'.$selfClosingTag.' />';
763
+      $replacement[] = '<'.$selfClosingTag.'>';
764 764
     }
765 765
     $html = \str_replace(
766 766
         $replace,
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
     }
864 864
 
865 865
     $attrs = [];
866
-    foreach ((array)$attributes as $attrName => $attrValue) {
866
+    foreach ((array) $attributes as $attrName => $attrValue) {
867 867
 
868 868
       if (isset(self::$booleanAttributes[$attrName])) {
869 869
         continue;
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
       }
943 943
 
944 944
       $this->protectedChildNodes[$counter] = $element->text();
945
-      $element->getNode()->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>';
945
+      $element->getNode()->nodeValue = '<'.$this->protectedChildNodesHelper.' data-'.$this->protectedChildNodesHelper.'="'.$counter.'"></'.$this->protectedChildNodesHelper.'>';
946 946
 
947 947
       ++$counter;
948 948
     }
@@ -957,11 +957,11 @@  discard block
 block discarded – undo
957 957
         continue;
958 958
       }
959 959
 
960
-      $this->protectedChildNodes[$counter] = '<!--' . $text . '-->';
960
+      $this->protectedChildNodes[$counter] = '<!--'.$text.'-->';
961 961
 
962 962
       /* @var $node \DOMComment */
963 963
       $node = $element->getNode();
964
-      $child = new \DOMText('<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>');
964
+      $child = new \DOMText('<'.$this->protectedChildNodesHelper.' data-'.$this->protectedChildNodesHelper.'="'.$counter.'"></'.$this->protectedChildNodesHelper.'>');
965 965
       $element->getNode()->parentNode->replaceChild($child, $node);
966 966
 
967 967
       ++$counter;
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
         continue;
1159 1159
       }
1160 1160
 
1161
-      $attrValue .= \trim($class) . ' ';
1161
+      $attrValue .= \trim($class).' ';
1162 1162
     }
1163 1163
     $attrValue = \trim($attrValue);
1164 1164
 
Please login to merge, or discard this patch.