Passed
Push — master ( 453007...cbc44e )
by Chris
03:29
created
php/hamle/Text/Complex.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
   protected $filter;
39 39
 
40 40
   function __construct($s) {
41
-    if(FALSE !== $pos = strpos($s,'|')) {
42
-      $this->filter = new Filter(substr($s, $pos+1), $this);
43
-      $s = substr($s,0,$pos);
41
+    if (FALSE !== $pos = strpos($s, '|')) {
42
+      $this->filter = new Filter(substr($s, $pos + 1), $this);
43
+      $s = substr($s, 0, $pos);
44 44
     }
45 45
     $s = preg_split("/-[>!]/", $s);
46 46
     // if(count($s) == 1) $s = explode("-!",$s[0]);
@@ -56,27 +56,27 @@  discard block
 block discarded – undo
56 56
   }
57 57
 
58 58
   function toHTML($escape = false) {
59
-    if($escape)
60
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
61
-    return "<?=" . $this->toPHP() . "?>";
59
+    if ($escape)
60
+      return "<?=htmlspecialchars(".$this->toPHP().")?>";
61
+    return "<?=".$this->toPHP()."?>";
62 62
   }
63 63
   function toPHP() {
64
-    return $this->filter?$this->filter->toPHP():$this->toPHPVar();
64
+    return $this->filter ? $this->filter->toPHP() : $this->toPHPVar();
65 65
   }
66 66
   function toPHPVar() {
67 67
     if ($this->sel) {
68 68
       $sel = array();
69 69
       foreach ($this->sel as $s)
70 70
         $sel[] = "hamleGet('$s')";
71
-      return $this->func->toPHP() . "->" . implode('->', $sel);
71
+      return $this->func->toPHP()."->".implode('->', $sel);
72 72
     } else
73 73
       return $this->func->toPHP();
74 74
   }
75 75
 
76 76
   function getOrCreateModel(Model $parent = null) {
77
-    if($this->func instanceof Text\Scope)
77
+    if ($this->func instanceof Text\Scope)
78 78
       return $this->func->getOrCreateModel($parent);
79
-    if($this->func instanceof Text\Func)
79
+    if ($this->func instanceof Text\Func)
80 80
       return $this->func->getOrCreateModel($parent);
81 81
   }
82 82
 
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
    * @return WriteModel
86 86
    */
87 87
   function setValue($value) {
88
-    if(!$this->sel || count($this->sel) != 1)
88
+    if (!$this->sel || count($this->sel) != 1)
89 89
       throw new \RuntimeException('Can only set values, when one var name is present');
90 90
     $model = $this->getOrCreateModel();
91
-    if(!$model instanceof WriteModel)
91
+    if (!$model instanceof WriteModel)
92 92
       throw new \RuntimeException('Can only set values on WriteModels, got '.get_class($model));
93 93
     $model->hamleSet($this->sel[0], $value);
94 94
     return $model;
Please login to merge, or discard this 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 WriteModels, got '.get_class($model));
100
+    if(!$model instanceof WriteModel) {
101
+          throw new \RuntimeException('Can only set values on WriteModels, 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.