Completed
Pull Request — 5.0 (#1)
by Huberty
02:41
created
src/SwiftTwigMailTemplate.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
      *
105 105
      * @return \Swift_Message
106 106
      */
107
-    public function renderMail(array $data = []) :\Swift_Message
107
+    public function renderMail(array $data = [ ]) :\Swift_Message
108 108
     {
109 109
         $mail = new \Swift_Message();
110 110
 
111 111
         $twigEnvironment = clone $this->twigEnvironment;
112
-        $function = new \Twig_SimpleFunction('embedImage', function ($imgPath) use ($mail) {
112
+        $function = new \Twig_SimpleFunction('embedImage', function($imgPath) use ($mail) {
113 113
             return $mail->embed(\Swift_Image::fromPath($imgPath));
114 114
         });
115 115
         $twigEnvironment->addFunction($function);
@@ -289,17 +289,17 @@  discard block
 block discarded – undo
289 289
      * @param string $keep The list of tags to keep
290 290
      * @param string $expand The list of tags to remove completely, along their content
291 291
      */
292
-    private function removeHtml(string $s , string $keep = '' , string $expand = 'script|style|noframes|select|option') :string
292
+    private function removeHtml(string $s, string $keep = '', string $expand = 'script|style|noframes|select|option') :string
293 293
     {
294 294
         /**///prep the string
295
-        $s = ' ' . $s;
295
+        $s = ' '.$s;
296 296
 
297 297
         /**///initialize keep tag logic
298
-        if(strlen($keep) > 0){
299
-            $k = explode('|',$keep);
300
-            for($i=0;$i<count($k);$i++){
301
-                $s = str_replace('<' . $k[$i],'[{(' . $k[$i],$s);
302
-                $s = str_replace('</' . $k[$i],'[{(/' . $k[$i],$s);
298
+        if (strlen($keep) > 0) {
299
+            $k = explode('|', $keep);
300
+            for ($i = 0; $i < count($k); $i++) {
301
+                $s = str_replace('<'.$k[ $i ], '[{('.$k[ $i ], $s);
302
+                $s = str_replace('</'.$k[ $i ], '[{(/'.$k[ $i ], $s);
303 303
             }
304 304
         }
305 305
         $pos = array();
@@ -307,43 +307,43 @@  discard block
 block discarded – undo
307 307
 
308 308
         //begin removal
309 309
         /**///remove comment blocks
310
-        while(stripos($s,'<!--') > 0){
311
-            $pos[1] = stripos($s,'<!--');
312
-            $pos[2] = stripos($s,'-->', $pos[1]);
313
-            $len[1] = $pos[2] - $pos[1] + 3;
314
-            $x = substr($s,$pos[1],$len[1]);
315
-            $s = str_replace($x,'',$s);
310
+        while (stripos($s, '<!--') > 0) {
311
+            $pos[ 1 ] = stripos($s, '<!--');
312
+            $pos[ 2 ] = stripos($s, '-->', $pos[ 1 ]);
313
+            $len[ 1 ] = $pos[ 2 ] - $pos[ 1 ] + 3;
314
+            $x = substr($s, $pos[ 1 ], $len[ 1 ]);
315
+            $s = str_replace($x, '', $s);
316 316
         }
317 317
 
318 318
         /**///remove tags with content between them
319
-        if(strlen($expand) > 0){
320
-            $e = explode('|',$expand);
321
-            for($i=0;$i<count($e);$i++){
322
-                while(stripos($s,'<' . $e[$i]) > 0){
323
-                    $len[1] = strlen('<' . $e[$i]);
324
-                    $pos[1] = stripos($s,'<' . $e[$i]);
325
-                    $pos[2] = stripos($s,$e[$i] . '>', $pos[1] + $len[1]);
326
-                    $len[2] = $pos[2] - $pos[1] + $len[1];
327
-                    $x = substr($s,$pos[1],$len[2]);
328
-                    $s = str_replace($x,'',$s);
319
+        if (strlen($expand) > 0) {
320
+            $e = explode('|', $expand);
321
+            for ($i = 0; $i < count($e); $i++) {
322
+                while (stripos($s, '<'.$e[ $i ]) > 0) {
323
+                    $len[ 1 ] = strlen('<'.$e[ $i ]);
324
+                    $pos[ 1 ] = stripos($s, '<'.$e[ $i ]);
325
+                    $pos[ 2 ] = stripos($s, $e[ $i ].'>', $pos[ 1 ] + $len[ 1 ]);
326
+                    $len[ 2 ] = $pos[ 2 ] - $pos[ 1 ] + $len[ 1 ];
327
+                    $x = substr($s, $pos[ 1 ], $len[ 2 ]);
328
+                    $s = str_replace($x, '', $s);
329 329
                 }
330 330
             }
331 331
         }
332 332
 
333 333
         /**///remove remaining tags
334
-        while(stripos($s,'<') > 0){
335
-            $pos[1] = stripos($s,'<');
336
-            $pos[2] = stripos($s,'>', $pos[1]);
337
-            $len[1] = $pos[2] - $pos[1] + 1;
338
-            $x = substr($s,$pos[1],$len[1]);
339
-            $s = str_replace($x,'',$s);
334
+        while (stripos($s, '<') > 0) {
335
+            $pos[ 1 ] = stripos($s, '<');
336
+            $pos[ 2 ] = stripos($s, '>', $pos[ 1 ]);
337
+            $len[ 1 ] = $pos[ 2 ] - $pos[ 1 ] + 1;
338
+            $x = substr($s, $pos[ 1 ], $len[ 1 ]);
339
+            $s = str_replace($x, '', $s);
340 340
         }
341 341
 
342 342
         /**///finalize keep tag
343 343
         if (isset($k)) {
344
-            for($i=0;$i<count($k);$i++){
345
-                $s = str_replace('[{(' . $k[$i],'<' . $k[$i],$s);
346
-                $s = str_replace('[{(/' . $k[$i],'</' . $k[$i],$s);
344
+            for ($i = 0; $i < count($k); $i++) {
345
+                $s = str_replace('[{('.$k[ $i ], '<'.$k[ $i ], $s);
346
+                $s = str_replace('[{(/'.$k[ $i ], '</'.$k[ $i ], $s);
347 347
             }
348 348
         }
349 349
 
Please login to merge, or discard this patch.