Passed
Push — master ( 2b3dd9...f88783 )
by Chris
01:40
created
php/hamle/Text/Filter.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -41,49 +41,49 @@  discard block
 block discarded – undo
41 41
   protected $chained;
42 42
 
43 43
   function __construct($s, Text $what) {
44
-    if(preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) {
44
+    if (preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) {
45 45
       $this->filter = $m[1];
46 46
       $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : [];
47
-      foreach($this->vars as $k=>$v)
48
-        $this->vars[$k] = str_replace("&comma;",',',$v);
49
-      if(isset($m['chained']) && strlen($m['chained'])) {
50
-        $this->chained = new Filter($m['chained'],$what);
47
+      foreach ($this->vars as $k=>$v)
48
+        $this->vars[$k] = str_replace("&comma;", ',', $v);
49
+      if (isset($m['chained']) && strlen($m['chained'])) {
50
+        $this->chained = new Filter($m['chained'], $what);
51 51
       }
52 52
     } else {
53 53
       throw new ParseError("Unable to parse filter expression \"$s\"");
54 54
     }
55
-    if(!in_array($this->filter, ['itersplit', 'newlinebr', 'round',
56
-        'strtoupper', 'strtolower', 'ucfirst','replace', 'json'])) {
55
+    if (!in_array($this->filter, ['itersplit', 'newlinebr', 'round',
56
+        'strtoupper', 'strtolower', 'ucfirst', 'replace', 'json'])) {
57 57
       throw new ParseError("Unknown Filter Type \"{$this->filter}\"");
58 58
     }
59
-    if(in_array($this->filter,['itersplit','newlinebr', 'replace'])) {
59
+    if (in_array($this->filter, ['itersplit', 'newlinebr', 'replace'])) {
60 60
         $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}";
61 61
     }
62 62
     $mapFilter = ['json'=>'json_encode'];
63
-    if(isset($mapFilter[$this->filter]))
63
+    if (isset($mapFilter[$this->filter]))
64 64
       $this->filter = $mapFilter[$this->filter];
65 65
     $this->what = $what;
66 66
   }
67 67
 
68 68
   function toHTML($escape = false) {
69
-    if($escape)
70
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
71
-    return "<?=" . $this->toPHP() . "?>";
69
+    if ($escape)
70
+      return "<?=htmlspecialchars(".$this->toPHP().")?>";
71
+    return "<?=".$this->toPHP()."?>";
72 72
   }
73 73
 
74 74
   function toPHPpre() {
75 75
     $pre = '';
76
-    if($this->chained)
76
+    if ($this->chained)
77 77
       $pre = $this->chained->toPHPpre();
78 78
     return "$pre{$this->filter}(";
79 79
   }
80 80
 
81 81
   function toPHPpost() {
82 82
     $post = '';
83
-    if($this->chained)
83
+    if ($this->chained)
84 84
       $post = $this->chained->toPHPpost();
85 85
     $o = '';
86
-    foreach($this->vars as $v)
86
+    foreach ($this->vars as $v)
87 87
       $o .= ','.$this->varToCode($v);
88 88
     return "$o)$post";
89 89
   }
@@ -98,19 +98,19 @@  discard block
 block discarded – undo
98 98
 
99 99
   static function itersplit($v, $sep = ",") {
100 100
     $o = [];
101
-    foreach(explode($sep, $v) as $k=>$i) {
102
-      if($i)
103
-        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
101
+    foreach (explode($sep, $v) as $k=>$i) {
102
+      if ($i)
103
+        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k];
104 104
     }
105 105
     return new WrapArray($o);
106 106
   }
107 107
 
108 108
   static function newlinebr($v) {
109
-    return str_replace("\n","<br />\n",$v);
109
+    return str_replace("\n", "<br />\n", $v);
110 110
   }
111 111
 
112 112
   static function replace($v, $src, $dst) {
113
-    return str_replace($src,$dst,$v);
113
+    return str_replace($src, $dst, $v);
114 114
   }
115 115
 
116 116
 }
117 117
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -44,8 +44,9 @@  discard block
 block discarded – undo
44 44
     if(preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) {
45 45
       $this->filter = $m[1];
46 46
       $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : [];
47
-      foreach($this->vars as $k=>$v)
48
-        $this->vars[$k] = str_replace("&comma;",',',$v);
47
+      foreach($this->vars as $k=>$v) {
48
+              $this->vars[$k] = str_replace("&comma;",',',$v);
49
+      }
49 50
       if(isset($m['chained']) && strlen($m['chained'])) {
50 51
         $this->chained = new Filter($m['chained'],$what);
51 52
       }
@@ -60,31 +61,36 @@  discard block
 block discarded – undo
60 61
         $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}";
61 62
     }
62 63
     $mapFilter = ['json'=>'json_encode'];
63
-    if(isset($mapFilter[$this->filter]))
64
-      $this->filter = $mapFilter[$this->filter];
64
+    if(isset($mapFilter[$this->filter])) {
65
+          $this->filter = $mapFilter[$this->filter];
66
+    }
65 67
     $this->what = $what;
66 68
   }
67 69
 
68 70
   function toHTML($escape = false) {
69
-    if($escape)
70
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
71
+    if($escape) {
72
+          return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
73
+    }
71 74
     return "<?=" . $this->toPHP() . "?>";
72 75
   }
73 76
 
74 77
   function toPHPpre() {
75 78
     $pre = '';
76
-    if($this->chained)
77
-      $pre = $this->chained->toPHPpre();
79
+    if($this->chained) {
80
+          $pre = $this->chained->toPHPpre();
81
+    }
78 82
     return "$pre{$this->filter}(";
79 83
   }
80 84
 
81 85
   function toPHPpost() {
82 86
     $post = '';
83
-    if($this->chained)
84
-      $post = $this->chained->toPHPpost();
87
+    if($this->chained) {
88
+          $post = $this->chained->toPHPpost();
89
+    }
85 90
     $o = '';
86
-    foreach($this->vars as $v)
87
-      $o .= ','.$this->varToCode($v);
91
+    foreach($this->vars as $v) {
92
+          $o .= ','.$this->varToCode($v);
93
+    }
88 94
     return "$o)$post";
89 95
   }
90 96
 
@@ -99,8 +105,9 @@  discard block
 block discarded – undo
99 105
   static function itersplit($v, $sep = ",") {
100 106
     $o = [];
101 107
     foreach(explode($sep, $v) as $k=>$i) {
102
-      if($i)
103
-        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
108
+      if($i) {
109
+              $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
110
+      }
104 111
     }
105 112
     return new WrapArray($o);
106 113
   }
Please login to merge, or discard this patch.