Completed
Push — master ( bbd140...a7f3dd )
by Chris
03:02
created
php/hamle/Tag/Snippet.php 1 patch
Braces   +29 added lines, -18 removed lines patch added patch discarded remove patch
@@ -32,25 +32,33 @@  discard block
 block discarded – undo
32 32
 
33 33
   function __construct($params) {
34 34
     parent::__construct();
35
-    if (!preg_match('/^(append|content|prepend|replace)(?: (.*))?$/', $params, $m))
36
-      throw new Hamle\Exception\ParseError("Unable to parse Snippet($params)");
35
+    if (!preg_match('/^(append|content|prepend|replace)(?: (.*))?$/', $params, $m)) {
36
+          throw new Hamle\Exception\ParseError("Unable to parse Snippet($params)");
37
+    }
37 38
     $this->type = $m[1];
38
-    if (isset($m[2]))
39
-      $this->path = explode(" ", $m[2]);
40
-    else
41
-      $this->path = array();
42
-    foreach ($this->path as $k => $v)
43
-      $this->path[$k] = self::decodeClassId($v);
39
+    if (isset($m[2])) {
40
+          $this->path = explode(" ", $m[2]);
41
+    } else {
42
+          $this->path = array();
43
+    }
44
+    foreach ($this->path as $k => $v) {
45
+          $this->path[$k] = self::decodeClassId($v);
46
+    }
44 47
   }
45 48
 
46 49
   static function decodeClassId($s) {
47 50
     $out = $m = array();
48
-    if(preg_match('/^[a-zA-Z0-9\_]+/', $s, $m))
49
-      $out['type'] = $m[0];
51
+    if(preg_match('/^[a-zA-Z0-9\_]+/', $s, $m)) {
52
+          $out['type'] = $m[0];
53
+    }
50 54
     preg_match_all('/[#\.][a-zA-Z0-9\-\_]+/m', $s, $m);
51
-    if (isset($m[0])) foreach ($m[0] as $s) {
55
+    if (isset($m[0])) {
56
+      foreach ($m[0] as $s) {
52 57
       if ($s[0] == "#") $out['id'] = substr($s, 1);
53
-      if ($s[0] == ".") $out['class'][] = substr($s, 1);
58
+    }
59
+      if ($s[0] == ".") {
60
+        $out['class'][] = substr($s, 1);
61
+      }
54 62
     }
55 63
     return $out;
56 64
   }
@@ -62,21 +70,24 @@  discard block
 block discarded – undo
62 70
   function addSnipContent($contentTag, &$tagArray = array(), $key = 0) {
63 71
     if ($this->type == "content") {
64 72
       $tagArray[$key] = $contentTag;
65
-    } else
66
-      parent::addSnipContent($contentTag, $tagArray, $key);
73
+    } else {
74
+          parent::addSnipContent($contentTag, $tagArray, $key);
75
+    }
67 76
   }
68 77
 
69 78
   function apply(Hamle\Tag $rootTag) {
70 79
     if ($this->type == "append" or $this->type == "prepend") {
71 80
       $matchTags = $rootTag->find($this->path);
72
-      foreach ($matchTags as $tag)
73
-        foreach ($this->tags as $t) {
81
+      foreach ($matchTags as $tag) {
82
+              foreach ($this->tags as $t) {
74 83
           $tag->addChild($t, $this->type);
84
+      }
75 85
         }
76 86
     } elseif ($this->type == "replace") {
77 87
       $rootTag->replace($this->path, $this);
78
-    } else
79
-      throw new Hamle\Exception\ParseError("Cant Apply snippet to document '{$this->type}'");
88
+    } else {
89
+          throw new Hamle\Exception\ParseError("Cant Apply snippet to document '{$this->type}'");
90
+    }
80 91
   }
81 92
 
82 93
 }
83 94
\ No newline at end of file
Please login to merge, or discard this patch.
php/hamle/Tag/Filter.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,8 +42,9 @@
 block discarded – undo
42 42
     parent::__construct();
43 43
     $this->type = ucfirst(strtolower($tag));
44 44
     $this->filter = "\\Seufert\\Hamle\\Filter\\{$this->type}";
45
-    if (!class_exists($this->filter))
46
-      Throw new ParseError("Unable to fild filter $tag");
45
+    if (!class_exists($this->filter)) {
46
+          Throw new ParseError("Unable to fild filter $tag");
47
+    }
47 48
   }
48 49
 
49 50
   function renderContent($pad = "", $oneliner = false) {
Please login to merge, or discard this patch.
php/hamle/Tag/Html.php 1 patch
Braces   +23 added lines, -13 removed lines patch added patch discarded remove patch
@@ -42,17 +42,21 @@  discard block
 block discarded – undo
42 42
   function __construct($tag, $class = array(), $attr = array(), $id = "") {
43 43
     parent::__construct();
44 44
     $this->opt = $attr;
45
-    if(isset($attr['class']) && !is_array($attr['class']))
46
-      $this->opt['class'] = $attr['class']?explode(" ",$attr['class']):array();
45
+    if(isset($attr['class']) && !is_array($attr['class'])) {
46
+          $this->opt['class'] = $attr['class']?explode(" ",$attr['class']):array();
47
+    }
47 48
     $this->source = array();
48 49
     $this->type = $tag ? $tag : "div";
49 50
     if($class) {
50
-      if (isset($this->opt['class']))
51
-        $this->opt['class'] = array_merge($this->opt['class'], $class);
52
-      else
53
-        $this->opt['class'] = $class;
51
+      if (isset($this->opt['class'])) {
52
+              $this->opt['class'] = array_merge($this->opt['class'], $class);
53
+      } else {
54
+              $this->opt['class'] = $class;
55
+      }
56
+    }
57
+    if($id) {
58
+      $this->opt['id'] = $id;
54 59
     }
55
-    if($id) $this->opt['id'] = $id;
56 60
   }
57 61
 
58 62
   function renderStTag() {
@@ -61,8 +65,9 @@  discard block
 block discarded – undo
61 65
   }
62 66
 
63 67
   function renderEnTag() {
64
-    if (in_array($this->type, self::$selfCloseTags))
65
-      return "";
68
+    if (in_array($this->type, self::$selfCloseTags)) {
69
+          return "";
70
+    }
66 71
     return "</{$this->type}>";
67 72
   }
68 73
 
@@ -74,10 +79,15 @@  discard block
 block discarded – undo
74 79
   function optToTags() {
75 80
     $out = array();
76 81
     foreach ($this->opt as $k => $v) {
77
-      if ($k == "class" && !$v) continue;
78
-      if (is_array($v)) $v = implode(" ", $v);
79
-      if (!$v instanceof H\Text)
80
-        $v = new H\Text($v);
82
+      if ($k == "class" && !$v) {
83
+        continue;
84
+      }
85
+      if (is_array($v)) {
86
+        $v = implode(" ", $v);
87
+      }
88
+      if (!$v instanceof H\Text) {
89
+              $v = new H\Text($v);
90
+      }
81 91
       $k = new H\Text($k);
82 92
       $out[] = " " . $k->toHTML() . "=\"" . $v->toHTMLAtt() . "\"";
83 93
     }
Please login to merge, or discard this patch.
php/hamle/Form.php 1 patch
Braces   +17 added lines, -12 removed lines patch added patch discarded remove patch
@@ -64,15 +64,18 @@  discard block
 block discarded – undo
64 64
   
65 65
   function process() {
66 66
     $clicked = "";
67
-    foreach($this->_fields as $f)
68
-      if($f instanceOf Field\Button)
67
+    foreach($this->_fields as $f) {
68
+          if($f instanceOf Field\Button)
69 69
         if($f->isClicked())
70
-          $clicked = $f;
71
-    foreach($this->_fields as $f)
72
-      $f->doProcess($clicked?true:false);
73
-    if($clicked)
74
-      try {
75
-        $this->onSubmit($clicked);
70
+          $clicked = $f;
71
+    }
72
+    foreach($this->_fields as $f) {
73
+          $f->doProcess($clicked?true:false);
74
+    }
75
+    if($clicked) {
76
+          try {
77
+        $this->onSubmit($clicked);
78
+    }
76 79
       } catch(Exception\FormInvalid $e) {
77 80
         $this->hint = $e->getMessage();
78 81
       }
@@ -80,8 +83,9 @@  discard block
 block discarded – undo
80 83
   
81 84
   function isValid() {
82 85
     $valid = true;
83
-    foreach($this->_fields as $f)
84
-      $valid = $f->valid && $valid;
86
+    foreach($this->_fields as $f) {
87
+          $valid = $f->valid && $valid;
88
+    }
85 89
     return $valid;
86 90
   }
87 91
   /**
@@ -95,8 +99,9 @@  discard block
 block discarded – undo
95 99
     return $this->_fields;
96 100
   }
97 101
   function getField($n) {
98
-    if(!isset($this->_fields[$n]))
99
-      throw new Exception\NoKey("unable to find form field ($n)");
102
+    if(!isset($this->_fields[$n])) {
103
+          throw new Exception\NoKey("unable to find form field ($n)");
104
+    }
100 105
     return $this->_fields[$n];
101 106
   }
102 107
   function __get($n) {
Please login to merge, or discard this patch.
php/hamle/Text/Func.php 1 patch
Braces   +41 added lines, -25 removed lines patch added patch discarded remove patch
@@ -38,10 +38,12 @@  discard block
 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 \$ func in '$s'");
43
-    if (trim($m[2]))
44
-      $this->sub = new FuncSub($m[2]);
41
+    if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) {
42
+          throw new ParseError("Unable to read \$ func in '$s'");
43
+    }
44
+    if (trim($m[2])) {
45
+          $this->sub = new FuncSub($m[2]);
46
+    }
45 47
     if (!trim($m[1])) {
46 48
       $this->scope = true;
47 49
       return;
@@ -58,17 +60,24 @@  discard block
 block discarded – undo
58 60
     $m = array();
59 61
     $att = array('id' => array(), 'tag' => array());
60 62
     foreach (explode(",", $s) as $str) {
61
-      if (preg_match('/^[a-zA-Z0-9\\_]+/', $str, $m)) $type = $m[0];
62
-      else $type = "*";
63
-      if (preg_match('/#([a-zA-Z0-9\_\\${}]+)/', $str, $m)) $att['id'][$type][] = $m[1];
64
-      elseif (preg_match_all('/\\.([a-zA-Z0-9\_\-\\${}]+)/', $str, $m))
65
-        foreach ($m[1] as $tag)
63
+      if (preg_match('/^[a-zA-Z0-9\\_]+/', $str, $m)) {
64
+        $type = $m[0];
65
+      } else {
66
+        $type = "*";
67
+      }
68
+      if (preg_match('/#([a-zA-Z0-9\_\\${}]+)/', $str, $m)) {
69
+        $att['id'][$type][] = $m[1];
70
+      } elseif (preg_match_all('/\\.([a-zA-Z0-9\_\-\\${}]+)/', $str, $m)) {
71
+              foreach ($m[1] as $tag)
66 72
           $att['tag'][$type][] = new Text($tag, Text::TOKEN_CODE);
67
-      else $att['tag'][$type] = array();
73
+      } else {
74
+        $att['tag'][$type] = array();
75
+      }
68 76
     }
69 77
     //var_dump($att);
70
-    if (!(count($att['id']) xor count($att['tag'])))
71
-      throw new ParseError("Only tag, type or id can be combined");
78
+    if (!(count($att['id']) xor count($att['tag']))) {
79
+          throw new ParseError("Only tag, type or id can be combined");
80
+    }
72 81
     return $att;
73 82
   }
74 83
 
@@ -81,14 +90,18 @@  discard block
 block discarded – undo
81 90
     }
82 91
     $rand = false;
83 92
     if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) {
84
-      foreach($m[0] as $k=>$mv)
85
-        if ($m[2][$k]) {
93
+      foreach($m[0] as $k=>$mv) {
94
+              if ($m[2][$k]) {
86 95
           $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING;
96
+      }
87 97
           $att['sort'][$m[2][$k]] = $dir;
88
-        } else $rand = true;
98
+        } else {
99
+          $rand = true;
100
+        }
101
+    }
102
+    if($rand) {
103
+          $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM];
89 104
     }
90
-    if($rand)
91
-      $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM];
92 105
     return $att;
93 106
   }
94 107
 
@@ -106,21 +119,24 @@  discard block
 block discarded – undo
106 119
         $this->sortlimit['limit'] . "," . $this->sortlimit['offset'];
107 120
     $sub = $this->sub ? "->" . $this->sub->toPHP() : "";
108 121
     if ($this->scope) {
109
-      if($this->scope === true)
110
-        return "Hamle\\Scope::get(0)$sub";
122
+      if($this->scope === true) {
123
+              return "Hamle\\Scope::get(0)$sub";
124
+      }
111 125
       return $this->scope->toPHP().$sub;
112 126
     }
113
-    if (count($this->filt['tag']))
114
-      return "Hamle\\Run::modelTypeTags(" .
127
+    if (count($this->filt['tag'])) {
128
+          return "Hamle\\Run::modelTypeTags(" .
115 129
       Text::varToCode($this->filt['tag']) . ",$limit)$sub";
116
-    if (count($this->filt['id']))
117
-      if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1)
130
+    }
131
+    if (count($this->filt['id'])) {
132
+          if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1)
118 133
         return "Hamle\\Run::modelId(" .
119 134
         Text::varToCode(current($this->filt['id']['*'])) .
120 135
         ",$limit)$sub";
121
-      else
122
-        return "Hamle\\Run::modelTypeId(" .
136
+    } else {
137
+              return "Hamle\\Run::modelTypeId(" .
123 138
         Text::varToCode($this->filt['id']) . ",$limit)$sub";
139
+      }
124 140
     return "";
125 141
   }
126 142
 
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
@@ -33,17 +33,25 @@
 block discarded – undo
33 33
 
34 34
   function __construct($s) {
35 35
     $m = array();
36
-    if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m))
37
-      throw new ParseError("Unable to read \$ sub func in '$s'");
38
-    if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT;
39
-    elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD;
40
-    else $this->dir = Hamle\Hamle::REL_ANY;
36
+    if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) {
37
+          throw new ParseError("Unable to read \$ sub func in '$s'");
38
+    }
39
+    if ($m[1] == "<") {
40
+      $this->dir = Hamle\Hamle::REL_PARENT;
41
+    } elseif ($m[1] == ">") {
42
+      $this->dir = Hamle\Hamle::REL_CHILD;
43
+    } else {
44
+      $this->dir = Hamle\Hamle::REL_ANY;
45
+    }
41 46
     $this->sortlimit = $this->attSortLimit($m[2]);
42 47
     $this->filt = $this->attIdTag($m[2]);
43 48
     $this->grouptype = $this->attGroupType($m[2]);
44
-    if ($this->filt['id']) throw new ParseError("Unable to select by id");
45
-    if (trim($m[3]))
46
-      $this->sub = new FuncSub($m[3]);
49
+    if ($this->filt['id']) {
50
+      throw new ParseError("Unable to select by id");
51
+    }
52
+    if (trim($m[3])) {
53
+          $this->sub = new FuncSub($m[3]);
54
+    }
47 55
   }
48 56
 
49 57
   function toPHP() {
Please login to merge, or discard this patch.
php/hamle/Text/Complex.php 1 patch
Braces   +19 added lines, -13 removed lines patch added patch discarded remove patch
@@ -39,20 +39,24 @@  discard block
 block discarded – undo
39 39
       $s = substr($s,0,$pos);
40 40
     }
41 41
     $s = explode("->", $s);
42
-    if (!$s[0]) throw new ParseError("Unable to parse Complex Expression");
43
-    if ($s[0][1] == "(")
44
-      $this->func = new Text\Func($s[0]);
45
-    elseif ($s[0][1] == "[")
46
-      $this->func = new Text\Scope($s[0]);
47
-    else
48
-      $this->func = new SimpleVar($s[0]);
42
+    if (!$s[0]) {
43
+      throw new ParseError("Unable to parse Complex Expression");
44
+    }
45
+    if ($s[0][1] == "(") {
46
+          $this->func = new Text\Func($s[0]);
47
+    } elseif ($s[0][1] == "[") {
48
+          $this->func = new Text\Scope($s[0]);
49
+    } else {
50
+          $this->func = new SimpleVar($s[0]);
51
+    }
49 52
     array_shift($s);
50 53
     $this->sel = $s;
51 54
   }
52 55
 
53 56
   function toHTML($escape = false) {
54
-    if($escape)
55
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
57
+    if($escape) {
58
+          return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
59
+    }
56 60
     return "<?=" . $this->toPHP() . "?>";
57 61
   }
58 62
   function toPHP() {
@@ -61,11 +65,13 @@  discard block
 block discarded – undo
61 65
   function toPHPVar() {
62 66
     if ($this->sel) {
63 67
       $sel = array();
64
-      foreach ($this->sel as $s)
65
-        $sel[] = "hamleGet('$s')";
68
+      foreach ($this->sel as $s) {
69
+              $sel[] = "hamleGet('$s')";
70
+      }
66 71
       return $this->func->toPHP() . "->" . implode('->', $sel);
67
-    } else
68
-      return $this->func->toPHP();
72
+    } else {
73
+          return $this->func->toPHP();
74
+    }
69 75
   }
70 76
 
71 77
 }
72 78
\ No newline at end of file
Please login to merge, or discard this patch.
php/hamle/Text/Scope.php 1 patch
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,16 +34,18 @@
 block discarded – undo
34 34
   function __construct($s) {
35 35
     $m = array();
36 36
     //var_dump($s);
37
-    if (!preg_match('/\$\[(-?[0-9]+|[a-zA-Z][a-zA-Z0-9]+)\]/', $s, $m))
38
-      throw new ParseError("Unable to match scope ($s)");
37
+    if (!preg_match('/\$\[(-?[0-9]+|[a-zA-Z][a-zA-Z0-9]+)\]/', $s, $m)) {
38
+          throw new ParseError("Unable to match scope ($s)");
39
+    }
39 40
     $this->scope = $m[1];
40 41
   }
41 42
 
42 43
   function toPHP() {
43
-    if (is_numeric($this->scope))
44
-      return "Hamle\\Scope::get(" . Text::varToCode($this->scope) . ")";
45
-    else
46
-      return "Hamle\\Scope::getName(" . Text::varToCode($this->scope) . ")";
44
+    if (is_numeric($this->scope)) {
45
+          return "Hamle\\Scope::get(" . Text::varToCode($this->scope) . ")";
46
+    } else {
47
+          return "Hamle\\Scope::getName(" . Text::varToCode($this->scope) . ")";
48
+    }
47 49
   }
48 50
 
49 51
   function toHTML($escape = false) {
Please login to merge, or discard this patch.
php/hamle/Text/SimpleVar.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,8 +42,9 @@
 block discarded – undo
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 48
     return "<?=" . $this->toPHP() . "?>";
48 49
   }
49 50
 
Please login to merge, or discard this patch.