Passed
Push — master ( 945f9e...7020fc )
by Chris
02:58
created
php/hamle/Parse.php 1 patch
Braces   +56 added lines, -36 removed lines patch added patch discarded remove patch
@@ -109,22 +109,25 @@  discard block
 block discarded – undo
109 109
     $revSnip = array();
110 110
     /** @var Tag[] $roots */
111 111
     $roots = array();
112
-    foreach ($this->root as $snip)
113
-      if ($snip instanceOf Tag\Snippet) {
112
+    foreach ($this->root as $snip) {
113
+          if ($snip instanceOf Tag\Snippet) {
114 114
         if ($snip->getType() == "append") {
115 115
           array_unshift($revSnip, $snip);
116
+    }
116 117
         } else {
117 118
           $fwdSnip[] = $snip;
118 119
         }
119 120
       } else {
120 121
         $roots[] = $snip;
121 122
       }
122
-    foreach ($fwdSnip as $snip)
123
-      foreach ($roots as $root)
123
+    foreach ($fwdSnip as $snip) {
124
+          foreach ($roots as $root)
124 125
         $snip->apply($root);
125
-    foreach ($revSnip as $snip)
126
-      foreach ($roots as $root)
126
+    }
127
+    foreach ($revSnip as $snip) {
128
+          foreach ($roots as $root)
127 129
         $snip->apply($root);
130
+    }
128 131
     $this->root = $roots;
129 132
   }
130 133
 
@@ -143,9 +146,11 @@  discard block
 block discarded – undo
143 146
     $heir = array();
144 147
     while ($this->lineNo < $this->lineCount) {
145 148
       $line = $this->lines[$this->lineNo];
146
-      if (trim($line)) if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) {
149
+      if (trim($line)) {
150
+        if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) {
147 151
         if (FALSE !== strpos($m[1], "\t"))
148 152
           throw new ParseError("Tabs are not supported in templates at this time");
153
+      }
149 154
         $indent = strlen($m[1]);
150 155
         $tag = isset($m[2]) ? $tag = $m[2] : "";
151 156
         $classid = isset($m[3]) ? $m[3] : "";
@@ -157,13 +162,13 @@  discard block
 block discarded – undo
157 162
         unset($m[0]);
158 163
         switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) {
159 164
           case "|": //Control Tag
160
-            if ($code == "|snippet")
161
-              $hTag = new Tag\Snippet($text);
162
-            elseif ($code == "|form")
163
-              $hTag = new Tag\Form($text);
164
-            elseif ($code == "|formhint")
165
-              $hTag = new Tag\FormHint();
166
-            elseif ($code == "|else") {
165
+            if ($code == "|snippet") {
166
+                          $hTag = new Tag\Snippet($text);
167
+            } elseif ($code == "|form") {
168
+                          $hTag = new Tag\Form($text);
169
+            } elseif ($code == "|formhint") {
170
+                          $hTag = new Tag\FormHint();
171
+            } elseif ($code == "|else") {
167 172
               $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]);
168 173
               $hTag->setVar($text);
169 174
             } else {
@@ -174,8 +179,9 @@  discard block
 block discarded – undo
174 179
           case ":": //Filter Tag
175 180
             $hTag = new Tag\Filter(substr($code, 1));
176 181
             $hTag->addContent($text, Text::TOKEN_CODE);
177
-            foreach ($this->consumeBlock($indent) as $l)
178
-              $hTag->addContent($l, Text::TOKEN_CODE);
182
+            foreach ($this->consumeBlock($indent) as $l) {
183
+                          $hTag->addContent($l, Text::TOKEN_CODE);
184
+            }
179 185
             break;
180 186
           case "_": //String Tag
181 187
           case "__": //Unescape String Tag
@@ -191,8 +197,9 @@  discard block
 block discarded – undo
191 197
           case "//": // Non Printed Comment
192 198
             $hTag = new Tag\Comment($textcode);
193 199
             $hTag->addContent($text);
194
-            foreach ($this->consumeBlock($indent) as $l)
195
-              $hTag->addContent($l, Text::TOKEN_CODE);
200
+            foreach ($this->consumeBlock($indent) as $l) {
201
+                          $hTag->addContent($l, Text::TOKEN_CODE);
202
+            }
196 203
             break;
197 204
           default:
198 205
             $attr = array();
@@ -204,25 +211,34 @@  discard block
 block discarded – undo
204 211
             }
205 212
             $class = array(); $id = ""; $ref = "";
206 213
             preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid);
207
-            if (isset($cid[0])) foreach ($cid[0] as $s) {
214
+            if (isset($cid[0])) {
215
+              foreach ($cid[0] as $s) {
208 216
               if ($s[0] == "#") $id = substr($s, 1);
209
-              if ($s[0] == ".") $class[] = substr($s, 1);
210
-              if ($s[0] == "!") $ref = substr($s, 1);
211 217
             }
212
-            if($ref)
213
-              $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
214
-            else
215
-              $hTag = new Tag\Html($tag, $class, $attr, $id);
218
+              if ($s[0] == ".") {
219
+                $class[] = substr($s, 1);
220
+              }
221
+              if ($s[0] == "!") {
222
+                $ref = substr($s, 1);
223
+              }
224
+            }
225
+            if($ref) {
226
+                          $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
227
+            } else {
228
+                          $hTag = new Tag\Html($tag, $class, $attr, $id);
229
+            }
216 230
             $hTag->addContent($text);
217 231
             break;
218 232
         }
219 233
         $heir[$i] = $hTag;
220
-        if ($i > 0)
221
-          $heir[$i - 1]->addChild($hTag);
222
-        else
223
-          $this->root[] = $hTag;
224
-      } else
225
-        throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error());
234
+        if ($i > 0) {
235
+                  $heir[$i - 1]->addChild($hTag);
236
+        } else {
237
+                  $this->root[] = $hTag;
238
+        }
239
+      } else {
240
+              throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error());
241
+      }
226 242
       $this->lineNo++;
227 243
     }
228 244
   }
@@ -238,8 +254,9 @@  discard block
 block discarded – undo
238 254
 
239 255
   function output($minify = false) {
240 256
     $out = "<?php\nuse Seufert\\Hamle;\n?>";
241
-    foreach ($this->root as $tag)
242
-      $out .= $tag->render(0, $minify);
257
+    foreach ($this->root as $tag) {
258
+          $out .= $tag->render(0, $minify);
259
+    }
243 260
     return $out;
244 261
 
245 262
   }
@@ -251,15 +268,18 @@  discard block
 block discarded – undo
251 268
         (!trim($this->lines[$this->lineNo + 1]) ||
252 269
             preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/',
253 270
                 $this->lines[$this->lineNo + 1], $m))) {
254
-      if (trim($this->lines[$this->lineNo + 1]))
255
-        $out[] = $m[2];
271
+      if (trim($this->lines[$this->lineNo + 1])) {
272
+              $out[] = $m[2];
273
+      }
256 274
       $this->lineNo++;
257 275
     }
258 276
     return $out;
259 277
   }
260 278
 
261 279
   function indentLevel($indent) {
262
-    if (!isset($this->indents)) $this->indents = array();
280
+    if (!isset($this->indents)) {
281
+      $this->indents = array();
282
+    }
263 283
     if (!count($this->indents)) {
264 284
       $this->indents = array(0 => $indent);
265 285
       // Key = indent level, Value = Depth in spaces
Please login to merge, or discard this patch.
php/hamle/Text/Filter.php 1 patch
Braces   +18 added lines, -12 removed lines patch added patch discarded remove patch
@@ -49,8 +49,9 @@  discard block
 block discarded – undo
49 49
     if(preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) {
50 50
       $this->filter = $m[1];
51 51
       $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : [];
52
-      foreach($this->vars as $k=>$v)
53
-        $this->vars[$k] = str_replace("&comma;",',',$v);
52
+      foreach($this->vars as $k=>$v) {
53
+              $this->vars[$k] = str_replace("&comma;",',',$v);
54
+      }
54 55
       if(isset($m['chained']) && strlen($m['chained'])) {
55 56
         $this->chained = new Filter($m['chained'],$what);
56 57
       }
@@ -71,25 +72,29 @@  discard block
 block discarded – undo
71 72
   }
72 73
 
73 74
   function toHTML($escape = false) {
74
-    if($escape)
75
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
75
+    if($escape) {
76
+          return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
77
+    }
76 78
     return "<?=" . $this->toPHP() . "?>";
77 79
   }
78 80
 
79 81
   function toPHPpre() {
80 82
     $pre = '';
81
-    if($this->chained)
82
-      $pre = $this->chained->toPHPpre();
83
+    if($this->chained) {
84
+          $pre = $this->chained->toPHPpre();
85
+    }
83 86
     return "$pre{$this->filter}(";
84 87
   }
85 88
 
86 89
   function toPHPpost() {
87 90
     $post = '';
88
-    if($this->chained)
89
-      $post = $this->chained->toPHPpost();
91
+    if($this->chained) {
92
+          $post = $this->chained->toPHPpost();
93
+    }
90 94
     $o = '';
91
-    foreach($this->vars as $v)
92
-      $o .= ','.$this->varToCode($v);
95
+    foreach($this->vars as $v) {
96
+          $o .= ','.$this->varToCode($v);
97
+    }
93 98
     return "$o)$post";
94 99
   }
95 100
 
@@ -104,8 +109,9 @@  discard block
 block discarded – undo
104 109
   static function itersplit($v, $sep = ",") {
105 110
     $o = [];
106 111
     foreach(explode($sep, $v) as $k=>$i) {
107
-      if($i)
108
-        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
112
+      if($i) {
113
+              $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
114
+      }
109 115
     }
110 116
     return new WrapArray($o);
111 117
   }
Please login to merge, or discard this patch.