Passed
Push — master ( cbc44e...97c601 )
by Chris
03:17
created
php/hamle/Text/Complex.php 1 patch
Braces   +31 added lines, -21 removed lines patch added patch discarded remove patch
@@ -44,20 +44,24 @@  discard block
 block discarded – undo
44 44
     }
45 45
     $s = preg_split("/-[>!]/", $s);
46 46
     // if(count($s) == 1) $s = explode("-!",$s[0]);
47
-    if (!$s[0]) throw new ParseError("Unable to parse Complex Expression");
48
-    if ($s[0][1] == "(")
49
-      $this->func = new Text\Func($s[0]);
50
-    elseif ($s[0][1] == "[")
51
-      $this->func = new Text\Scope($s[0]);
52
-    else
53
-      $this->func = new SimpleVar($s[0]);
47
+    if (!$s[0]) {
48
+      throw new ParseError("Unable to parse Complex Expression");
49
+    }
50
+    if ($s[0][1] == "(") {
51
+          $this->func = new Text\Func($s[0]);
52
+    } elseif ($s[0][1] == "[") {
53
+          $this->func = new Text\Scope($s[0]);
54
+    } else {
55
+          $this->func = new SimpleVar($s[0]);
56
+    }
54 57
     array_shift($s);
55 58
     $this->sel = $s;
56 59
   }
57 60
 
58 61
   function toHTML($escape = false) {
59
-    if($escape)
60
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
62
+    if($escape) {
63
+          return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
64
+    }
61 65
     return "<?=" . $this->toPHP() . "?>";
62 66
   }
63 67
   function toPHP() {
@@ -66,18 +70,22 @@  discard block
 block discarded – undo
66 70
   function toPHPVar() {
67 71
     if ($this->sel) {
68 72
       $sel = array();
69
-      foreach ($this->sel as $s)
70
-        $sel[] = "hamleGet('$s')";
73
+      foreach ($this->sel as $s) {
74
+              $sel[] = "hamleGet('$s')";
75
+      }
71 76
       return $this->func->toPHP() . "->" . implode('->', $sel);
72
-    } else
73
-      return $this->func->toPHP();
77
+    } else {
78
+          return $this->func->toPHP();
79
+    }
74 80
   }
75 81
 
76 82
   function getOrCreateModel(Model $parent = null) {
77
-    if($this->func instanceof Text\Scope)
78
-      return $this->func->getOrCreateModel($parent);
79
-    if($this->func instanceof Text\Func)
80
-      return $this->func->getOrCreateModel($parent);
83
+    if($this->func instanceof Text\Scope) {
84
+          return $this->func->getOrCreateModel($parent);
85
+    }
86
+    if($this->func instanceof Text\Func) {
87
+          return $this->func->getOrCreateModel($parent);
88
+    }
81 89
   }
82 90
 
83 91
   /**
@@ -85,11 +93,13 @@  discard block
 block discarded – undo
85 93
    * @return WriteModel
86 94
    */
87 95
   function setValue($value) {
88
-    if(!$this->sel || count($this->sel) != 1)
89
-      throw new \RuntimeException('Can only set values, when one var name is present');
96
+    if(!$this->sel || count($this->sel) != 1) {
97
+          throw new \RuntimeException('Can only set values, when one var name is present');
98
+    }
90 99
     $model = $this->getOrCreateModel();
91
-    if(!$model instanceof WriteModel)
92
-      throw new \RuntimeException('Can only set values on WriteModel, got '.get_class($model));
100
+    if(!$model instanceof WriteModel) {
101
+          throw new \RuntimeException('Can only set values on WriteModel, got '.get_class($model));
102
+    }
93 103
     $model->hamleSet($this->sel[0], $value);
94 104
     return $model;
95 105
   }
Please login to merge, or discard this patch.
php/hamle/Text/FuncSub.php 1 patch
Braces   +22 added lines, -12 removed lines patch added patch discarded remove patch
@@ -39,17 +39,25 @@  discard block
 block discarded – undo
39 39
    */
40 40
   public function __construct($s) {
41 41
     $m = array();
42
-    if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m))
43
-      throw new ParseError("Unable to read \$ sub func in '$s'");
44
-    if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT;
45
-    elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD;
46
-    else $this->dir = Hamle\Hamle::REL_ANY;
42
+    if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) {
43
+          throw new ParseError("Unable to read \$ sub func in '$s'");
44
+    }
45
+    if ($m[1] == "<") {
46
+      $this->dir = Hamle\Hamle::REL_PARENT;
47
+    } elseif ($m[1] == ">") {
48
+      $this->dir = Hamle\Hamle::REL_CHILD;
49
+    } else {
50
+      $this->dir = Hamle\Hamle::REL_ANY;
51
+    }
47 52
     $this->sortlimit = $this->attSortLimit($m[2]);
48 53
     $this->filt = $this->attIdTag($m[2]);
49 54
     $this->grouptype = $this->attGroupType($m[2]);
50
-    if ($this->filt['id']) throw new ParseError("Unable to select by id");
51
-    if (trim($m[3]))
52
-      $this->sub = new FuncSub($m[3]);
55
+    if ($this->filt['id']) {
56
+      throw new ParseError("Unable to select by id");
57
+    }
58
+    if (trim($m[3])) {
59
+          $this->sub = new FuncSub($m[3]);
60
+    }
53 61
   }
54 62
 
55 63
   /**
@@ -69,13 +77,15 @@  discard block
 block discarded – undo
69 77
     $model = $parent->hamleRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'],
70 78
       $this->sortlimit['limit'], $this->sortlimit['offset']);
71 79
     if(!$model->valid()) {
72
-      if(!$parent instanceof Hamle\WriteModel)
73
-        throw new \Exception('Cant create model, ' . get_class($parent) . ' must implement Hamle\\WriteModel.');
80
+      if(!$parent instanceof Hamle\WriteModel) {
81
+              throw new \Exception('Cant create model, ' . get_class($parent) . ' must implement Hamle\\WriteModel.');
82
+      }
74 83
       $model = $parent->current()->hamleCreateRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'],
75 84
         $this->sortlimit['limit'], $this->sortlimit['offset']);
76 85
     }
77
-    if($this->sub)
78
-      return $this->sub->getOrCreateModel($model);
86
+    if($this->sub) {
87
+          return $this->sub->getOrCreateModel($model);
88
+    }
79 89
     return $model;
80 90
   }
81 91
 
Please login to merge, or discard this patch.