Completed
Push — master ( 983da4...4bd5ba )
by Chris
04:09
created
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.
php/hamle/Tag/Control.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
     $this->type = strtolower($tag);
52 52
     $this->var = "";
53 53
     if ($parentTag && $this->type == "else") {
54
-      if($parentTag instanceof H\Tag) {
54
+      if ($parentTag instanceof H\Tag) {
55 55
         $elseTag = $parentTag->tags[count($parentTag->tags) - 1];
56
-        if($elseTag instanceof H\Tag\Control &&
56
+        if ($elseTag instanceof H\Tag\Control &&
57 57
             in_array($elseTag->type, array('with', 'if'))
58 58
         ) {
59 59
           $elseTag->else = true;
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
         break;
102 102
       case "include":
103 103
         $file = $hsv->toHTML();
104
-        if($file[0] == "#")
105
-          $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");";
104
+        if ($file[0] == "#")
105
+          $out .= "echo Hamle\\Run::includeFragment(" . $hsv->toPHP() . ");";
106 106
         else
107 107
           $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");";
108 108
         break;
Please login to merge, or discard this patch.
php/hamle/Text/Func.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
     }
87 87
     $rand = false;
88 88
     if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) {
89
-      foreach($m[0] as $k=>$mv)
89
+      foreach ($m[0] as $k=>$mv)
90 90
         if ($m[2][$k]) {
91
-          $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING;
91
+          $dir = $m[1][$k] == "-" ? Hamle\Hamle::SORT_DESCENDING : Hamle\Hamle::SORT_ASCENDING;
92 92
           $att['sort'][$m[2][$k]] = $dir;
93 93
         } else $rand = true;
94 94
     }
95
-    if($rand)
95
+    if ($rand)
96 96
       $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM];
97 97
     return $att;
98 98
   }
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
    */
112 112
   function toPHP() {
113 113
     $sub = $this->sub ? "->" . $this->sub->toPHP() : "";
114
-    if($this->scope instanceof Scope) {
114
+    if ($this->scope instanceof Scope) {
115 115
       return $this->scope->toPHP() . $sub;
116
-    } elseif($this->scope === true) {
116
+    } elseif ($this->scope === true) {
117 117
       return "Hamle\\Scope::get(0)$sub";
118 118
     }
119 119
     $limit = Text::varToCode($this->sortlimit['sort']) . "," .
Please login to merge, or discard this patch.
php/hamle/Text/Filter.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,16 +38,16 @@  discard block
 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 44
     } else {
45 45
       throw new ParseError("Unable to parse filter expression \"$s\"");
46 46
     }
47
-    if(!in_array($this->filter, ['itersplit', 'newlinebr', 'round', 'strtoupper', 'strtolower', 'ucfirst'])) {
47
+    if (!in_array($this->filter, ['itersplit', 'newlinebr', 'round', 'strtoupper', 'strtolower', 'ucfirst'])) {
48 48
       throw new ParseError("Unknown Filter Type \"{$this->filter}\"");
49 49
     }
50
-    switch($this->filter) {
50
+    switch ($this->filter) {
51 51
       case "itersplit":
52 52
         $this->filter = "Seufert\\Hamle\\Text\\Filter::iterSplit";
53 53
         break;
@@ -59,29 +59,29 @@  discard block
 block discarded – undo
59 59
   }
60 60
 
61 61
   function toHTML($escape = false) {
62
-    if($escape)
63
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
62
+    if ($escape)
63
+      return "<?=htmlspecialchars(" . $this->toPHP() . ")?>";
64 64
     return "<?=" . $this->toPHP() . "?>";
65 65
   }
66 66
 
67 67
   function toPHP() {
68
-    $o = [$this->what->toPHPVar()] ;
69
-    foreach($this->vars as $v)
68
+    $o = [$this->what->toPHPVar()];
69
+    foreach ($this->vars as $v)
70 70
       $o[] = $this->varToCode($v);
71
-    return "{$this->filter}(" . implode(',',$o) . ")";
71
+    return "{$this->filter}(" . implode(',', $o) . ")";
72 72
   }
73 73
 
74 74
   static function iterSplit($v, $sep = ",") {
75 75
     $o = [];
76
-    foreach(explode($sep, $v) as $k=>$i) {
77
-      if($i)
78
-        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
76
+    foreach (explode($sep, $v) as $k=>$i) {
77
+      if ($i)
78
+        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k];
79 79
     }
80 80
     return new WrapArray($o);
81 81
   }
82 82
 
83 83
   static function newlineBr($v) {
84
-    return str_replace("\n","<br />\n",$v);
84
+    return str_replace("\n", "<br />\n", $v);
85 85
   }
86 86
 
87 87
 }
88 88
\ No newline at end of file
Please login to merge, or discard this patch.