Completed
Push — master ( a7f3dd...9754ce )
by Chris
02:54
created
php/hamle/Parse.php 1 patch
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,8 +24,8 @@
 block discarded – undo
24 24
 
25 25
  */
26 26
 namespace Seufert\Hamle;
27
-use Seufert\Hamle\Exception\ParseError;
28
-use Seufert\Hamle\Parse\Filter as ParseFilter;
27
+use Seufert\Hamle\Exception\ParseError;
28
+use Seufert\Hamle\Parse\Filter as ParseFilter;
29 29
 use Seufert\Hamle\Text;
30 30
 
31 31
 /**
Please login to merge, or discard this patch.
php/hamle/Tag/Control.php 2 patches
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.
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 2 patches
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.
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.