Completed
Push — master ( ea1817...bbd140 )
by Chris
03:35
created
php/hamle/Text/SimpleVar.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -33,22 +33,22 @@
 block discarded – undo
33 33
   protected $filter;
34 34
 
35 35
   function __construct($s) {
36
-    if(FALSE !== $pos = strpos($s,'|')) {
37
-      $this->var = substr($s,1,$pos-1);
38
-      $this->filter = new Filter(substr($s, $pos+1), $this);
36
+    if (FALSE !== $pos = strpos($s, '|')) {
37
+      $this->var = substr($s, 1, $pos - 1);
38
+      $this->filter = new Filter(substr($s, $pos + 1), $this);
39 39
     } else {
40 40
       $this->var = substr($s, 1);
41 41
     }
42 42
   }
43 43
 
44 44
   function toHTML($escape = false) {
45
-    if($escape)
46
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
45
+    if ($escape)
46
+      return "<?=htmlspecialchars(" . $this->toPHP() . ")?>";
47 47
     return "<?=" . $this->toPHP() . "?>";
48 48
   }
49 49
 
50 50
   function toPHP() {
51
-    return $this->filter?$this->filter->toPHP():$this->toPHPVar();
51
+    return $this->filter ? $this->filter->toPHP() : $this->toPHPVar();
52 52
   }
53 53
 
54 54
   function toPHPVar() {
Please login to merge, or discard this patch.
php/hamle/Text/Filter.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,28 +37,28 @@
 block discarded – undo
37 37
   protected $what;
38 38
 
39 39
   function __construct($s, Text $what) {
40
-    if(preg_match("/^([a-z]+)(\\((.*)\\))$/",$s, $m)) {
40
+    if (preg_match("/^([a-z]+)(\\((.*)\\))$/", $s, $m)) {
41 41
       $this->filter = $m[1];
42
-      $this->vars = isset($m[3])?explode(',',$m[3]):[];
42
+      $this->vars = isset($m[3]) ? explode(',', $m[3]) : [];
43 43
     } else {
44 44
       throw new ParseError("Unable to parse filter expression \"$s\"");
45 45
     }
46
-    if(!in_array($this->filter,['round','strtoupper','strtolower','ucfirst'])) {
46
+    if (!in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) {
47 47
       throw new ParseError("Unknown Filter Type \"{$this->filter}\"");
48 48
     }
49 49
     $this->what = $what;
50 50
   }
51 51
 
52 52
   function toHTML($escape = false) {
53
-    if($escape)
54
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
53
+    if ($escape)
54
+      return "<?=htmlspecialchars(" . $this->toPHP() . ")?>";
55 55
     return "<?=" . $this->toPHP() . "?>";
56 56
   }
57 57
 
58 58
   function toPHP() {
59
-    $o = [$this->what->toPHPVar()] ;
60
-    foreach($this->vars as $v)
59
+    $o = [$this->what->toPHPVar()];
60
+    foreach ($this->vars as $v)
61 61
       $o[] = $this->varToCode($v);
62
-    return "{$this->filter}(" . implode(',',$o) . ")";
62
+    return "{$this->filter}(" . implode(',', $o) . ")";
63 63
   }
64 64
 }
65 65
\ No newline at end of file
Please login to merge, or discard this patch.
php/hamle/Text/Comparison.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
 
36 36
   function __construct($s, $mode = self::TOKEN_CONTROL) {
37 37
     $m = array();
38
-    if(preg_match('/^(.*) '.self::REGEX_COMP_OPER.' (.*)$/', $s, $m)) {
39
-      $this->param1 = new Text($m[1],Text::TOKEN_HTML);
40
-      $this->param2 = new Text($m[3],Text::TOKEN_HTML);
38
+    if (preg_match('/^(.*) ' . self::REGEX_COMP_OPER . ' (.*)$/', $s, $m)) {
39
+      $this->param1 = new Text($m[1], Text::TOKEN_HTML);
40
+      $this->param2 = new Text($m[3], Text::TOKEN_HTML);
41 41
       $this->operator = $m[2];
42 42
     } else
43
-      $this->param1 = new Text($s,Text::TOKEN_HTML);
43
+      $this->param1 = new Text($s, Text::TOKEN_HTML);
44 44
   }
45 45
 
46 46
 //  function __construct(String $p1, String $p2, $operator) {
@@ -49,20 +49,20 @@  discard block
 block discarded – undo
49 49
 //    $this->operator = $operator;
50 50
 //  }
51 51
   function toPHP() {
52
-    if(!$this->param2) return $this->param1->toPHP();
52
+    if (!$this->param2) return $this->param1->toPHP();
53 53
     $p1 = $this->param1->toPHP();
54 54
     $p2 = $this->param2->toPHP();
55
-    switch($this->operator) {
55
+    switch ($this->operator) {
56 56
       case "equals":
57 57
       case "equal":
58
-        return $p1." == ".$p2;
58
+        return $p1 . " == " . $p2;
59 59
       case "notequals":
60 60
       case "notequal":
61
-        return $p1." != ".$p2;
61
+        return $p1 . " != " . $p2;
62 62
       case "less":
63
-        return $p1." < ".$p2;
63
+        return $p1 . " < " . $p2;
64 64
       case "greater":
65
-        return $p1." > ".$p2;
65
+        return $p1 . " > " . $p2;
66 66
       case "has":
67 67
         return "in_array($p2, $p1)";
68 68
       case "starts":
Please login to merge, or discard this patch.
php/hamle/Scope.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 
20 20
   static function add($model, $name = null) {
21 21
     if (!$model instanceOf Model)
22
-      throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface");
22
+      throw new Unsupported("Unsupported Model (" . get_class($model) . "), Needs to implement hamleModel Interface");
23 23
     if ($name)
24 24
       self::$namedScopes[$name] = $model;
25 25
     else
Please login to merge, or discard this patch.
php/hamle/Setup.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
    */
41 41
   public function cachePath($f) {
42 42
     $s = DIRECTORY_SEPARATOR;
43
-    $dir = implode($s,[__DIR__,"..","..","cache",""]);
44
-    if(!is_dir($dir)) mkdir($dir);
45
-    return $dir.$f;
43
+    $dir = implode($s, [__DIR__, "..", "..", "cache", ""]);
44
+    if (!is_dir($dir)) mkdir($dir);
45
+    return $dir . $f;
46 46
   }
47 47
 
48 48
   /**
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
    * @throws Exception\RunTime
68 68
    */
69 69
   public function getModelTypeID($typeId, $sort = [], $limit = 0, $offset = 0) {
70
-    if(count($typeId) > 1)
70
+    if (count($typeId) > 1)
71 71
       throw new Exception\RunTime("Unable to open more than one ID at a time");
72 72
     return new Model\Zero();
73 73
   }
Please login to merge, or discard this patch.
php/hamle/Hamle.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
 
64 64
   public $baseModel;
65 65
 
66
-  const REL_CHILD = 0x01;  /* Child Relation */
66
+  const REL_CHILD = 0x01; /* Child Relation */
67 67
   const REL_PARENT = 0x02; /* Parent Relation */
68
-  const REL_ANY = 0x03;    /* Unspecified or any relation */
68
+  const REL_ANY = 0x03; /* Unspecified or any relation */
69 69
   
70
-  const SORT_NATURAL = 0x00;    /* Sort in what ever order is 'default' */
71
-  const SORT_ASCENDING = 0x02;  /* Sort Ascending */
70
+  const SORT_NATURAL = 0x00; /* Sort in what ever order is 'default' */
71
+  const SORT_ASCENDING = 0x02; /* Sort Ascending */
72 72
   const SORT_DESCENDING = 0x03; /* Sort Decending */
73
-  const SORT_RANDOM = 0x04;     /* Sort Randomly */
73
+  const SORT_RANDOM = 0x04; /* Sort Randomly */
74 74
   /**
75 75
    * Create new HAMLE Parser
76 76
    * 
@@ -81,22 +81,22 @@  discard block
 block discarded – undo
81 81
    */
82 82
   function __construct($baseModel, $setup = NULL) {
83 83
     self::$me = $this;
84
-    if(!$setup)
84
+    if (!$setup)
85 85
       $setup = new Setup();
86 86
     $this->parse = new Parse();
87
-    if(!$setup instanceOf Setup)
87
+    if (!$setup instanceOf Setup)
88 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");
89
+    if (!$baseModel instanceOf Model)
90
+      throw new Exception\Unsupported("Unsupported Model(" . get_class($baseModel) . ") Type was passed, it must implement hamleModel");
91 91
     $this->setup = $setup;
92 92
     $this->baseModel = $baseModel;
93 93
     $this->initSnipFiles();
94 94
   }
95 95
 
96 96
   function initSnipFiles() {
97
-    if($this->snipMod == 0) {
97
+    if ($this->snipMod == 0) {
98 98
       $this->snipFiles = $this->setup->snippetFiles();
99
-      foreach($this->snipFiles as $f) {
99
+      foreach ($this->snipFiles as $f) {
100 100
         if (!file_exists($f)) throw new Exception\NotFound("Unable to find Snippet File ($f)");
101 101
         $this->snipFiles = max($this->snipFiles, filemtime($f));
102 102
       }
@@ -111,17 +111,17 @@  discard block
 block discarded – undo
111 111
    */
112 112
   function load($hamleFile, \Closure $parseFunc = null) {
113 113
     $template = $this->setup->templatePath($hamleFile);
114
-      if(!file_exists($template)) 
114
+      if (!file_exists($template)) 
115 115
         throw new Exception\NotFound("Unable to find HAMLE Template ($template)");
116 116
     $this->cacheFile = $this->setup->cachePath(
117
-                  str_replace("/","-",$hamleFile).".php");
117
+                  str_replace("/", "-", $hamleFile) . ".php");
118 118
     $this->setup->debugLog("Set cache file path to ({$this->cacheFile})");
119
-    $cacheFileAge = is_file($this->cacheFile)?filemtime($this->cacheFile):0;
119
+    $cacheFileAge = is_file($this->cacheFile) ? filemtime($this->cacheFile) : 0;
120 120
     $cacheDirty = !$this->cache ||
121 121
         $cacheFileAge < $this->snipMod || $cacheFileAge < filemtime($template);
122
-    if($cacheDirty) {
122
+    if ($cacheDirty) {
123 123
       $this->setup->debugLog("Parsing File ($template to {$this->cacheFile})");
124
-      $this->parse($parseFunc?"":file_get_contents($template), $parseFunc);
124
+      $this->parse($parseFunc ? "" : file_get_contents($template), $parseFunc);
125 125
     } else
126 126
       $this->setup->debugLog("Using Cached file ({$this->cacheFile})");
127 127
     return $this;
@@ -135,22 +135,22 @@  discard block
 block discarded – undo
135 135
    * @throws Exception\ParseError if unable to write to the cache file
136 136
    */
137 137
   function parse($hamleCode, \Closure $parseFunc = null) {
138
-    if(!$this->cacheFile)
138
+    if (!$this->cacheFile)
139 139
         $this->cacheFile = $this->setup->cachePath("string.hamle.php");
140
-    if($parseFunc)
140
+    if ($parseFunc)
141 141
       $parseFunc($this->parse);
142 142
     else
143 143
       $this->parse->str($hamleCode);
144 144
     $this->setup->debugLog("Loading Snippet Files");
145
-    foreach($this->snipFiles as $snip)
145
+    foreach ($this->snipFiles as $snip)
146 146
       $this->parse->parseSnip(file_get_contents($snip));
147 147
     $this->setup->debugLog("Applying Snippet Files");
148 148
     $this->parse->applySnip();
149 149
     $this->setup->debugLog("Executing Parse Filters");
150
-    foreach($this->setup->getFilters() as $filter)
150
+    foreach ($this->setup->getFilters() as $filter)
151 151
       $this->parse->parseFilter($filter);
152 152
     $this->setup->debugLog("Updating Cache File ({$this->cacheFile})");
153
-    if(FALSE === file_put_contents($this->cacheFile, $this->parse->output()))
153
+    if (FALSE === file_put_contents($this->cacheFile, $this->parse->output()))
154 154
       throw new Exception\ParseError(
155 155
                       "Unable to write to cache file ({$this->cacheFile})");
156 156
   }
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
    */
162 162
   function string($hamleString) {
163 163
     $md5 = md5($hamleString);
164
-    $stringId = substr($md5,0,12).substr($md5,24,8);
164
+    $stringId = substr($md5, 0, 12) . substr($md5, 24, 8);
165 165
     $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php");
166
-    if(!is_file($this->cacheFile))
166
+    if (!is_file($this->cacheFile))
167 167
       $this->parse($hamleString);
168 168
   }
169 169
 
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
       $baseModel = $this->baseModel;
180 180
       $this->baseModel = null;
181 181
       $currentModel = $baseModel == Scope::getTopScope();
182
-      if(!$currentModel && $baseModel) Scope::add($baseModel);
182
+      if (!$currentModel && $baseModel) Scope::add($baseModel);
183 183
       require $this->cacheFile;
184
-      if(!$currentModel && $baseModel) Scope::done();
184
+      if (!$currentModel && $baseModel) Scope::done();
185 185
       $this->baseModel = $baseModel;
186 186
       $out = ob_get_contents();
187 187
       ob_end_clean();
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
    * @return int The line number being passed by the parser
199 199
    */
200 200
   static function getLineNo() {
201
-    if(!isset(self::$me))
201
+    if (!isset(self::$me))
202 202
       return 0;
203 203
     return self::$me->parse->getLineNo();
204 204
   }
Please login to merge, or discard this patch.
php/hamle/Parse.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         $i = self::indentLevel($indent);
157 157
         unset($m[0]);
158 158
         switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) {
159
-          case "|": //Control Tag
159
+          case "|" : //Control Tag
160 160
             if ($code == "|snippet")
161 161
               $hTag = new Tag\Snippet($text);
162 162
             elseif ($code == "|form")
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
             break;
192 192
           default:
193 193
             $attr = array();
194
-            if(isset($params[0]) && $params[0] == "[") {
194
+            if (isset($params[0]) && $params[0] == "[") {
195 195
               $param = substr($params, 1, strlen($params) - 2);
196
-              $param = str_replace('+','%2B', $param);
196
+              $param = str_replace('+', '%2B', $param);
197 197
               parse_str($param, $attr);
198 198
             }
199 199
             $class = array(); $id = ""; $ref = "";
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
               if ($s[0] == ".") $class[] = substr($s, 1);
204 204
               if ($s[0] == "!") $ref = substr($s, 1);
205 205
             }
206
-            if($ref)
206
+            if ($ref)
207 207
               $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref);
208 208
             else
209 209
               $hTag = new Tag\Html($tag, $class, $attr, $id);
Please login to merge, or discard this patch.