Completed
Push — master ( b33770...8b770c )
by Chris
07:17
created
php/hamle/Text/Comparison.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
 
36 36
   function __construct($s, $mode = self::TOKEN_CONTROL) {
37 37
     $m = array();
38
-    if(preg_match('/^(.*) '.self::REGEX_COMP_OPER.' (.*)$/', $s, $m)) {
39
-      $this->param1 = new Text($m[1],Text::TOKEN_HTML);
40
-      $this->param2 = new Text($m[3],Text::TOKEN_HTML);
38
+    if (preg_match('/^(.*) '.self::REGEX_COMP_OPER.' (.*)$/', $s, $m)) {
39
+      $this->param1 = new Text($m[1], Text::TOKEN_HTML);
40
+      $this->param2 = new Text($m[3], Text::TOKEN_HTML);
41 41
       $this->operator = $m[2];
42 42
     } else
43
-      $this->param1 = new Text($s,Text::TOKEN_HTML);
43
+      $this->param1 = new Text($s, Text::TOKEN_HTML);
44 44
   }
45 45
 
46 46
 //  function __construct(String $p1, String $p2, $operator) {
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
 //    $this->operator = $operator;
50 50
 //  }
51 51
   function toPHP() {
52
-    if(!$this->param2) return $this->param1->toPHP();
52
+    if (!$this->param2) return $this->param1->toPHP();
53 53
     $p1 = $this->param1->toPHP();
54 54
     $p2 = $this->param2->toPHP();
55
-    switch($this->operator) {
55
+    switch ($this->operator) {
56 56
       case "equals":
57 57
       case "equal":
58 58
         return $p1." == ".$p2;
Please login to merge, or discard this patch.
php/hamle/Text/FormField.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,10 +35,10 @@
 block discarded – undo
35 35
   }
36 36
 
37 37
   function toPHP() {
38
-    return '$form->getField(' . Text::varToCode($this->var) . ')->getValue()';
38
+    return '$form->getField('.Text::varToCode($this->var).')->getValue()';
39 39
   }
40 40
 
41 41
   function toHTML($escape = false) {
42
-    return '<?=' . $this->toPHP() . '?>';
42
+    return '<?='.$this->toPHP().'?>';
43 43
   }
44 44
 }
45 45
\ No newline at end of file
Please login to merge, or discard this patch.
php/hamle/Field/Button.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,6 +42,6 @@
 block discarded – undo
42 42
   }
43 43
 
44 44
   function isClicked() {
45
-    return isset($_REQUEST[$this->form . "_" . $this->name]);
45
+    return isset($_REQUEST[$this->form."_".$this->name]);
46 46
   }
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
php/hamle/Form.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     $this->setup();
55 55
     $fields = $this->_fields;
56 56
     $this->_fields = array();
57
-    foreach($fields as $v) {
57
+    foreach ($fields as $v) {
58 58
       $this->_fields[$v->name] = $v;
59 59
       $v->form($this->_name);
60 60
     }
@@ -64,23 +64,23 @@  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)
69
-        if($f->isClicked())
67
+    foreach ($this->_fields as $f)
68
+      if ($f instanceOf Field\Button)
69
+        if ($f->isClicked())
70 70
           $clicked = $f;
71
-    foreach($this->_fields as $f)
72
-      $f->doProcess($clicked?true:false);
73
-    if($clicked)
71
+    foreach ($this->_fields as $f)
72
+      $f->doProcess($clicked ?true:false);
73
+    if ($clicked)
74 74
       try {
75 75
         $this->onSubmit($clicked);
76
-      } catch(Exception\FormInvalid $e) {
76
+      } catch (Exception\FormInvalid $e) {
77 77
         $this->hint = $e->getMessage();
78 78
       }
79 79
   }
80 80
   
81 81
   function isValid() {
82 82
     $valid = true;
83
-    foreach($this->_fields as $f)
83
+    foreach ($this->_fields as $f)
84 84
       $valid = $f->valid && $valid;
85 85
     return $valid;
86 86
   }
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     return $this->_fields;
96 96
   }
97 97
   function getField($n) {
98
-    if(!isset($this->_fields[$n]))
98
+    if (!isset($this->_fields[$n]))
99 99
       throw new Exception\NoKey("unable to find form field ($n)");
100 100
     return $this->_fields[$n];
101 101
   }
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
   }
105 105
   
106 106
   function getHTMLProp() {
107
-    return array('action'=>'','method'=>'post','name'=>$this->_name,
107
+    return array('action'=>'', 'method'=>'post', 'name'=>$this->_name,
108 108
                                         'enctype'=>'multipart/form-data');
109 109
   }
110 110
 
Please login to merge, or discard this patch.
php/hamle/Tag/Html.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -42,22 +42,22 @@  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
     $this->source = array();
48 48
     $this->type = $tag ? $tag : "div";
49
-    if($class) {
49
+    if ($class) {
50 50
       if (isset($this->opt['class']))
51 51
         $this->opt['class'] = array_merge($this->opt['class'], $class);
52 52
       else
53 53
         $this->opt['class'] = $class;
54 54
     }
55
-    if($id) $this->opt['id'] = $id;
55
+    if ($id) $this->opt['id'] = $id;
56 56
   }
57 57
 
58 58
   function renderStTag() {
59 59
     $close = in_array($this->type, self::$selfCloseTags) ? " />" : ">";
60
-    return "<{$this->type}" . $this->optToTags() . $close;
60
+    return "<{$this->type}".$this->optToTags().$close;
61 61
   }
62 62
 
63 63
   function renderEnTag() {
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
       if (!$v instanceof H\Text)
80 80
         $v = new H\Text($v);
81 81
       $k = new H\Text($k);
82
-      $out[] = " " . $k->toHTML() . "=\"" . $v->toHTMLAtt() . "\"";
82
+      $out[] = " ".$k->toHTML()."=\"".$v->toHTMLAtt()."\"";
83 83
     }
84 84
     return implode("", $out);
85 85
   }
Please login to merge, or discard this patch.
php/hamle/Text/Scope.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,17 +36,17 @@  discard block
 block discarded – undo
36 36
   function __construct($s) {
37 37
     $m = [];
38 38
     //var_dump($s);
39
-    if(!preg_match('/\$\[(-?[0-9]+|[a-zA-Z][a-zA-Z0-9]+)\]/', $s, $m)) {
39
+    if (!preg_match('/\$\[(-?[0-9]+|[a-zA-Z][a-zA-Z0-9]+)\]/', $s, $m)) {
40 40
       throw new ParseError("Unable to match scope ($s)");
41 41
     }
42 42
     $this->scope = $m[1];
43 43
   }
44 44
 
45 45
   function toPHP() {
46
-    if(is_numeric($this->scope)) {
47
-      return "Hamle\\Scope::get(" . Text::varToCode($this->scope) . ")";
46
+    if (is_numeric($this->scope)) {
47
+      return "Hamle\\Scope::get(".Text::varToCode($this->scope).")";
48 48
     } else {
49
-      return "Hamle\\Scope::getName(" . Text::varToCode($this->scope) . ")";
49
+      return "Hamle\\Scope::getName(".Text::varToCode($this->scope).")";
50 50
     }
51 51
   }
52 52
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
 
62 62
   function getOrCreateModel(Model $parent = null) {
63
-    if(is_numeric($this->scope)) {
63
+    if (is_numeric($this->scope)) {
64 64
       return \Seufert\Hamle\Scope::get($this->scope);
65 65
     }
66 66
     return \Seufert\Hamle\Scope::getName($this->scope);
Please login to merge, or discard this patch.
php/hamle/Text/SimpleVar.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -35,26 +35,26 @@  discard block
 block discarded – undo
35 35
   protected $filter;
36 36
 
37 37
   function __construct($s) {
38
-    if(FALSE !== $pos = strpos($s,'|')) {
39
-      $this->var = substr($s,1,$pos-1);
40
-      $this->filter = new Filter(substr($s, $pos+1), $this);
38
+    if (FALSE !== $pos = strpos($s, '|')) {
39
+      $this->var = substr($s, 1, $pos - 1);
40
+      $this->filter = new Filter(substr($s, $pos + 1), $this);
41 41
     } else {
42 42
       $this->var = substr($s, 1);
43 43
     }
44 44
   }
45 45
 
46 46
   function toHTML($escape = false) {
47
-    if($escape)
48
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
49
-    return "<?=" . $this->toPHP() . "?>";
47
+    if ($escape)
48
+      return "<?=htmlspecialchars(".$this->toPHP().")?>";
49
+    return "<?=".$this->toPHP()."?>";
50 50
   }
51 51
 
52 52
   function toPHP() {
53
-    return $this->filter?$this->filter->toPHP():$this->toPHPVar();
53
+    return $this->filter ? $this->filter->toPHP() : $this->toPHPVar();
54 54
   }
55 55
 
56 56
   function toPHPVar() {
57
-    return "Hamle\\Scope::get()->hamleGet(" . Text::varToCode($this->var) . ")";
57
+    return "Hamle\\Scope::get()->hamleGet(".Text::varToCode($this->var).")";
58 58
   }
59 59
 
60 60
   function getOrCreateModel(Model $parent = null) {
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
    */
68 68
   function setValue($value) {
69 69
     $model = $this->getOrCreateModel();
70
-    if(!$model instanceof WriteModel)
70
+    if (!$model instanceof WriteModel)
71 71
       throw new \RuntimeException('Can only write to model that implements WriteModel');
72 72
     $model->hamleSet($this->var, $value);
73 73
     return $model;
Please login to merge, or discard this patch.
php/hamle/Text/FuncSub.php 1 patch
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)->current();
79 79
     return $model->current();
80 80
   }
Please login to merge, or discard this patch.
php/hamle/Text/Filter.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -41,47 +41,47 @@  discard block
 block discarded – undo
41 41
   protected $chained;
42 42
 
43 43
   function __construct($s, Text $what) {
44
-    if(preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) {
44
+    if (preg_match("/^([a-z]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) {
45 45
       $this->filter = $m[1];
46 46
       $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : [];
47
-      foreach($this->vars as $k=>$v)
48
-        $this->vars[$k] = str_replace("&comma;",',',$v);
49
-      if(isset($m['chained']) && strlen($m['chained'])) {
50
-        $this->chained = new Filter($m['chained'],$what);
47
+      foreach ($this->vars as $k=>$v)
48
+        $this->vars[$k] = str_replace("&comma;", ',', $v);
49
+      if (isset($m['chained']) && strlen($m['chained'])) {
50
+        $this->chained = new Filter($m['chained'], $what);
51 51
       }
52 52
     } else {
53 53
       throw new ParseError("Unable to parse filter expression \"$s\"");
54 54
     }
55
-    if(method_exists(Filter::class, $this->filter)) {
55
+    if (method_exists(Filter::class, $this->filter)) {
56 56
       $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}";
57
-    } elseif(!in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst', 'json'])) {
57
+    } elseif (!in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst', 'json'])) {
58 58
       throw new ParseError("Unknown Filter Type \"{$this->filter}\"");
59 59
     }
60 60
     $mapFilter = ['json'=>'json_encode'];
61
-    if(isset($mapFilter[$this->filter]))
61
+    if (isset($mapFilter[$this->filter]))
62 62
       $this->filter = $mapFilter[$this->filter];
63 63
     $this->what = $what;
64 64
   }
65 65
 
66 66
   function toHTML($escape = false) {
67
-    if($escape)
68
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
69
-    return "<?=" . $this->toPHP() . "?>";
67
+    if ($escape)
68
+      return "<?=htmlspecialchars(".$this->toPHP().")?>";
69
+    return "<?=".$this->toPHP()."?>";
70 70
   }
71 71
 
72 72
   function toPHPpre() {
73 73
     $pre = '';
74
-    if($this->chained)
74
+    if ($this->chained)
75 75
       $pre = $this->chained->toPHPpre();
76 76
     return "$pre{$this->filter}(";
77 77
   }
78 78
 
79 79
   function toPHPpost() {
80 80
     $post = '';
81
-    if($this->chained)
81
+    if ($this->chained)
82 82
       $post = $this->chained->toPHPpost();
83 83
     $o = '';
84
-    foreach($this->vars as $v)
84
+    foreach ($this->vars as $v)
85 85
       $o .= ','.$this->varToCode($v);
86 86
     return "$o)$post";
87 87
   }
@@ -96,24 +96,24 @@  discard block
 block discarded – undo
96 96
 
97 97
   static function itersplit($v, $sep = ",") {
98 98
     $o = [];
99
-    foreach(explode($sep, $v) as $k=>$i) {
100
-      if($i)
101
-        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
99
+    foreach (explode($sep, $v) as $k=>$i) {
100
+      if ($i)
101
+        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k];
102 102
     }
103 103
     return new WrapArray($o);
104 104
   }
105 105
 
106 106
   static function newlinebr($v) {
107
-    return str_replace("\n","<br />\n",$v);
107
+    return str_replace("\n", "<br />\n", $v);
108 108
   }
109 109
 
110 110
   static function replace($v, $src, $dst) {
111
-    return str_replace($src,$dst,$v);
111
+    return str_replace($src, $dst, $v);
112 112
   }
113 113
 
114 114
   static function ascents($v) {
115
-    $v = str_replace(['$',' ',','],'', $v);
116
-    return (int) round($v * 100,0);
115
+    $v = str_replace(['$', ' ', ','], '', $v);
116
+    return (int) round($v * 100, 0);
117 117
   }
118 118
 
119 119
 }
120 120
\ No newline at end of file
Please login to merge, or discard this patch.