Completed
Pull Request — master (#23)
by Lars
09:10
created
src/CssToInlineStyles.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
   public function setHTML($html)
145 145
   {
146 146
     // strip style definitions, if we use css-class "cleanup" on a style-element
147
-    $this->html = (string)preg_replace('/<style[^>]+class="cleanup"[^>]*>.*<\/style>/Usi', ' ', $html);
147
+    $this->html = (string) preg_replace('/<style[^>]+class="cleanup"[^>]*>.*<\/style>/Usi', ' ', $html);
148 148
   }
149 149
 
150 150
   /**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
    */
155 155
   public function setCSS($css)
156 156
   {
157
-    $this->css = (string)$css;
157
+    $this->css = (string) $css;
158 158
   }
159 159
 
160 160
   /**
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
   public function convert($outputXHTML = false, $libXMLOptions = 0, $path = false)
196 196
   {
197 197
     // redefine
198
-    $outputXHTML = (bool)$outputXHTML;
198
+    $outputXHTML = (bool) $outputXHTML;
199 199
 
200 200
     // validate
201 201
     if (!$this->html) {
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
       foreach ($document->getElementsByTagName('link') as $node) {
214 214
         
215 215
         /** @noinspection PhpUndefinedMethodInspection */
216
-        $file = ($path ?: __DIR__) . '/' . $node->getAttribute('href');
216
+        $file = ($path ?: __DIR__).'/'.$node->getAttribute('href');
217 217
 
218 218
         if (file_exists($file)) {
219 219
           $css .= file_get_contents($file);
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
     if (!empty($matches[2])) {
287 287
       // add
288 288
       foreach ($matches[2] as $match) {
289
-        $css .= trim($match) . "\n";
289
+        $css .= trim($match)."\n";
290 290
       }
291 291
     }
292 292
 
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
     $cssRules = array();
307 307
 
308 308
     // init vars
309
-    $css = (string)$css;
309
+    $css = (string) $css;
310 310
 
311 311
     $css = $this->doCleanup($css);
312 312
 
313 313
     // rules are splitted by }
314
-    $rules = (array)explode('}', $css);
314
+    $rules = (array) explode('}', $css);
315 315
 
316 316
     // init var
317 317
     $i = 1;
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
       $cssProperties = trim($chunks[1]);
334 334
 
335 335
       // split multiple selectors
336
-      $selectors = (array)explode(',', $selectors);
336
+      $selectors = (array) explode(',', $selectors);
337 337
 
338 338
       // loop selectors
339 339
       foreach ($selectors as $selector) {
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
       $css = $this->stripeMediaQueries($css);
403 403
     }
404 404
 
405
-    return (string)$css;
405
+    return (string) $css;
406 406
   }
407 407
 
408 408
   /**
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
     // remove comments previously to matching media queries
418 418
     $css = preg_replace(self::$styleCommentRegEx, '', $css);
419 419
 
420
-    return (string)preg_replace(self::$cssMediaQueriesRegEx, '', $css);
420
+    return (string) preg_replace(self::$cssMediaQueriesRegEx, '', $css);
421 421
   }
422 422
 
423 423
   /**
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
    */
430 430
   private function stripeCharsetInCss($css)
431 431
   {
432
-    return (string)preg_replace(self::$cssCharsetRegEx, '', $css);
432
+    return (string) preg_replace(self::$cssCharsetRegEx, '', $css);
433 433
   }
434 434
 
435 435
   /**
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
     // loop properties
451 451
     foreach ($properties as $property) {
452 452
       // split into chunks
453
-      $chunks = (array)explode(':', $property, 2);
453
+      $chunks = (array) explode(':', $property, 2);
454 454
 
455 455
       // validate
456 456
       if (!isset($chunks[1])) {
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
    */
489 489
   private function splitIntoProperties($styles)
490 490
   {
491
-    $properties = (array)explode(';', $styles);
491
+    $properties = (array) explode(';', $styles);
492 492
     $propertiesCount = count($properties);
493 493
 
494 494
     /** @noinspection ForeachInvariantsInspection */
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
           &&
501 501
           strpos($properties[$i + 1], 'base64,') !== false
502 502
       ) {
503
-        $properties[$i] .= ';' . $properties[$i + 1];
503
+        $properties[$i] .= ';'.$properties[$i + 1];
504 504
         $properties[$i + 1] = '';
505 505
         ++$i;
506 506
       }
@@ -534,9 +534,9 @@  discard block
 block discarded – undo
534 534
     // with UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
535 535
     //
536 536
     if ($libXMLOptions !== 0) {
537
-      $document->loadHTML('<?xml encoding="' . $this->getEncoding() . '">' . $html, $libXMLOptions);
537
+      $document->loadHTML('<?xml encoding="'.$this->getEncoding().'">'.$html, $libXMLOptions);
538 538
     } else {
539
-      $document->loadHTML('<?xml encoding="' . $this->getEncoding() . '">' . $html);
539
+      $document->loadHTML('<?xml encoding="'.$this->getEncoding().'">'.$html);
540 540
     }
541 541
 
542 542
 
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
     if (null !== $stylesAttribute) {
688 688
       // get value for the styles attribute
689 689
       /** @noinspection PhpUndefinedFieldInspection */
690
-      $definedStyles = (string)$stylesAttribute->value;
690
+      $definedStyles = (string) $stylesAttribute->value;
691 691
 
692 692
       // split into properties
693 693
       $definedProperties = $this->splitIntoProperties($definedStyles);
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
           ||
705 705
           false === stripos($properties[$key], '!important')
706 706
           ||
707
-          false !== stripos(implode('', (array)$value), '!important')
707
+          false !== stripos(implode('', (array) $value), '!important')
708 708
       ) {
709 709
         $properties[$key] = $value;
710 710
       }
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
 
716 716
     // build chunks
717 717
     foreach ($properties as $key => $values) {
718
-      foreach ((array)$values as $value) {
719
-        $propertyChunks[] = $key . ': ' . $value . ';';
718
+      foreach ((array) $values as $value) {
719
+        $propertyChunks[] = $key.': '.$value.';';
720 720
       }
721 721
     }
722 722
 
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
       }
746 746
 
747 747
       // split into chunks
748
-      $chunks = (array)explode(':', trim($property), 2);
748
+      $chunks = (array) explode(':', trim($property), 2);
749 749
 
750 750
       // validate
751 751
       if (!isset($chunks[1])) {
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
    */
812 812
   public function setCleanup($on = true)
813 813
   {
814
-    $this->cleanup = (bool)$on;
814
+    $this->cleanup = (bool) $on;
815 815
   }
816 816
 
817 817
   /**
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
    */
824 824
   public function setEncoding($encoding)
825 825
   {
826
-    $this->encoding = (string)$encoding;
826
+    $this->encoding = (string) $encoding;
827 827
   }
828 828
 
829 829
   /**
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
    */
835 835
   public function setUseInlineStylesBlock($on = true)
836 836
   {
837
-    $this->useInlineStylesBlock = (bool)$on;
837
+    $this->useInlineStylesBlock = (bool) $on;
838 838
   }
839 839
 
840 840
   /**
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
    */
848 848
   public function setLoadCSSFromHTML($on = true)
849 849
   {
850
-    $this->loadCSSFromHTML = (bool)$on;
850
+    $this->loadCSSFromHTML = (bool) $on;
851 851
   }
852 852
 
853 853
   /**
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
    */
859 859
   public function setStripOriginalStyleTags($on = true)
860 860
   {
861
-    $this->stripOriginalStyleTags = (bool)$on;
861
+    $this->stripOriginalStyleTags = (bool) $on;
862 862
   }
863 863
 
864 864
   /**
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
    */
873 873
   public function setExcludeMediaQueries($on = true)
874 874
   {
875
-    $this->excludeMediaQueries = (bool)$on;
875
+    $this->excludeMediaQueries = (bool) $on;
876 876
   }
877 877
 
878 878
   /**
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
    */
883 883
   public function setExcludeCssCharset($on = true)
884 884
   {
885
-    $this->excludeCssCharset = (bool)$on;
885
+    $this->excludeCssCharset = (bool) $on;
886 886
   }
887 887
 
888 888
   /**
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
    */
893 893
   public function setExcludeConditionalInlineStylesBlock($on = true)
894 894
   {
895
-    $this->excludeConditionalInlineStylesBlock = (bool)$on;
895
+    $this->excludeConditionalInlineStylesBlock = (bool) $on;
896 896
   }
897 897
 
898 898
 }
Please login to merge, or discard this patch.
example/index.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 require_once 'config.php';
4
-require_once __DIR__ . '/../vendor/autoload.php';
4
+require_once __DIR__.'/../vendor/autoload.php';
5 5
 
6 6
 use voku\CssToInlineStyles\CssToInlineStyles;
7 7
 
8 8
 // create instance
9 9
 $cssToInlineStyles = new CssToInlineStyles();
10 10
 
11
-$html = file_get_contents(__DIR__ . '/examples/sumo/index.htm');
12
-$css = file_get_contents(__DIR__ . '/examples/sumo/style.css');
11
+$html = file_get_contents(__DIR__.'/examples/sumo/index.htm');
12
+$css = file_get_contents(__DIR__.'/examples/sumo/style.css');
13 13
 
14 14
 $cssToInlineStyles->setHTML($html);
15 15
 $cssToInlineStyles->setCSS($css);
Please login to merge, or discard this patch.