Passed
Push — master ( cbc44e...97c601 )
by Chris
03:17
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 WriteModel, 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 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 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  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))
42
+    if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL.'+)(.*)$/', $s, $m))
43 43
       throw new ParseError("Unable to read \$ sub func in '$s'");
44 44
     if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT;
45 45
     elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD;
@@ -57,24 +57,24 @@  discard block
 block discarded – undo
57 57
    * @return string
58 58
    */
59 59
   public function toPHP() {
60
-    $limit = Hamle\Text::varToCode($this->sortlimit['sort']) . "," .
61
-        $this->sortlimit['limit'] . "," . $this->sortlimit['offset'] . "," .
60
+    $limit = Hamle\Text::varToCode($this->sortlimit['sort']).",".
61
+        $this->sortlimit['limit'].",".$this->sortlimit['offset'].",".
62 62
         $this->grouptype['grouptype'];
63
-    $sub = $this->sub ? "->" . $this->sub->toPHP() : "";
64
-    return "hamleRel(" . $this->dir . "," .
65
-    Hamle\Text::varToCode($this->filt['tag']) . ",$limit)$sub";
63
+    $sub = $this->sub ? "->".$this->sub->toPHP() : "";
64
+    return "hamleRel(".$this->dir.",".
65
+    Hamle\Text::varToCode($this->filt['tag']).",$limit)$sub";
66 66
   }
67 67
 
68 68
   public function getOrCreateModel(Model $parent = null) {
69 69
     $model = $parent->hamleRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'],
70 70
       $this->sortlimit['limit'], $this->sortlimit['offset']);
71
-    if(!$model->valid()) {
72
-      if(!$parent instanceof Hamle\WriteModel)
73
-        throw new \Exception('Cant create model, ' . get_class($parent) . ' must implement Hamle\\WriteModel.');
71
+    if (!$model->valid()) {
72
+      if (!$parent instanceof Hamle\WriteModel)
73
+        throw new \Exception('Cant create model, '.get_class($parent).' must implement Hamle\\WriteModel.');
74 74
       $model = $parent->current()->hamleCreateRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'],
75 75
         $this->sortlimit['limit'], $this->sortlimit['offset']);
76 76
     }
77
-    if($this->sub)
77
+    if ($this->sub)
78 78
       return $this->sub->getOrCreateModel($model);
79 79
     return $model;
80 80
   }
Please login to merge, or discard this 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.