Completed
Push — master ( 60e98c...d80912 )
by Lars
01:25
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
@@ -551,184 +551,184 @@  discard block
 block discarded – undo
551 551
     return \in_array($tag_name, self::$optional_end_tags, true)
552 552
            ||
553 553
            (
554
-               $tag_name == 'li'
554
+                $tag_name == 'li'
555 555
                &&
556 556
                (
557
-                   $nextSibling === null
557
+                    $nextSibling === null
558 558
                    ||
559 559
                    (
560
-                       $nextSibling instanceof \DOMElement
560
+                        $nextSibling instanceof \DOMElement
561 561
                        &&
562 562
                        $nextSibling->tagName == 'li'
563
-                   )
564
-               )
565
-           )
563
+                    )
564
+                )
565
+            )
566 566
            ||
567 567
            (
568
-               (
569
-                   $tag_name == 'rp'
570
-               )
568
+                (
569
+                    $tag_name == 'rp'
570
+                )
571 571
                &&
572 572
                (
573
-                   $nextSibling === null
573
+                    $nextSibling === null
574 574
                    ||
575 575
                    (
576
-                       $nextSibling instanceof \DOMElement
576
+                        $nextSibling instanceof \DOMElement
577 577
                        &&
578 578
                        (
579
-                           $nextSibling->tagName == 'rp'
579
+                            $nextSibling->tagName == 'rp'
580 580
                            ||
581 581
                            $nextSibling->tagName == 'rt'
582
-                       )
583
-                   )
584
-               )
585
-           )
582
+                        )
583
+                    )
584
+                )
585
+            )
586 586
            ||
587 587
            (
588
-               $tag_name == 'tr'
588
+                $tag_name == 'tr'
589 589
                &&
590 590
                (
591
-                   $nextSibling === null
591
+                    $nextSibling === null
592 592
                    ||
593 593
                    (
594
-                       $nextSibling instanceof \DOMElement
594
+                        $nextSibling instanceof \DOMElement
595 595
                        &&
596 596
                        $nextSibling->tagName == 'tr'
597
-                   )
598
-               )
599
-           )
597
+                    )
598
+                )
599
+            )
600 600
            ||
601 601
            (
602
-               (
603
-                   $tag_name == 'td'
602
+                (
603
+                    $tag_name == 'td'
604 604
                    ||
605 605
                    $tag_name == 'th'
606
-               )
606
+                )
607 607
                &&
608 608
                (
609
-                   $nextSibling === null
609
+                    $nextSibling === null
610 610
                    ||
611 611
                    (
612
-                       $nextSibling instanceof \DOMElement
612
+                        $nextSibling instanceof \DOMElement
613 613
                        &&
614 614
                        (
615
-                           $nextSibling->tagName == 'td'
615
+                            $nextSibling->tagName == 'td'
616 616
                            ||
617 617
                            $nextSibling->tagName == 'th'
618
-                       )
619
-                   )
620
-               )
621
-           )
618
+                        )
619
+                    )
620
+                )
621
+            )
622 622
            ||
623 623
            (
624
-               (
625
-                   $tag_name == 'dd'
624
+                (
625
+                    $tag_name == 'dd'
626 626
                    ||
627 627
                    $tag_name == 'dt'
628
-               )
628
+                )
629 629
                &&
630 630
                (
631
-                   (
632
-                       $nextSibling === null
631
+                    (
632
+                        $nextSibling === null
633 633
                        &&
634 634
                        $tag_name == 'dd'
635
-                   )
635
+                    )
636 636
                    ||
637 637
                    (
638
-                       $nextSibling instanceof \DOMElement
638
+                        $nextSibling instanceof \DOMElement
639 639
                        &&
640 640
                        (
641
-                           $nextSibling->tagName == 'dd'
641
+                            $nextSibling->tagName == 'dd'
642 642
                            ||
643 643
                            $nextSibling->tagName == 'dt'
644
-                       )
645
-                   )
646
-               )
647
-           )
644
+                        )
645
+                    )
646
+                )
647
+            )
648 648
            ||
649 649
            (
650
-               $tag_name == 'option'
650
+                $tag_name == 'option'
651 651
                &&
652 652
                (
653
-                   $nextSibling === null
653
+                    $nextSibling === null
654 654
                    ||
655 655
                    (
656
-                       $nextSibling instanceof \DOMElement
656
+                        $nextSibling instanceof \DOMElement
657 657
                        &&
658 658
                        (
659
-                           $nextSibling->tagName == 'option'
659
+                            $nextSibling->tagName == 'option'
660 660
                            ||
661 661
                            $nextSibling->tagName == 'optgroup'
662
-                       )
663
-                   )
664
-               )
665
-           )
662
+                        )
663
+                    )
664
+                )
665
+            )
666 666
            ||
667 667
            (
668
-               $tag_name == 'p'
668
+                $tag_name == 'p'
669 669
                &&
670 670
                (
671
-                   (
672
-                       $nextSibling === null
671
+                    (
672
+                        $nextSibling === null
673 673
                        &&
674 674
                        (
675
-                           $node->parentNode !== null
675
+                            $node->parentNode !== null
676 676
                            &&
677 677
                            !\in_array(
678
-                               $node->parentNode->tagName,
679
-                               [
680
-                                   'a',
681
-                                   'audio',
682
-                                   'del',
683
-                                   'ins',
684
-                                   'map',
685
-                                   'noscript',
686
-                                   'video',
687
-                               ],
688
-                               true
689
-                           )
690
-                       )
691
-                   )
678
+                                $node->parentNode->tagName,
679
+                                [
680
+                                    'a',
681
+                                    'audio',
682
+                                    'del',
683
+                                    'ins',
684
+                                    'map',
685
+                                    'noscript',
686
+                                    'video',
687
+                                ],
688
+                                true
689
+                            )
690
+                        )
691
+                    )
692 692
                    ||
693 693
                    (
694
-                       $nextSibling instanceof \DOMElement
694
+                        $nextSibling instanceof \DOMElement
695 695
                        &&
696 696
                        \in_array(
697
-                           $nextSibling->tagName,
698
-                           [
699
-                               'address',
700
-                               'article',
701
-                               'aside',
702
-                               'blockquote',
703
-                               'dir',
704
-                               'div',
705
-                               'dl',
706
-                               'fieldset',
707
-                               'footer',
708
-                               'form',
709
-                               'h1',
710
-                               'h2',
711
-                               'h3',
712
-                               'h4',
713
-                               'h5',
714
-                               'h6',
715
-                               'header',
716
-                               'hgroup',
717
-                               'hr',
718
-                               'menu',
719
-                               'nav',
720
-                               'ol',
721
-                               'p',
722
-                               'pre',
723
-                               'section',
724
-                               'table',
725
-                               'ul',
726
-                           ],
727
-                           true
728
-                       )
729
-                   )
730
-               )
731
-           );
697
+                            $nextSibling->tagName,
698
+                            [
699
+                                'address',
700
+                                'article',
701
+                                'aside',
702
+                                'blockquote',
703
+                                'dir',
704
+                                'div',
705
+                                'dl',
706
+                                'fieldset',
707
+                                'footer',
708
+                                'form',
709
+                                'h1',
710
+                                'h2',
711
+                                'h3',
712
+                                'h4',
713
+                                'h5',
714
+                                'h6',
715
+                                'header',
716
+                                'hgroup',
717
+                                'hr',
718
+                                'menu',
719
+                                'nav',
720
+                                'ol',
721
+                                'p',
722
+                                'pre',
723
+                                'section',
724
+                                'table',
725
+                                'ul',
726
+                            ],
727
+                            true
728
+                        )
729
+                    )
730
+                )
731
+            );
732 732
   }
733 733
 
734 734
   protected function domNodeToString(\DOMNode $node): string
@@ -756,9 +756,9 @@  discard block
 block discarded – undo
756 756
           }
757 757
 
758 758
           $html .= '<!DOCTYPE ' . $child->name . ''
759
-                   . ($child->publicId ? ' ' . $tmpTypePublic . ' "' . $child->publicId . '"' : '')
760
-                   . ($child->systemId ? ' ' . $tmpTypeSystem . ' "' . $child->systemId . '"' : '')
761
-                   . '>';
759
+                    . ($child->publicId ? ' ' . $tmpTypePublic . ' "' . $child->publicId . '"' : '')
760
+                    . ($child->systemId ? ' ' . $tmpTypeSystem . ' "' . $child->systemId . '"' : '')
761
+                    . '>';
762 762
         }
763 763
 
764 764
       } else if ($child instanceof \DOMElement) {
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 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
 
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
                       0 == \preg_match('/["\'=<>` \t\r\n\f]+/', $attribute->value);
504 504
 
505 505
         $attr_val = $attribute->value;
506
-        $attrstr .= ($omitquotes ? '' : '"') . $attr_val . ($omitquotes ? '' : '"');
506
+        $attrstr .= ($omitquotes ? '' : '"').$attr_val.($omitquotes ? '' : '"');
507 507
         $attrstr .= ' ';
508 508
       }
509 509
     }
@@ -755,22 +755,22 @@  discard block
 block discarded – undo
755 755
             $tmpTypePublic = 'PUBLIC';
756 756
           }
757 757
 
758
-          $html .= '<!DOCTYPE ' . $child->name . ''
759
-                   . ($child->publicId ? ' ' . $tmpTypePublic . ' "' . $child->publicId . '"' : '')
760
-                   . ($child->systemId ? ' ' . $tmpTypeSystem . ' "' . $child->systemId . '"' : '')
758
+          $html .= '<!DOCTYPE '.$child->name.''
759
+                   . ($child->publicId ? ' '.$tmpTypePublic.' "'.$child->publicId.'"' : '')
760
+                   . ($child->systemId ? ' '.$tmpTypeSystem.' "'.$child->systemId.'"' : '')
761 761
                    . '>';
762 762
         }
763 763
 
764 764
       } else if ($child instanceof \DOMElement) {
765 765
 
766
-        $html .= trim('<' . $child->tagName . ' ' . $this->domNodeAttributesToString($child));
767
-        $html .= '>' . $this->domNodeToString($child);
766
+        $html .= trim('<'.$child->tagName.' '.$this->domNodeAttributesToString($child));
767
+        $html .= '>'.$this->domNodeToString($child);
768 768
 
769 769
         if (
770 770
             $this->doRemoveOmittedHtmlTags === false
771 771
             ||
772 772
             !$this->domNodeClosingTagOptional($child)) {
773
-          $html .= '</' . $child->tagName . '>';
773
+          $html .= '</'.$child->tagName.'>';
774 774
         }
775 775
 
776 776
       } elseif ($child instanceof \DOMText) {
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
    */
845 845
   public function minify($html, $decodeUtf8Specials = false): string
846 846
   {
847
-    $html = (string)$html;
847
+    $html = (string) $html;
848 848
     if (!isset($html[0])) {
849 849
       return '';
850 850
     }
@@ -880,10 +880,10 @@  discard block
 block discarded – undo
880 880
     // -------------------------------------------------------------------------
881 881
 
882 882
     // Remove extra white-space(s) between HTML attribute(s)
883
-    $html = (string)\preg_replace_callback(
883
+    $html = (string) \preg_replace_callback(
884 884
         '#<([^\/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#',
885
-        function ($matches) {
886
-          return '<' . $matches[1] . (string)\preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]) . $matches[3] . '>';
885
+        function($matches) {
886
+          return '<'.$matches[1].(string) \preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]).$matches[3].'>';
887 887
         },
888 888
         $html
889 889
     );
@@ -891,15 +891,15 @@  discard block
 block discarded – undo
891 891
 
892 892
     if ($this->doRemoveSpacesBetweenTags === true) {
893 893
       // Remove spaces that are between > and <
894
-      $html = (string)\preg_replace('/(>) (<)/', '>$2', $html);
894
+      $html = (string) \preg_replace('/(>) (<)/', '>$2', $html);
895 895
     }
896 896
 
897 897
     // -------------------------------------------------------------------------
898 898
     // Restore protected HTML-code.
899 899
     // -------------------------------------------------------------------------
900 900
 
901
-    $html = (string)\preg_replace_callback(
902
-        '/<(?<element>' . $this->protectedChildNodesHelper . ')(?<attributes> [^>]*)?>(?<value>.*?)<\/' . $this->protectedChildNodesHelper . '>/',
901
+    $html = (string) \preg_replace_callback(
902
+        '/<(?<element>'.$this->protectedChildNodesHelper.')(?<attributes> [^>]*)?>(?<value>.*?)<\/'.$this->protectedChildNodesHelper.'>/',
903 903
         [$this, 'restoreProtectedHtml'],
904 904
         $html
905 905
     );
@@ -920,14 +920,14 @@  discard block
 block discarded – undo
920 920
 
921 921
     $html = \str_replace(
922 922
         [
923
-            'html>' . "\n",
924
-            "\n" . '<html',
925
-            'html/>' . "\n",
926
-            "\n" . '</html',
927
-            'head>' . "\n",
928
-            "\n" . '<head',
929
-            'head/>' . "\n",
930
-            "\n" . '</head',
923
+            'html>'."\n",
924
+            "\n".'<html',
925
+            'html/>'."\n",
926
+            "\n".'</html',
927
+            'head>'."\n",
928
+            "\n".'<head',
929
+            'head/>'."\n",
930
+            "\n".'</head',
931 931
         ],
932 932
         [
933 933
             'html>',
@@ -946,10 +946,10 @@  discard block
 block discarded – undo
946 946
     $replace = [];
947 947
     $replacement = [];
948 948
     foreach (self::$selfClosingTags as $selfClosingTag) {
949
-      $replace[] = '<' . $selfClosingTag . '/>';
950
-      $replacement[] = '<' . $selfClosingTag . '>';
951
-      $replace[] = '<' . $selfClosingTag . ' />';
952
-      $replacement[] = '<' . $selfClosingTag . '>';
949
+      $replace[] = '<'.$selfClosingTag.'/>';
950
+      $replacement[] = '<'.$selfClosingTag.'>';
951
+      $replace[] = '<'.$selfClosingTag.' />';
952
+      $replacement[] = '<'.$selfClosingTag.'>';
953 953
     }
954 954
     $html = \str_replace(
955 955
         $replace,
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
         $html
958 958
     );
959 959
 
960
-    $html = (string)\preg_replace('#<\b(' . $CACHE_SELF_CLOSING_TAGS . ')([^>]+)><\/\b\1>#', '<\\1\\2>', $html);
960
+    $html = (string) \preg_replace('#<\b('.$CACHE_SELF_CLOSING_TAGS.')([^>]+)><\/\b\1>#', '<\\1\\2>', $html);
961 961
 
962 962
     // ------------------------------------
963 963
     // check if compression worked
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
     }
1057 1057
 
1058 1058
     $attrs = [];
1059
-    foreach ((array)$attributes as $attrName => $attrValue) {
1059
+    foreach ((array) $attributes as $attrName => $attrValue) {
1060 1060
 
1061 1061
       // -------------------------------------------------------------------------
1062 1062
       // Remove optional "http:"-prefix from attributes.
@@ -1131,7 +1131,7 @@  discard block
 block discarded – undo
1131 1131
       }
1132 1132
 
1133 1133
       $this->protectedChildNodes[$counter] = $element->text();
1134
-      $element->getNode()->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>';
1134
+      $element->getNode()->nodeValue = '<'.$this->protectedChildNodesHelper.' data-'.$this->protectedChildNodesHelper.'="'.$counter.'"></'.$this->protectedChildNodesHelper.'>';
1135 1135
 
1136 1136
       ++$counter;
1137 1137
     }
@@ -1146,11 +1146,11 @@  discard block
 block discarded – undo
1146 1146
         continue;
1147 1147
       }
1148 1148
 
1149
-      $this->protectedChildNodes[$counter] = '<!--' . $text . '-->';
1149
+      $this->protectedChildNodes[$counter] = '<!--'.$text.'-->';
1150 1150
 
1151 1151
       /* @var $node \DOMComment */
1152 1152
       $node = $element->getNode();
1153
-      $child = new \DOMText('<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>');
1153
+      $child = new \DOMText('<'.$this->protectedChildNodesHelper.' data-'.$this->protectedChildNodesHelper.'="'.$counter.'"></'.$this->protectedChildNodesHelper.'>');
1154 1154
       $element->getNode()->parentNode->replaceChild($child, $node);
1155 1155
 
1156 1156
       ++$counter;
@@ -1347,7 +1347,7 @@  discard block
 block discarded – undo
1347 1347
         continue;
1348 1348
       }
1349 1349
 
1350
-      $attrValue .= \trim($class) . ' ';
1350
+      $attrValue .= \trim($class).' ';
1351 1351
     }
1352 1352
     $attrValue = \trim($attrValue);
1353 1353
 
Please login to merge, or discard this patch.