Completed
Pull Request — master (#21)
by
unknown
01:55
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   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -557,184 +557,184 @@  discard block
 block discarded – undo
557 557
     return \in_array($tag_name, self::$optional_end_tags, true)
558 558
            ||
559 559
            (
560
-               $tag_name == 'li'
560
+                $tag_name == 'li'
561 561
                &&
562 562
                (
563
-                   $nextSibling === null
563
+                    $nextSibling === null
564 564
                    ||
565 565
                    (
566
-                       $nextSibling instanceof \DOMElement
566
+                        $nextSibling instanceof \DOMElement
567 567
                        &&
568 568
                        $nextSibling->tagName == 'li'
569
-                   )
570
-               )
571
-           )
569
+                    )
570
+                )
571
+            )
572 572
            ||
573 573
            (
574
-               (
575
-                   $tag_name == 'rp'
576
-               )
574
+                (
575
+                    $tag_name == 'rp'
576
+                )
577 577
                &&
578 578
                (
579
-                   $nextSibling === null
579
+                    $nextSibling === null
580 580
                    ||
581 581
                    (
582
-                       $nextSibling instanceof \DOMElement
582
+                        $nextSibling instanceof \DOMElement
583 583
                        &&
584 584
                        (
585
-                           $nextSibling->tagName == 'rp'
585
+                            $nextSibling->tagName == 'rp'
586 586
                            ||
587 587
                            $nextSibling->tagName == 'rt'
588
-                       )
589
-                   )
590
-               )
591
-           )
588
+                        )
589
+                    )
590
+                )
591
+            )
592 592
            ||
593 593
            (
594
-               $tag_name == 'tr'
594
+                $tag_name == 'tr'
595 595
                &&
596 596
                (
597
-                   $nextSibling === null
597
+                    $nextSibling === null
598 598
                    ||
599 599
                    (
600
-                       $nextSibling instanceof \DOMElement
600
+                        $nextSibling instanceof \DOMElement
601 601
                        &&
602 602
                        $nextSibling->tagName == 'tr'
603
-                   )
604
-               )
605
-           )
603
+                    )
604
+                )
605
+            )
606 606
            ||
607 607
            (
608
-               (
609
-                   $tag_name == 'td'
608
+                (
609
+                    $tag_name == 'td'
610 610
                    ||
611 611
                    $tag_name == 'th'
612
-               )
612
+                )
613 613
                &&
614 614
                (
615
-                   $nextSibling === null
615
+                    $nextSibling === null
616 616
                    ||
617 617
                    (
618
-                       $nextSibling instanceof \DOMElement
618
+                        $nextSibling instanceof \DOMElement
619 619
                        &&
620 620
                        (
621
-                           $nextSibling->tagName == 'td'
621
+                            $nextSibling->tagName == 'td'
622 622
                            ||
623 623
                            $nextSibling->tagName == 'th'
624
-                       )
625
-                   )
626
-               )
627
-           )
624
+                        )
625
+                    )
626
+                )
627
+            )
628 628
            ||
629 629
            (
630
-               (
631
-                   $tag_name == 'dd'
630
+                (
631
+                    $tag_name == 'dd'
632 632
                    ||
633 633
                    $tag_name == 'dt'
634
-               )
634
+                )
635 635
                &&
636 636
                (
637
-                   (
638
-                       $nextSibling === null
637
+                    (
638
+                        $nextSibling === null
639 639
                        &&
640 640
                        $tag_name == 'dd'
641
-                   )
641
+                    )
642 642
                    ||
643 643
                    (
644
-                       $nextSibling instanceof \DOMElement
644
+                        $nextSibling instanceof \DOMElement
645 645
                        &&
646 646
                        (
647
-                           $nextSibling->tagName == 'dd'
647
+                            $nextSibling->tagName == 'dd'
648 648
                            ||
649 649
                            $nextSibling->tagName == 'dt'
650
-                       )
651
-                   )
652
-               )
653
-           )
650
+                        )
651
+                    )
652
+                )
653
+            )
654 654
            ||
655 655
            (
656
-               $tag_name == 'option'
656
+                $tag_name == 'option'
657 657
                &&
658 658
                (
659
-                   $nextSibling === null
659
+                    $nextSibling === null
660 660
                    ||
661 661
                    (
662
-                       $nextSibling instanceof \DOMElement
662
+                        $nextSibling instanceof \DOMElement
663 663
                        &&
664 664
                        (
665
-                           $nextSibling->tagName == 'option'
665
+                            $nextSibling->tagName == 'option'
666 666
                            ||
667 667
                            $nextSibling->tagName == 'optgroup'
668
-                       )
669
-                   )
670
-               )
671
-           )
668
+                        )
669
+                    )
670
+                )
671
+            )
672 672
            ||
673 673
            (
674
-               $tag_name == 'p'
674
+                $tag_name == 'p'
675 675
                &&
676 676
                (
677
-                   (
678
-                       $nextSibling === null
677
+                    (
678
+                        $nextSibling === null
679 679
                        &&
680 680
                        (
681
-                           $node->parentNode !== null
681
+                            $node->parentNode !== null
682 682
                            &&
683 683
                            !\in_array(
684
-                               $node->parentNode->nodeName,
685
-                               [
686
-                                   'a',
687
-                                   'audio',
688
-                                   'del',
689
-                                   'ins',
690
-                                   'map',
691
-                                   'noscript',
692
-                                   'video',
693
-                               ],
694
-                               true
695
-                           )
696
-                       )
697
-                   )
684
+                                $node->parentNode->nodeName,
685
+                                [
686
+                                    'a',
687
+                                    'audio',
688
+                                    'del',
689
+                                    'ins',
690
+                                    'map',
691
+                                    'noscript',
692
+                                    'video',
693
+                                ],
694
+                                true
695
+                            )
696
+                        )
697
+                    )
698 698
                    ||
699 699
                    (
700
-                       $nextSibling instanceof \DOMElement
700
+                        $nextSibling instanceof \DOMElement
701 701
                        &&
702 702
                        \in_array(
703
-                           $nextSibling->tagName,
704
-                           [
705
-                               'address',
706
-                               'article',
707
-                               'aside',
708
-                               'blockquote',
709
-                               'dir',
710
-                               'div',
711
-                               'dl',
712
-                               'fieldset',
713
-                               'footer',
714
-                               'form',
715
-                               'h1',
716
-                               'h2',
717
-                               'h3',
718
-                               'h4',
719
-                               'h5',
720
-                               'h6',
721
-                               'header',
722
-                               'hgroup',
723
-                               'hr',
724
-                               'menu',
725
-                               'nav',
726
-                               'ol',
727
-                               'p',
728
-                               'pre',
729
-                               'section',
730
-                               'table',
731
-                               'ul',
732
-                           ],
733
-                           true
734
-                       )
735
-                   )
736
-               )
737
-           );
703
+                            $nextSibling->tagName,
704
+                            [
705
+                                'address',
706
+                                'article',
707
+                                'aside',
708
+                                'blockquote',
709
+                                'dir',
710
+                                'div',
711
+                                'dl',
712
+                                'fieldset',
713
+                                'footer',
714
+                                'form',
715
+                                'h1',
716
+                                'h2',
717
+                                'h3',
718
+                                'h4',
719
+                                'h5',
720
+                                'h6',
721
+                                'header',
722
+                                'hgroup',
723
+                                'hr',
724
+                                'menu',
725
+                                'nav',
726
+                                'ol',
727
+                                'p',
728
+                                'pre',
729
+                                'section',
730
+                                'table',
731
+                                'ul',
732
+                            ],
733
+                            true
734
+                        )
735
+                    )
736
+                )
737
+            );
738 738
   }
739 739
 
740 740
   protected function domNodeToString(\DOMNode $node): string
@@ -769,9 +769,9 @@  discard block
 block discarded – undo
769 769
           }
770 770
 
771 771
           $html .= '<!DOCTYPE ' . $child->name . ''
772
-                   . ($child->publicId ? ' ' . $tmpTypePublic . ' "' . $child->publicId . '"' : '')
773
-                   . ($child->systemId ? ' ' . $tmpTypeSystem . ' "' . $child->systemId . '"' : '')
774
-                   . '>';
772
+                    . ($child->publicId ? ' ' . $tmpTypePublic . ' "' . $child->publicId . '"' : '')
773
+                    . ($child->systemId ? ' ' . $tmpTypeSystem . ' "' . $child->systemId . '"' : '')
774
+                    . '>';
775 775
         }
776 776
 
777 777
       } elseif ($child instanceof \DOMElement) {
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
                       0 == \preg_match('/["\'=<>` \t\r\n\f]+/', $attribute->value);
505 505
 
506 506
         $attr_val = $attribute->value;
507
-        $attrstr .= ($omitquotes ? '' : '"') . $attr_val . ($omitquotes ? '' : '"');
507
+        $attrstr .= ($omitquotes ? '' : '"').$attr_val.($omitquotes ? '' : '"');
508 508
         $attrstr .= ' ';
509 509
       }
510 510
     }
@@ -768,23 +768,23 @@  discard block
 block discarded – undo
768 768
             $tmpTypePublic = 'PUBLIC';
769 769
           }
770 770
 
771
-          $html .= '<!DOCTYPE ' . $child->name . ''
772
-                   . ($child->publicId ? ' ' . $tmpTypePublic . ' "' . $child->publicId . '"' : '')
773
-                   . ($child->systemId ? ' ' . $tmpTypeSystem . ' "' . $child->systemId . '"' : '')
771
+          $html .= '<!DOCTYPE '.$child->name.''
772
+                   . ($child->publicId ? ' '.$tmpTypePublic.' "'.$child->publicId.'"' : '')
773
+                   . ($child->systemId ? ' '.$tmpTypeSystem.' "'.$child->systemId.'"' : '')
774 774
                    . '>';
775 775
         }
776 776
 
777 777
       } elseif ($child instanceof \DOMElement) {
778 778
 
779
-        $html .= \rtrim('<' . $child->tagName . ' ' . $this->domNodeAttributesToString($child));
780
-        $html .= '>' . $this->domNodeToString($child);
779
+        $html .= \rtrim('<'.$child->tagName.' '.$this->domNodeAttributesToString($child));
780
+        $html .= '>'.$this->domNodeToString($child);
781 781
 
782 782
         if (
783 783
             $this->doRemoveOmittedHtmlTags === false
784 784
             ||
785 785
             !$this->domNodeClosingTagOptional($child)
786 786
         ) {
787
-          $html .= '</' . $child->tagName . '>';
787
+          $html .= '</'.$child->tagName.'>';
788 788
         }
789 789
 
790 790
         if ($this->doRemoveWhitespaceAroundTags === false) {
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
    */
886 886
   public function minify($html, $decodeUtf8Specials = false): string
887 887
   {
888
-    $html = (string)$html;
888
+    $html = (string) $html;
889 889
     if (!isset($html[0])) {
890 890
       return '';
891 891
     }
@@ -921,25 +921,25 @@  discard block
 block discarded – undo
921 921
     // -------------------------------------------------------------------------
922 922
 
923 923
     // Remove extra white-space(s) between HTML attribute(s)
924
-    $html = (string)\preg_replace_callback(
924
+    $html = (string) \preg_replace_callback(
925 925
         '#<([^/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(/?)>#',
926
-        function ($matches) {
927
-          return '<' . $matches[1] . (string)\preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]) . $matches[3] . '>';
926
+        function($matches) {
927
+          return '<'.$matches[1].(string) \preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]).$matches[3].'>';
928 928
         },
929 929
         $html
930 930
     );
931 931
 
932 932
     if ($this->doRemoveSpacesBetweenTags === true) {
933 933
       // Remove spaces that are between > and <
934
-      $html = (string)\preg_replace('/(>) (<)/', '>$2', $html);
934
+      $html = (string) \preg_replace('/(>) (<)/', '>$2', $html);
935 935
     }
936 936
 
937 937
     // -------------------------------------------------------------------------
938 938
     // Restore protected HTML-code.
939 939
     // -------------------------------------------------------------------------
940 940
 
941
-    $html = (string)\preg_replace_callback(
942
-        '/<(?<element>' . $this->protectedChildNodesHelper . ')(?<attributes> [^>]*)?>(?<value>.*?)<\/' . $this->protectedChildNodesHelper . '>/',
941
+    $html = (string) \preg_replace_callback(
942
+        '/<(?<element>'.$this->protectedChildNodesHelper.')(?<attributes> [^>]*)?>(?<value>.*?)<\/'.$this->protectedChildNodesHelper.'>/',
943 943
         [$this, 'restoreProtectedHtml'],
944 944
         $html
945 945
     );
@@ -958,14 +958,14 @@  discard block
 block discarded – undo
958 958
 
959 959
     $html = \str_replace(
960 960
         [
961
-            'html>' . "\n",
962
-            "\n" . '<html',
963
-            'html/>' . "\n",
964
-            "\n" . '</html',
965
-            'head>' . "\n",
966
-            "\n" . '<head',
967
-            'head/>' . "\n",
968
-            "\n" . '</head',
961
+            'html>'."\n",
962
+            "\n".'<html',
963
+            'html/>'."\n",
964
+            "\n".'</html',
965
+            'head>'."\n",
966
+            "\n".'<head',
967
+            'head/>'."\n",
968
+            "\n".'</head',
969 969
         ],
970 970
         [
971 971
             'html>',
@@ -984,10 +984,10 @@  discard block
 block discarded – undo
984 984
     $replace = [];
985 985
     $replacement = [];
986 986
     foreach (self::$selfClosingTags as $selfClosingTag) {
987
-      $replace[] = '<' . $selfClosingTag . '/>';
988
-      $replacement[] = '<' . $selfClosingTag . '>';
989
-      $replace[] = '<' . $selfClosingTag . ' />';
990
-      $replacement[] = '<' . $selfClosingTag . '>';
987
+      $replace[] = '<'.$selfClosingTag.'/>';
988
+      $replacement[] = '<'.$selfClosingTag.'>';
989
+      $replace[] = '<'.$selfClosingTag.' />';
990
+      $replacement[] = '<'.$selfClosingTag.'>';
991 991
     }
992 992
     $html = \str_replace(
993 993
         $replace,
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
         $html
996 996
     );
997 997
 
998
-    $html = (string)\preg_replace('#<\b(' . $CACHE_SELF_CLOSING_TAGS . ')([^>]*+)><\/\b\1>#', '<\\1\\2>', $html);
998
+    $html = (string) \preg_replace('#<\b('.$CACHE_SELF_CLOSING_TAGS.')([^>]*+)><\/\b\1>#', '<\\1\\2>', $html);
999 999
 
1000 1000
     // ------------------------------------
1001 1001
     // check if compression worked
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
     }
1095 1095
 
1096 1096
     $attrs = [];
1097
-    foreach ((array)$attributes as $attrName => $attrValue) {
1097
+    foreach ((array) $attributes as $attrName => $attrValue) {
1098 1098
 
1099 1099
       // -------------------------------------------------------------------------
1100 1100
       // Remove optional "http:"-prefix from attributes.
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
       }
1170 1170
 
1171 1171
       $this->protectedChildNodes[$counter] = $element->text();
1172
-      $element->getNode()->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>';
1172
+      $element->getNode()->nodeValue = '<'.$this->protectedChildNodesHelper.' data-'.$this->protectedChildNodesHelper.'="'.$counter.'"></'.$this->protectedChildNodesHelper.'>';
1173 1173
 
1174 1174
       ++$counter;
1175 1175
     }
@@ -1184,11 +1184,11 @@  discard block
 block discarded – undo
1184 1184
         continue;
1185 1185
       }
1186 1186
 
1187
-      $this->protectedChildNodes[$counter] = '<!--' . $text . '-->';
1187
+      $this->protectedChildNodes[$counter] = '<!--'.$text.'-->';
1188 1188
 
1189 1189
       /* @var $node \DOMComment */
1190 1190
       $node = $element->getNode();
1191
-      $child = new \DOMText('<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>');
1191
+      $child = new \DOMText('<'.$this->protectedChildNodesHelper.' data-'.$this->protectedChildNodesHelper.'="'.$counter.'"></'.$this->protectedChildNodesHelper.'>');
1192 1192
       $element->getNode()->parentNode->replaceChild($child, $node);
1193 1193
 
1194 1194
       ++$counter;
@@ -1385,7 +1385,7 @@  discard block
 block discarded – undo
1385 1385
         continue;
1386 1386
       }
1387 1387
 
1388
-      $attrValue .= \trim($class) . ' ';
1388
+      $attrValue .= \trim($class).' ';
1389 1389
     }
1390 1390
     $attrValue = \trim($attrValue);
1391 1391
 
Please login to merge, or discard this patch.