Completed
Push — master ( 709799...b4b5ef )
by Lars
01:21
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.
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
       } elseif ($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
       } elseif ($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
     }
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
    */
661 661
   public function minify($html, $decodeUtf8Specials = false): string
662 662
   {
663
-    $html = (string)$html;
663
+    $html = (string) $html;
664 664
     if (!isset($html[0])) {
665 665
       return '';
666 666
     }
@@ -696,10 +696,10 @@  discard block
 block discarded – undo
696 696
     // -------------------------------------------------------------------------
697 697
 
698 698
     // Remove extra white-space(s) between HTML attribute(s)
699
-    $html = (string)\preg_replace_callback(
699
+    $html = (string) \preg_replace_callback(
700 700
         '#<([^\/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#',
701
-        function ($matches) {
702
-          return '<' . $matches[1] . (string)\preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]) . $matches[3] . '>';
701
+        function($matches) {
702
+          return '<'.$matches[1].(string) \preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]).$matches[3].'>';
703 703
         },
704 704
         $html
705 705
     );
@@ -707,15 +707,15 @@  discard block
 block discarded – undo
707 707
 
708 708
     if ($this->doRemoveSpacesBetweenTags === true) {
709 709
       // Remove spaces that are between > and <
710
-      $html = (string)\preg_replace('/(>) (<)/', '>$2', $html);
710
+      $html = (string) \preg_replace('/(>) (<)/', '>$2', $html);
711 711
     }
712 712
 
713 713
     // -------------------------------------------------------------------------
714 714
     // Restore protected HTML-code.
715 715
     // -------------------------------------------------------------------------
716 716
 
717
-    $html = (string)\preg_replace_callback(
718
-        '/<(?<element>' . $this->protectedChildNodesHelper . ')(?<attributes> [^>]*)?>(?<value>.*?)<\/' . $this->protectedChildNodesHelper . '>/',
717
+    $html = (string) \preg_replace_callback(
718
+        '/<(?<element>'.$this->protectedChildNodesHelper.')(?<attributes> [^>]*)?>(?<value>.*?)<\/'.$this->protectedChildNodesHelper.'>/',
719 719
         [$this, 'restoreProtectedHtml'],
720 720
         $html
721 721
     );
@@ -736,14 +736,14 @@  discard block
 block discarded – undo
736 736
 
737 737
     $html = \str_replace(
738 738
         [
739
-            'html>' . "\n",
740
-            "\n" . '<html',
741
-            'html/>' . "\n",
742
-            "\n" . '</html',
743
-            'head>' . "\n",
744
-            "\n" . '<head',
745
-            'head/>' . "\n",
746
-            "\n" . '</head',
739
+            'html>'."\n",
740
+            "\n".'<html',
741
+            'html/>'."\n",
742
+            "\n".'</html',
743
+            'head>'."\n",
744
+            "\n".'<head',
745
+            'head/>'."\n",
746
+            "\n".'</head',
747 747
         ],
748 748
         [
749 749
             'html>',
@@ -762,10 +762,10 @@  discard block
 block discarded – undo
762 762
     $replace = [];
763 763
     $replacement = [];
764 764
     foreach (self::$selfClosingTags as $selfClosingTag) {
765
-      $replace[] = '<' . $selfClosingTag . '/>';
766
-      $replacement[] = '<' . $selfClosingTag . '>';
767
-      $replace[] = '<' . $selfClosingTag . ' />';
768
-      $replacement[] = '<' . $selfClosingTag . '>';
765
+      $replace[] = '<'.$selfClosingTag.'/>';
766
+      $replacement[] = '<'.$selfClosingTag.'>';
767
+      $replace[] = '<'.$selfClosingTag.' />';
768
+      $replacement[] = '<'.$selfClosingTag.'>';
769 769
     }
770 770
     $html = \str_replace(
771 771
         $replace,
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
     }
869 869
 
870 870
     $attrs = [];
871
-    foreach ((array)$attributes as $attrName => $attrValue) {
871
+    foreach ((array) $attributes as $attrName => $attrValue) {
872 872
 
873 873
       if (isset(self::$booleanAttributes[$attrName])) {
874 874
         continue;
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
       }
948 948
 
949 949
       $this->protectedChildNodes[$counter] = $element->text();
950
-      $element->getNode()->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>';
950
+      $element->getNode()->nodeValue = '<'.$this->protectedChildNodesHelper.' data-'.$this->protectedChildNodesHelper.'="'.$counter.'"></'.$this->protectedChildNodesHelper.'>';
951 951
 
952 952
       ++$counter;
953 953
     }
@@ -962,11 +962,11 @@  discard block
 block discarded – undo
962 962
         continue;
963 963
       }
964 964
 
965
-      $this->protectedChildNodes[$counter] = '<!--' . $text . '-->';
965
+      $this->protectedChildNodes[$counter] = '<!--'.$text.'-->';
966 966
 
967 967
       /* @var $node \DOMComment */
968 968
       $node = $element->getNode();
969
-      $child = new \DOMText('<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>');
969
+      $child = new \DOMText('<'.$this->protectedChildNodesHelper.' data-'.$this->protectedChildNodesHelper.'="'.$counter.'"></'.$this->protectedChildNodesHelper.'>');
970 970
       $element->getNode()->parentNode->replaceChild($child, $node);
971 971
 
972 972
       ++$counter;
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
         continue;
1164 1164
       }
1165 1165
 
1166
-      $attrValue .= \trim($class) . ' ';
1166
+      $attrValue .= \trim($class).' ';
1167 1167
     }
1168 1168
     $attrValue = \trim($attrValue);
1169 1169
 
Please login to merge, or discard this patch.
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -500,134 +500,134 @@
 block discarded – undo
500 500
     return \in_array($tag_name, self::$optional_end_tags, true)
501 501
            ||
502 502
            (
503
-               $tag_name == 'li'
503
+                $tag_name == 'li'
504 504
                &&
505 505
                (
506
-                   $nextSibling === null
506
+                    $nextSibling === null
507 507
                    ||
508 508
                    (
509
-                       $nextSibling instanceof \DOMElement
509
+                        $nextSibling instanceof \DOMElement
510 510
                        &&
511 511
                        $nextSibling->tagName == 'li'
512
-                   )
513
-               )
514
-           )
512
+                    )
513
+                )
514
+            )
515 515
            ||
516 516
            (
517
-               $tag_name == 'tr'
517
+                $tag_name == 'tr'
518 518
                &&
519 519
                (
520
-                   $nextSibling === null
520
+                    $nextSibling === null
521 521
                    ||
522 522
                    (
523
-                       $nextSibling instanceof \DOMElement
523
+                        $nextSibling instanceof \DOMElement
524 524
                        &&
525 525
                        $nextSibling->tagName == 'tr'
526
-                   )
527
-               )
528
-           )
526
+                    )
527
+                )
528
+            )
529 529
            ||
530 530
            (
531
-               $tag_name == 'td'
531
+                $tag_name == 'td'
532 532
                &&
533 533
                (
534
-                   $nextSibling === null
534
+                    $nextSibling === null
535 535
                    ||
536 536
                    (
537
-                       $nextSibling instanceof \DOMElement
537
+                        $nextSibling instanceof \DOMElement
538 538
                        &&
539 539
                        (
540
-                           $nextSibling->tagName == 'td'
540
+                            $nextSibling->tagName == 'td'
541 541
                            ||
542 542
                            $nextSibling->tagName == 'th'
543
-                       )
544
-                   )
545
-               )
546
-           )
543
+                        )
544
+                    )
545
+                )
546
+            )
547 547
            ||
548 548
            (
549
-               $tag_name == 'option'
549
+                $tag_name == 'option'
550 550
                &&
551 551
                (
552
-                   $nextSibling === null
552
+                    $nextSibling === null
553 553
                    ||
554 554
                    (
555
-                       $nextSibling instanceof \DOMElement
555
+                        $nextSibling instanceof \DOMElement
556 556
                        &&
557 557
                        (
558
-                           $nextSibling->tagName == 'option'
558
+                            $nextSibling->tagName == 'option'
559 559
                            ||
560 560
                            $nextSibling->tagName == 'optgroup'
561
-                       )
562
-                   )
563
-               )
564
-           )
561
+                        )
562
+                    )
563
+                )
564
+            )
565 565
            ||
566 566
            (
567
-               $tag_name == 'p'
567
+                $tag_name == 'p'
568 568
                &&
569 569
                (
570
-                   (
571
-                       $nextSibling === null
570
+                    (
571
+                        $nextSibling === null
572 572
                        &&
573 573
                        (
574
-                           $node->parentNode !== null
574
+                            $node->parentNode !== null
575 575
                            &&
576 576
                            !\in_array(
577
-                               $node->parentNode->tagName,
578
-                               [
579
-                                   'a',
580
-                                   'audio',
581
-                                   'del',
582
-                                   'ins',
583
-                                   'map',
584
-                                   'noscript',
585
-                                   'video'
586
-                               ],
587
-                               true
588
-                           )
589
-                       )
590
-                   )
577
+                                $node->parentNode->tagName,
578
+                                [
579
+                                    'a',
580
+                                    'audio',
581
+                                    'del',
582
+                                    'ins',
583
+                                    'map',
584
+                                    'noscript',
585
+                                    'video'
586
+                                ],
587
+                                true
588
+                            )
589
+                        )
590
+                    )
591 591
                    ||
592 592
                    (
593
-                       $nextSibling instanceof \DOMElement
593
+                        $nextSibling instanceof \DOMElement
594 594
                        &&
595 595
                        \in_array(
596
-                           $nextSibling->tagName,
597
-                           [
598
-                               'address',
599
-                               'article',
600
-                               'aside',
601
-                               'blockquote',
602
-                               'dir',
603
-                               'div',
604
-                               'dl',
605
-                               'fieldset',
606
-                               'footer',
607
-                               'form',
608
-                               'h1',
609
-                               'h2',
610
-                               'h3',
611
-                               'h4',
612
-                               'h5',
613
-                               'h6',
614
-                               'header',
615
-                               'hgroup',
616
-                               'hr',
617
-                               'menu',
618
-                               'nav',
619
-                               'ol',
620
-                               'p',
621
-                               'pre',
622
-                               'section',
623
-                               'table',
624
-                               'ul',
625
-                           ],
626
-                           true
627
-                       )
628
-                   )
629
-               )
630
-           );
596
+                            $nextSibling->tagName,
597
+                            [
598
+                                'address',
599
+                                'article',
600
+                                'aside',
601
+                                'blockquote',
602
+                                'dir',
603
+                                'div',
604
+                                'dl',
605
+                                'fieldset',
606
+                                'footer',
607
+                                'form',
608
+                                'h1',
609
+                                'h2',
610
+                                'h3',
611
+                                'h4',
612
+                                'h5',
613
+                                'h6',
614
+                                'header',
615
+                                'hgroup',
616
+                                'hr',
617
+                                'menu',
618
+                                'nav',
619
+                                'ol',
620
+                                'p',
621
+                                'pre',
622
+                                'section',
623
+                                'table',
624
+                                'ul',
625
+                            ],
626
+                            true
627
+                        )
628
+                    )
629
+                )
630
+            );
631 631
   }
632 632
 
633 633
   protected function domNodeToString(\DOMNode $node): string
Please login to merge, or discard this patch.