Completed
Push — master ( 063e7f...e25cba )
by Chris
02:38
created
php/hamle/Model/WrapArray.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,8 +35,9 @@
 block discarded – undo
35 35
   }
36 36
 
37 37
   function hamleGet($key) {
38
-    if (!isset($this->data[$this->pos][$key]))
39
-      return "Missing Key [$key]";
38
+    if (!isset($this->data[$this->pos][$key])) {
39
+          return "Missing Key [$key]";
40
+    }
40 41
     return $this->data[$this->pos][$key];
41 42
   }
42 43
 
Please login to merge, or discard this patch.
php/hamle/Hamle.php 1 patch
Braces   +47 added lines, -29 removed lines patch added patch discarded remove patch
@@ -81,13 +81,16 @@  discard block
 block discarded – undo
81 81
    */
82 82
   function __construct($baseModel, $setup = NULL) {
83 83
     self::$me = $this;
84
-    if(!$setup)
85
-      $setup = new Setup();
84
+    if(!$setup) {
85
+          $setup = new Setup();
86
+    }
86 87
     $this->parse = new Parse();
87
-    if(!$setup instanceOf Setup)
88
-      throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup");
89
-    if(!$baseModel instanceOf Model)
90
-      throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel");
88
+    if(!$setup instanceOf Setup) {
89
+          throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup");
90
+    }
91
+    if(!$baseModel instanceOf Model) {
92
+          throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel");
93
+    }
91 94
     $this->setup = $setup;
92 95
     $this->baseModel = $baseModel;
93 96
     $this->initSnipFiles();
@@ -97,7 +100,9 @@  discard block
 block discarded – undo
97 100
     if($this->snipMod == 0) {
98 101
       $this->snipFiles = $this->setup->snippetFiles();
99 102
       foreach($this->snipFiles as $f) {
100
-        if (!file_exists($f)) throw new Exception\NotFound("Unable to find Snippet File ($f)");
103
+        if (!file_exists($f)) {
104
+          throw new Exception\NotFound("Unable to find Snippet File ($f)");
105
+        }
101 106
         $this->snipFiles = max($this->snipFiles, filemtime($f));
102 107
       }
103 108
     }
@@ -111,8 +116,9 @@  discard block
 block discarded – undo
111 116
    */
112 117
   function load($hamleFile, \Closure $parseFunc = null) {
113 118
     $template = $this->setup->templatePath($hamleFile);
114
-      if(!file_exists($template)) 
115
-        throw new Exception\NotFound("Unable to find HAMLE Template ($template)");
119
+      if(!file_exists($template)) {
120
+              throw new Exception\NotFound("Unable to find HAMLE Template ($template)");
121
+      }
116 122
     $this->cacheFile = $this->setup->cachePath(
117 123
                   str_replace("/","-",$hamleFile).".php");
118 124
     $this->setup->debugLog("Set cache file path to ({$this->cacheFile})");
@@ -122,8 +128,9 @@  discard block
 block discarded – undo
122 128
     if($cacheDirty) {
123 129
       $this->setup->debugLog("Parsing File ($template to {$this->cacheFile})");
124 130
       $this->parse($parseFunc?"":file_get_contents($template), $parseFunc);
125
-    } else
126
-      $this->setup->debugLog("Using Cached file ({$this->cacheFile})");
131
+    } else {
132
+          $this->setup->debugLog("Using Cached file ({$this->cacheFile})");
133
+    }
127 134
     return $this;
128 135
   }
129 136
   /**
@@ -135,24 +142,29 @@  discard block
 block discarded – undo
135 142
    * @throws Exception\ParseError if unable to write to the cache file
136 143
    */
137 144
   function parse($hamleCode, \Closure $parseFunc = null) {
138
-    if(!$this->cacheFile)
139
-        $this->cacheFile = $this->setup->cachePath("string.hamle.php");
140
-    if($parseFunc)
141
-      $parseFunc($this->parse);
142
-    else
143
-      $this->parse->str($hamleCode);
145
+    if(!$this->cacheFile) {
146
+            $this->cacheFile = $this->setup->cachePath("string.hamle.php");
147
+    }
148
+    if($parseFunc) {
149
+          $parseFunc($this->parse);
150
+    } else {
151
+          $this->parse->str($hamleCode);
152
+    }
144 153
     $this->setup->debugLog("Loading Snippet Files");
145
-    foreach($this->snipFiles as $snip)
146
-      $this->parse->parseSnip(file_get_contents($snip));
154
+    foreach($this->snipFiles as $snip) {
155
+          $this->parse->parseSnip(file_get_contents($snip));
156
+    }
147 157
     $this->setup->debugLog("Applying Snippet Files");
148 158
     $this->parse->applySnip();
149 159
     $this->setup->debugLog("Executing Parse Filters");
150
-    foreach($this->setup->getFilters() as $filter)
151
-      $this->parse->parseFilter($filter);
160
+    foreach($this->setup->getFilters() as $filter) {
161
+          $this->parse->parseFilter($filter);
162
+    }
152 163
     $this->setup->debugLog("Updating Cache File ({$this->cacheFile})");
153
-    if(FALSE === file_put_contents($this->cacheFile, $this->parse->output()))
154
-      throw new Exception\ParseError(
164
+    if(FALSE === file_put_contents($this->cacheFile, $this->parse->output())) {
165
+          throw new Exception\ParseError(
155 166
                       "Unable to write to cache file ({$this->cacheFile})");
167
+    }
156 168
   }
157 169
 
158 170
   /**
@@ -163,8 +175,9 @@  discard block
 block discarded – undo
163 175
     $md5 = md5($hamleString);
164 176
     $stringId = substr($md5,0,12).substr($md5,24,8);
165 177
     $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php");
166
-    if(!is_file($this->cacheFile))
167
-      $this->parse($hamleString);
178
+    if(!is_file($this->cacheFile)) {
179
+          $this->parse($hamleString);
180
+    }
168 181
   }
169 182
 
170 183
   /**
@@ -179,9 +192,13 @@  discard block
 block discarded – undo
179 192
       $baseModel = $this->baseModel;
180 193
       $this->baseModel = null;
181 194
       $currentModel = $baseModel == Scope::getTopScope();
182
-      if(!$currentModel && $baseModel) Scope::add($baseModel);
195
+      if(!$currentModel && $baseModel) {
196
+        Scope::add($baseModel);
197
+      }
183 198
       require $this->cacheFile;
184
-      if(!$currentModel && $baseModel) Scope::done();
199
+      if(!$currentModel && $baseModel) {
200
+        Scope::done();
201
+      }
185 202
       $this->baseModel = $baseModel;
186 203
       $out = ob_get_contents();
187 204
       ob_end_clean();
@@ -198,8 +215,9 @@  discard block
 block discarded – undo
198 215
    * @return int The line number being passed by the parser
199 216
    */
200 217
   static function getLineNo() {
201
-    if(!isset(self::$me))
202
-      return 0;
218
+    if(!isset(self::$me)) {
219
+          return 0;
220
+    }
203 221
     return self::$me->parse->getLineNo();
204 222
   }
205 223
 
Please login to merge, or discard this patch.
php/hamle/Tag/Control.php 1 patch
Braces   +22 added lines, -16 removed lines patch added patch discarded remove patch
@@ -73,14 +73,16 @@  discard block
 block discarded – undo
73 73
       $scopeName = $m[1];
74 74
       $lookup = substr($this->var, 0, strlen($this->var) - strlen($m[0]));
75 75
       $hsv = new H\Text(trim($lookup), H\Text::TOKEN_CONTROL);
76
-    } else
77
-      $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL);
76
+    } else {
77
+          $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL);
78
+    }
78 79
     switch ($this->type) {
79 80
       case "each":
80
-        if ($this->var)
81
-          $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n";
82
-        else
83
-          $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n";
81
+        if ($this->var) {
82
+                  $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n";
83
+        } else {
84
+                  $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n";
85
+        }
84 86
         $out .= "Hamle\\Scope::add({$this->o}); ";
85 87
         break;
86 88
       case "if":
@@ -88,9 +90,9 @@  discard block
 block discarded – undo
88 90
         $out .= "if(" . $hsvcomp->toPHP() . ") {";
89 91
         break;
90 92
       case "with":
91
-        if ($scopeName)
92
-          $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;";
93
-        else {
93
+        if ($scopeName) {
94
+                  $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;";
95
+        } else {
94 96
           $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " .
95 97
               "{$this->o}->valid()) {\n";
96 98
           $out .= "Hamle\\Scope::add({$this->o});\n;";
@@ -101,10 +103,11 @@  discard block
 block discarded – undo
101 103
         break;
102 104
       case "include":
103 105
         $file = $hsv->toHTML();
104
-        if($file[0] == "#")
105
-          $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");";
106
-        else
107
-          $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");";
106
+        if($file[0] == "#") {
107
+                  $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");";
108
+        } else {
109
+                  $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");";
110
+        }
108 111
         break;
109 112
     }
110 113
     return $out . ' ?>';
@@ -123,8 +126,9 @@  discard block
 block discarded – undo
123 126
       case "each";
124 127
         $out .= 'Hamle\\Scope::done(); ';
125 128
         $out .= '}';
126
-        if (!$this->var)
127
-          $out .= "Hamle\\Scope::get()->rewind();\n";
129
+        if (!$this->var) {
130
+                  $out .= "Hamle\\Scope::get()->rewind();\n";
131
+        }
128 132
         break;
129 133
       case "if":
130 134
       case "else":
@@ -140,7 +144,9 @@  discard block
 block discarded – undo
140 144
         return "";
141 145
         break;
142 146
     }
143
-    if ($this->else) $out .= "else{";
147
+    if ($this->else) {
148
+      $out .= "else{";
149
+    }
144 150
     return $out . ' ?>';
145 151
   }
146 152
 
Please login to merge, or discard this patch.
php/hamle/Text/Func.php 1 patch
Braces   +38 added lines, -23 removed lines patch added patch discarded remove patch
@@ -43,10 +43,12 @@  discard block
 block discarded – undo
43 43
    */
44 44
   function __construct($s) {
45 45
     $m = array();
46
-    if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m))
47
-      throw new ParseError("Unable to read \$ func in '$s'");
48
-    if (trim($m[2]))
49
-      $this->sub = new FuncSub($m[2]);
46
+    if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) {
47
+          throw new ParseError("Unable to read \$ func in '$s'");
48
+    }
49
+    if (trim($m[2])) {
50
+          $this->sub = new FuncSub($m[2]);
51
+    }
50 52
     if (!trim($m[1])) {
51 53
       $this->scope = true;
52 54
       return;
@@ -63,17 +65,24 @@  discard block
 block discarded – undo
63 65
     $m = array();
64 66
     $att = array('id' => array(), 'tag' => array());
65 67
     foreach (explode(",", $s) as $str) {
66
-      if (preg_match('/^[a-zA-Z0-9\\_]+/', $str, $m)) $type = $m[0];
67
-      else $type = "*";
68
-      if (preg_match('/#([a-zA-Z0-9\_\\${}]+)/', $str, $m)) $att['id'][$type][] = $m[1];
69
-      elseif (preg_match_all('/\\.([a-zA-Z0-9\_\-\\${}]+)/', $str, $m))
70
-        foreach ($m[1] as $tag)
68
+      if (preg_match('/^[a-zA-Z0-9\\_]+/', $str, $m)) {
69
+        $type = $m[0];
70
+      } else {
71
+        $type = "*";
72
+      }
73
+      if (preg_match('/#([a-zA-Z0-9\_\\${}]+)/', $str, $m)) {
74
+        $att['id'][$type][] = $m[1];
75
+      } elseif (preg_match_all('/\\.([a-zA-Z0-9\_\-\\${}]+)/', $str, $m)) {
76
+              foreach ($m[1] as $tag)
71 77
           $att['tag'][$type][] = new Text($tag, Text::TOKEN_CODE);
72
-      else $att['tag'][$type] = array();
78
+      } else {
79
+        $att['tag'][$type] = array();
80
+      }
73 81
     }
74 82
     //var_dump($att);
75
-    if (!(count($att['id']) xor count($att['tag'])))
76
-      throw new ParseError("Only tag, type or id can be combined");
83
+    if (!(count($att['id']) xor count($att['tag']))) {
84
+          throw new ParseError("Only tag, type or id can be combined");
85
+    }
77 86
     return $att;
78 87
   }
79 88
 
@@ -86,14 +95,18 @@  discard block
 block discarded – undo
86 95
     }
87 96
     $rand = false;
88 97
     if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) {
89
-      foreach($m[0] as $k=>$mv)
90
-        if ($m[2][$k]) {
98
+      foreach($m[0] as $k=>$mv) {
99
+              if ($m[2][$k]) {
91 100
           $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING;
101
+      }
92 102
           $att['sort'][$m[2][$k]] = $dir;
93
-        } else $rand = true;
103
+        } else {
104
+          $rand = true;
105
+        }
106
+    }
107
+    if($rand) {
108
+          $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM];
94 109
     }
95
-    if($rand)
96
-      $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM];
97 110
     return $att;
98 111
   }
99 112
 
@@ -118,17 +131,19 @@  discard block
 block discarded – undo
118 131
     }
119 132
     $limit = Text::varToCode($this->sortlimit['sort']) . "," .
120 133
         $this->sortlimit['limit'] . "," . $this->sortlimit['offset'];
121
-    if (count($this->filt['tag']))
122
-      return "Hamle\\Run::modelTypeTags(" .
134
+    if (count($this->filt['tag'])) {
135
+          return "Hamle\\Run::modelTypeTags(" .
123 136
       Text::varToCode($this->filt['tag']) . ",$limit)$sub";
124
-    if (count($this->filt['id']))
125
-      if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1)
137
+    }
138
+    if (count($this->filt['id'])) {
139
+          if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1)
126 140
         return "Hamle\\Run::modelId(" .
127 141
         Text::varToCode(current($this->filt['id']['*'])) .
128 142
         ",$limit)$sub";
129
-      else
130
-        return "Hamle\\Run::modelTypeId(" .
143
+    } else {
144
+              return "Hamle\\Run::modelTypeId(" .
131 145
         Text::varToCode($this->filt['id']) . ",$limit)$sub";
146
+      }
132 147
     return "";
133 148
   }
134 149
 
Please login to merge, or discard this patch.
php/hamle/Text/Filter.php 1 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(",",',',$v);
44
+      foreach($this->vars as $k=>$v) {
45
+              $this->vars[$k] = str_replace(",",',',$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.
php/hamle/Scope.php 1 patch
Braces   +23 added lines, -14 removed lines patch added patch discarded remove patch
@@ -18,12 +18,14 @@  discard block
 block discarded – undo
18 18
   static $namedScopes = array();
19 19
 
20 20
   static function add($model, $name = null) {
21
-    if (!$model instanceOf Model)
22
-      throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface");
23
-    if ($name)
24
-      self::$namedScopes[$name] = $model;
25
-    else
26
-      self::$scopes[] = $model;
21
+    if (!$model instanceOf Model) {
22
+          throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface");
23
+    }
24
+    if ($name) {
25
+          self::$namedScopes[$name] = $model;
26
+    } else {
27
+          self::$scopes[] = $model;
28
+    }
27 29
   }
28 30
 
29 31
   static function done() {
@@ -41,15 +43,21 @@  discard block
 block discarded – undo
41 43
    */
42 44
   static function get($id = 0) {
43 45
     if (0 == $id) {
44
-      if ($scope = end(self::$scopes))
45
-        return $scope;
46
+      if ($scope = end(self::$scopes)) {
47
+              return $scope;
48
+      }
46 49
       throw new OutOfScope("Unable to find Scope ($id)");
47 50
     }
48 51
     $key = $id - 1;
49
-    if ($id < 0) $key = count(self::$scopes) + $id - 1;
50
-    if ($id == 0) $key = count(self::$scopes) - 1;
51
-    if (!isset(self::$scopes[$key]))
52
-      throw new OutOfScope("Unable to find Scope ($id) or $key");
52
+    if ($id < 0) {
53
+      $key = count(self::$scopes) + $id - 1;
54
+    }
55
+    if ($id == 0) {
56
+      $key = count(self::$scopes) - 1;
57
+    }
58
+    if (!isset(self::$scopes[$key])) {
59
+          throw new OutOfScope("Unable to find Scope ($id) or $key");
60
+    }
53 61
     return self::$scopes[$key];
54 62
   }
55 63
 
@@ -67,8 +75,9 @@  discard block
 block discarded – undo
67 75
       self::$namedScopes[$name]->rewind();
68 76
       return self::$namedScopes[$name];
69 77
     } else
70
-      if(self::$returnZeroOnNoScope)
71
-        return new Model\Zero();
78
+      if(self::$returnZeroOnNoScope) {
79
+              return new Model\Zero();
80
+      }
72 81
       throw new RunTime("Unable to find scope ($name)");
73 82
   }
74 83
 
Please login to merge, or discard this patch.
php/hamle/Text/FuncSub.php 1 patch
Braces   +16 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,17 +38,25 @@
 block discarded – undo
38 38
    */
39 39
   function __construct($s) {
40 40
     $m = array();
41
-    if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m))
42
-      throw new ParseError("Unable to read \$ sub func in '$s'");
43
-    if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT;
44
-    elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD;
45
-    else $this->dir = Hamle\Hamle::REL_ANY;
41
+    if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) {
42
+          throw new ParseError("Unable to read \$ sub func in '$s'");
43
+    }
44
+    if ($m[1] == "<") {
45
+      $this->dir = Hamle\Hamle::REL_PARENT;
46
+    } elseif ($m[1] == ">") {
47
+      $this->dir = Hamle\Hamle::REL_CHILD;
48
+    } else {
49
+      $this->dir = Hamle\Hamle::REL_ANY;
50
+    }
46 51
     $this->sortlimit = $this->attSortLimit($m[2]);
47 52
     $this->filt = $this->attIdTag($m[2]);
48 53
     $this->grouptype = $this->attGroupType($m[2]);
49
-    if ($this->filt['id']) throw new ParseError("Unable to select by id");
50
-    if (trim($m[3]))
51
-      $this->sub = new FuncSub($m[3]);
54
+    if ($this->filt['id']) {
55
+      throw new ParseError("Unable to select by id");
56
+    }
57
+    if (trim($m[3])) {
58
+          $this->sub = new FuncSub($m[3]);
59
+    }
52 60
   }
53 61
 
54 62
   /**
Please login to merge, or discard this patch.
php/hamle/Parse.php 1 patch
Braces   +61 added lines, -41 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
-          array_unshift($revSnip, $snip);
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)
124
-        $snip->apply($root);
125
-    foreach ($revSnip as $snip)
126
-      foreach ($roots as $root)
127
-        $snip->apply($root);
123
+    foreach ($fwdSnip as $snip) {
124
+          foreach ($roots as $root)
125
+        $snip->apply($root);
126
+    }
127
+    foreach ($revSnip as $snip) {
128
+          foreach ($roots as $root)
129
+        $snip->apply($root);
130
+    }
128 131
     $this->root = $roots;
129 132
   }
130 133
 
@@ -144,9 +147,11 @@  discard block
 block discarded – undo
144 147
     $heir = array();
145 148
     while ($this->lineNo < $this->lineCount) {
146 149
       $line = $this->lines[$this->lineNo];
147
-      if (trim($line)) if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) {
150
+      if (trim($line)) {
151
+        if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) {
148 152
         if (FALSE !== strpos($m[1], "\t"))
149
-          throw new ParseError("Tabs are not supported in templates at this time");
153
+          throw new ParseError("Tabs are not supported in templates at this time");
154
+      }
150 155
         $indent = strlen($m[1]);
151 156
         $tag = isset($m[2]) ? $tag = $m[2] : "";
152 157
         $classid = isset($m[3]) ? $m[3] : "";
@@ -158,13 +163,13 @@  discard block
 block discarded – undo
158 163
         unset($m[0]);
159 164
         switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) {
160 165
           case "|": //Control Tag
161
-            if ($code == "|snippet")
162
-              $hTag = new Tag\Snippet($text);
163
-            elseif ($code == "|form")
164
-              $hTag = new Tag\Form($text);
165
-            elseif ($code == "|formhint")
166
-              $hTag = new Tag\FormHint($text);
167
-            elseif ($code == "|else") {
166
+            if ($code == "|snippet") {
167
+                          $hTag = new Tag\Snippet($text);
168
+            } elseif ($code == "|form") {
169
+                          $hTag = new Tag\Form($text);
170
+            } elseif ($code == "|formhint") {
171
+                          $hTag = new Tag\FormHint($text);
172
+            } elseif ($code == "|else") {
168 173
               $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]);
169 174
               $hTag->setVar($text);
170 175
             } else {
@@ -175,8 +180,9 @@  discard block
 block discarded – undo
175 180
           case ":": //Filter Tag
176 181
             $hTag = new Tag\Filter(substr($code, 1));
177 182
             $hTag->addContent($text, Text::TOKEN_CODE);
178
-            foreach ($this->consumeBlock($indent) as $l)
179
-              $hTag->addContent($l, Text::TOKEN_CODE);
183
+            foreach ($this->consumeBlock($indent) as $l) {
184
+                          $hTag->addContent($l, Text::TOKEN_CODE);
185
+            }
180 186
             break;
181 187
           case "_": //String Tag
182 188
           case "__": //Unescape String Tag
@@ -187,8 +193,9 @@  discard block
 block discarded – undo
187 193
           case "//": // Non Printed Comment
188 194
             $hTag = new Tag\Comment($textcode);
189 195
             $hTag->addContent($text);
190
-            foreach ($this->consumeBlock($indent) as $l)
191
-              $hTag->addContent($l, Text::TOKEN_CODE);
196
+            foreach ($this->consumeBlock($indent) as $l) {
197
+                          $hTag->addContent($l, Text::TOKEN_CODE);
198
+            }
192 199
             break;
193 200
           default:
194 201
             $attr = array();
@@ -201,25 +208,34 @@  discard block
 block discarded – undo
201 208
             }
202 209
             $class = array(); $id = ""; $ref = "";
203 210
             preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid);
204
-            if (isset($cid[0])) foreach ($cid[0] as $s) {
205
-              if ($s[0] == "#") $id = substr($s, 1);
206
-              if ($s[0] == ".") $class[] = substr($s, 1);
207
-              if ($s[0] == "!") $ref = substr($s, 1);
211
+            if (isset($cid[0])) {
212
+              foreach ($cid[0] as $s) {
213
+              if ($s[0] == "#") $id = substr($s, 1);
214
+            }
215
+              if ($s[0] == ".") {
216
+                $class[] = substr($s, 1);
217
+              }
218
+              if ($s[0] == "!") {
219
+                $ref = substr($s, 1);
220
+              }
208 221
             }
209
-            if($ref)
210
-              $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
211
-            else
212
-              $hTag = new Tag\Html($tag, $class, $attr, $id);
222
+            if($ref) {
223
+                          $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
224
+            } else {
225
+                          $hTag = new Tag\Html($tag, $class, $attr, $id);
226
+            }
213 227
             $hTag->addContent($text);
214 228
             break;
215 229
         }
216 230
         $heir[$i] = $hTag;
217
-        if ($i > 0)
218
-          $heir[$i - 1]->addChild($hTag);
219
-        else
220
-          $this->root[] = $hTag;
221
-      } else
222
-        throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error());
231
+        if ($i > 0) {
232
+                  $heir[$i - 1]->addChild($hTag);
233
+        } else {
234
+                  $this->root[] = $hTag;
235
+        }
236
+      } else {
237
+              throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error());
238
+      }
223 239
       $this->lineNo++;
224 240
     }
225 241
   }
@@ -235,8 +251,9 @@  discard block
 block discarded – undo
235 251
 
236 252
   function output() {
237 253
     $out = "<?php\nuse Seufert\\Hamle;\n?>";
238
-    foreach ($this->root as $tag)
239
-      $out .= $tag->render();
254
+    foreach ($this->root as $tag) {
255
+          $out .= $tag->render();
256
+    }
240 257
     return $out;
241 258
 
242 259
   }
@@ -248,15 +265,18 @@  discard block
 block discarded – undo
248 265
         (!trim($this->lines[$this->lineNo + 1]) ||
249 266
             preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/',
250 267
                 $this->lines[$this->lineNo + 1], $m))) {
251
-      if (trim($this->lines[$this->lineNo + 1]))
252
-        $out[] = $m[2];
268
+      if (trim($this->lines[$this->lineNo + 1])) {
269
+              $out[] = $m[2];
270
+      }
253 271
       $this->lineNo++;
254 272
     }
255 273
     return $out;
256 274
   }
257 275
 
258 276
   function indentLevel($indent) {
259
-    if (!isset($this->indents)) $this->indents = array();
277
+    if (!isset($this->indents)) {
278
+      $this->indents = array();
279
+    }
260 280
     if (!count($this->indents)) {
261 281
       $this->indents = array(0 => $indent);
262 282
       // Key = indent level, Value = Depth in spaces
Please login to merge, or discard this patch.
php/hamle/Text/SimpleVar.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,8 +43,9 @@  discard block
 block discarded – undo
43 43
   }
44 44
 
45 45
   function toHTML($escape = false) {
46
-    if($escape)
47
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
46
+    if($escape) {
47
+          return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
48
+    }
48 49
     return "<?=" . $this->toPHP() . "?>";
49 50
   }
50 51
 
@@ -62,8 +63,9 @@  discard block
 block discarded – undo
62 63
    */
63 64
   function setValue($value) {
64 65
     $model = \Seufert\Hamle\Scope::get();
65
-    if(!$model instanceof WriteModel)
66
-      throw new \RuntimeException('Can only write to model that implements WriteModel');
66
+    if(!$model instanceof WriteModel) {
67
+          throw new \RuntimeException('Can only write to model that implements WriteModel');
68
+    }
67 69
     $model->hamleSet($this->var, $value);
68 70
     return $model;
69 71
   }
Please login to merge, or discard this patch.