Completed
Push — master ( 441fd6...7e3160 )
by Chris
03:37
created
php/hamle/Text/Filter.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -38,55 +38,55 @@
 block discarded – undo
38 38
   protected $what;
39 39
 
40 40
   function __construct($s, Text $what) {
41
-    if(preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) {
41
+    if (preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) {
42 42
       $this->filter = $m[1];
43 43
       $this->vars = isset($m[3]) ? explode(',', $m[3]) : [];
44
-      foreach($this->vars as $k=>$v)
45
-        $this->vars[$k] = str_replace(",",',',$v);
44
+      foreach ($this->vars as $k=>$v)
45
+        $this->vars[$k] = str_replace(",", ',', $v);
46 46
     } else {
47 47
       throw new ParseError("Unable to parse filter expression \"$s\"");
48 48
     }
49
-    if(!in_array($this->filter, ['itersplit', 'newlinebr', 'round',
50
-        'strtoupper', 'strtolower', 'ucfirst','replace', 'json'])) {
49
+    if (!in_array($this->filter, ['itersplit', 'newlinebr', 'round',
50
+        'strtoupper', 'strtolower', 'ucfirst', 'replace', 'json'])) {
51 51
       throw new ParseError("Unknown Filter Type \"{$this->filter}\"");
52 52
     }
53
-    if(in_array($this->filter,['itersplit','newlinebr', 'replace'])) {
53
+    if (in_array($this->filter, ['itersplit', 'newlinebr', 'replace'])) {
54 54
         $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}";
55 55
     }
56 56
     $mapFilter = ['json'=>'json_encode'];
57
-    if(isset($mapFilter[$this->filter]))
57
+    if (isset($mapFilter[$this->filter]))
58 58
       $this->filter = $mapFilter[$this->filter];
59 59
     $this->what = $what;
60 60
   }
61 61
 
62 62
   function toHTML($escape = false) {
63
-    if($escape)
64
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
65
-    return "<?=" . $this->toPHP() . "?>";
63
+    if ($escape)
64
+      return "<?=htmlspecialchars(".$this->toPHP().")?>";
65
+    return "<?=".$this->toPHP()."?>";
66 66
   }
67 67
 
68 68
   function toPHP() {
69
-    $o = [$this->what->toPHPVar()] ;
70
-    foreach($this->vars as $v)
69
+    $o = [$this->what->toPHPVar()];
70
+    foreach ($this->vars as $v)
71 71
       $o[] = $this->varToCode($v);
72
-    return "{$this->filter}(" . implode(',',$o) . ")";
72
+    return "{$this->filter}(".implode(',', $o).")";
73 73
   }
74 74
 
75 75
   static function itersplit($v, $sep = ",") {
76 76
     $o = [];
77
-    foreach(explode($sep, $v) as $k=>$i) {
78
-      if($i)
79
-        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
77
+    foreach (explode($sep, $v) as $k=>$i) {
78
+      if ($i)
79
+        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k];
80 80
     }
81 81
     return new WrapArray($o);
82 82
   }
83 83
 
84 84
   static function newlinebr($v) {
85
-    return str_replace("\n","<br />\n",$v);
85
+    return str_replace("\n", "<br />\n", $v);
86 86
   }
87 87
 
88 88
   static function replace($v, $src, $dst) {
89
-    return str_replace($src,$dst,$v);
89
+    return str_replace($src, $dst, $v);
90 90
   }
91 91
 
92 92
 }
93 93
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -41,8 +41,9 @@  discard block
 block discarded – undo
41 41
     if(preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) {
42 42
       $this->filter = $m[1];
43 43
       $this->vars = isset($m[3]) ? explode(',', $m[3]) : [];
44
-      foreach($this->vars as $k=>$v)
45
-        $this->vars[$k] = str_replace("&comma;",',',$v);
44
+      foreach($this->vars as $k=>$v) {
45
+              $this->vars[$k] = str_replace("&comma;",',',$v);
46
+      }
46 47
     } else {
47 48
       throw new ParseError("Unable to parse filter expression \"$s\"");
48 49
     }
@@ -54,29 +55,33 @@  discard block
 block discarded – undo
54 55
         $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}";
55 56
     }
56 57
     $mapFilter = ['json'=>'json_encode'];
57
-    if(isset($mapFilter[$this->filter]))
58
-      $this->filter = $mapFilter[$this->filter];
58
+    if(isset($mapFilter[$this->filter])) {
59
+          $this->filter = $mapFilter[$this->filter];
60
+    }
59 61
     $this->what = $what;
60 62
   }
61 63
 
62 64
   function toHTML($escape = false) {
63
-    if($escape)
64
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
65
+    if($escape) {
66
+          return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
67
+    }
65 68
     return "<?=" . $this->toPHP() . "?>";
66 69
   }
67 70
 
68 71
   function toPHP() {
69 72
     $o = [$this->what->toPHPVar()] ;
70
-    foreach($this->vars as $v)
71
-      $o[] = $this->varToCode($v);
73
+    foreach($this->vars as $v) {
74
+          $o[] = $this->varToCode($v);
75
+    }
72 76
     return "{$this->filter}(" . implode(',',$o) . ")";
73 77
   }
74 78
 
75 79
   static function itersplit($v, $sep = ",") {
76 80
     $o = [];
77 81
     foreach(explode($sep, $v) as $k=>$i) {
78
-      if($i)
79
-        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
82
+      if($i) {
83
+              $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
84
+      }
80 85
     }
81 86
     return new WrapArray($o);
82 87
   }
Please login to merge, or discard this patch.