@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | const FIND_DOLLARVAR = 0x02; |
52 | 52 | const FIND_BARDOLLAR = 0x04; |
53 | 53 | |
54 | - const START_RULE_MAP = [self::TOKEN_HTML => 'HtmlInput', self::TOKEN_CODE => 'CodeInput',self::TOKEN_CONTROL => 'ControlInput']; |
|
54 | + const START_RULE_MAP = [self::TOKEN_HTML => 'HtmlInput', self::TOKEN_CODE => 'CodeInput', self::TOKEN_CONTROL => 'ControlInput']; |
|
55 | 55 | |
56 | 56 | protected $mode; |
57 | 57 | |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | { |
62 | 62 | // var_dump($s); |
63 | 63 | $this->mode = $mode; |
64 | - $this->tree = (new Parser())->parse($s,['startRule' => self::START_RULE_MAP[$mode]]); |
|
64 | + $this->tree = (new Parser())->parse($s, ['startRule' => self::START_RULE_MAP[$mode]]); |
|
65 | 65 | // var_dump($this->tree); |
66 | - if(!$this->tree instanceof Doc) { |
|
66 | + if (!$this->tree instanceof Doc) { |
|
67 | 67 | $this->tree = new Doc(is_array($this->tree) ? $this->tree : [$this->tree]); |
68 | 68 | } |
69 | 69 | // $m = []; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | { |
115 | 115 | $func = $filter['func']; |
116 | 116 | if (method_exists(Filter::class, $func)) { |
117 | - $func = Filter::class . '::' . $func; |
|
117 | + $func = Filter::class.'::'.$func; |
|
118 | 118 | } elseif (in_array($func, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
119 | 119 | } elseif ($func === 'json') { |
120 | 120 | $func = 'json_encode'; |
@@ -124,14 +124,14 @@ discard block |
||
124 | 124 | throw new ParseError("Unknown Filter Type \"{$func}\""); |
125 | 125 | } |
126 | 126 | $args = join(',', array_map(function($v) { |
127 | - if(is_array($v) && $v['type'] ?? false === 'expr') { |
|
127 | + if (is_array($v) && $v['type'] ?? false === 'expr') { |
|
128 | 128 | return self::renderExpr($v); |
129 | 129 | } else |
130 | 130 | return self::varToCode($v); |
131 | 131 | } , $filter['args'])); |
132 | - if(strlen($args)) $args = ','.$args; |
|
133 | - $o = "$func($o" . $args . ")"; |
|
134 | - if($filter['chain'] ?? false) { |
|
132 | + if (strlen($args)) $args = ','.$args; |
|
133 | + $o = "$func($o".$args.")"; |
|
134 | + if ($filter['chain'] ?? false) { |
|
135 | 135 | $o = self::addFilter($o, $filter['chain']); |
136 | 136 | } |
137 | 137 | return $o; |
@@ -139,21 +139,21 @@ discard block |
||
139 | 139 | |
140 | 140 | static function renderScopeThis($n) |
141 | 141 | { |
142 | - $o = 'Hamle\Scope::get()->hamleGet(' . self::varToCode($n['name']) . ')'; |
|
142 | + $o = 'Hamle\Scope::get()->hamleGet('.self::varToCode($n['name']).')'; |
|
143 | 143 | $o = self::addParams($o, $n['param'] ?? []); |
144 | 144 | return $o; |
145 | 145 | } |
146 | 146 | |
147 | 147 | static function renderScopeId($n) |
148 | 148 | { |
149 | - $o = 'Hamle\Scope::get(' . $n['id'] . ')'; |
|
149 | + $o = 'Hamle\Scope::get('.$n['id'].')'; |
|
150 | 150 | $o = self::addParams($o, $n['param'] ?? []); |
151 | 151 | return $o; |
152 | 152 | } |
153 | 153 | |
154 | 154 | static function renderScopeName($n) |
155 | 155 | { |
156 | - $o = 'Hamle\Scope::getName(' . self::varToCode($n['name']) . ')'; |
|
156 | + $o = 'Hamle\Scope::getName('.self::varToCode($n['name']).')'; |
|
157 | 157 | $o = self::addParams($o, $n['param'] ?? []); |
158 | 158 | return $o; |
159 | 159 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | static function addParams(string $o, array $params) |
162 | 162 | { |
163 | 163 | while ($params['type'] ?? null === 'sub') { |
164 | - $o .= '->hamleGet(' . self::varToCode($params['name']) . ')'; |
|
164 | + $o .= '->hamleGet('.self::varToCode($params['name']).')'; |
|
165 | 165 | $params = $params['params'] ?? []; |
166 | 166 | } |
167 | 167 | return $o; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | static function addRel(string $o, array $query, string $rel): string |
171 | 171 | { |
172 | 172 | $r = $rel === 'child' ? Hamle::REL_CHILD : Hamle::REL_PARENT; |
173 | - $o = $o . "->hamleRel(" . self::varToCode($r) . ',' . self::queryParams($query, true) . ')'; |
|
173 | + $o = $o."->hamleRel(".self::varToCode($r).','.self::queryParams($query, true).')'; |
|
174 | 174 | return $o; |
175 | 175 | } |
176 | 176 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | self::varToCode($limit), |
231 | 231 | self::varToCode($offset) |
232 | 232 | ]; |
233 | - return 'Hamle\Run::modelTypeId(' . join(',', $opt) . ')'; |
|
233 | + return 'Hamle\Run::modelTypeId('.join(',', $opt).')'; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | static function renderQuery($n) |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | } elseif ($id !== null) { |
250 | 250 | $o = self::queryId($n['query']); |
251 | 251 | } else { |
252 | - $o = 'Hamle\Run::modelTypeTags(' . self::queryParams($n['query']) . ')'; |
|
252 | + $o = 'Hamle\Run::modelTypeTags('.self::queryParams($n['query']).')'; |
|
253 | 253 | } |
254 | 254 | if ($n['sub'] ?? []) { |
255 | 255 | $o = self::addRel($o, $n['sub'], $n['rel']); |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | $o = self::renderQuery($expr['body']); |
277 | 277 | break; |
278 | 278 | default: |
279 | - throw new \RuntimeException('Invalid Node: ' . $expr['body']['type']); |
|
279 | + throw new \RuntimeException('Invalid Node: '.$expr['body']['type']); |
|
280 | 280 | } |
281 | 281 | if ($expr['body']['filter'] ?? false) { |
282 | 282 | $o = self::addFilter($o, $expr['body']['filter']); |
@@ -295,16 +295,16 @@ discard block |
||
295 | 295 | $out .= $node['body']; |
296 | 296 | break; |
297 | 297 | case 'scopeName': |
298 | - $out .= '<?=' . self::renderScopeName($node) . '?>'; |
|
298 | + $out .= '<?='.self::renderScopeName($node).'?>'; |
|
299 | 299 | break; |
300 | 300 | case 'scopeThis': |
301 | - $out .= '<?=' . self::renderScopeThis($node) . '?>'; |
|
301 | + $out .= '<?='.self::renderScopeThis($node).'?>'; |
|
302 | 302 | break; |
303 | 303 | case 'expr': |
304 | - $out .= '<?=' . self::renderExpr($node) . "?>"; |
|
304 | + $out .= '<?='.self::renderExpr($node)."?>"; |
|
305 | 305 | break; |
306 | 306 | default: |
307 | - throw new \RuntimeException('Invalid Node:' . $node['type']); |
|
307 | + throw new \RuntimeException('Invalid Node:'.$node['type']); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | return $out; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $out [] = self::renderExpr($node); |
333 | 333 | break; |
334 | 334 | default: |
335 | - throw new \RuntimeException('Invalid Node:' . $node['type']); |
|
335 | + throw new \RuntimeException('Invalid Node:'.$node['type']); |
|
336 | 336 | } |
337 | 337 | } |
338 | 338 | return join('.', $out); |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | |
341 | 341 | function doEval() |
342 | 342 | { |
343 | - return eval('use Seufert\Hamle; return ' . $this->toPHP() . ';'); |
|
343 | + return eval('use Seufert\Hamle; return '.$this->toPHP().';'); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | static function varToCode($var) |
@@ -348,9 +348,9 @@ discard block |
||
348 | 348 | if (is_array($var)) { |
349 | 349 | $code = []; |
350 | 350 | foreach ($var as $key => $value) { |
351 | - $code[] = self::varToCode($key) . '=>' . self::varToCode($value); |
|
351 | + $code[] = self::varToCode($key).'=>'.self::varToCode($value); |
|
352 | 352 | } |
353 | - return 'array(' . implode(',', $code) . ')'; //remove unnecessary coma |
|
353 | + return 'array('.implode(',', $code).')'; //remove unnecessary coma |
|
354 | 354 | } |
355 | 355 | if (is_bool($var)) { |
356 | 356 | return ($var ? 'TRUE' : 'FALSE'); |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | if ($var instanceof Text) { |
362 | 362 | return $var->toPHP(); |
363 | 363 | } |
364 | - return "'" . str_replace(['$', "'"], ['$', "\\'"], $var) . "'"; |
|
364 | + return "'".str_replace(['$', "'"], ['$', "\\'"], $var)."'"; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | /** |
@@ -126,10 +126,13 @@ discard block |
||
126 | 126 | $args = join(',', array_map(function($v) { |
127 | 127 | if(is_array($v) && $v['type'] ?? false === 'expr') { |
128 | 128 | return self::renderExpr($v); |
129 | - } else |
|
130 | - return self::varToCode($v); |
|
129 | + } else { |
|
130 | + return self::varToCode($v); |
|
131 | + } |
|
131 | 132 | } , $filter['args'])); |
132 | - if(strlen($args)) $args = ','.$args; |
|
133 | + if(strlen($args)) { |
|
134 | + $args = ','.$args; |
|
135 | + } |
|
133 | 136 | $o = "$func($o" . $args . ")"; |
134 | 137 | if($filter['chain'] ?? false) { |
135 | 138 | $o = self::addFilter($o, $filter['chain']); |
@@ -202,8 +205,9 @@ discard block |
||
202 | 205 | self::varToCode($limit), |
203 | 206 | self::varToCode($offset) |
204 | 207 | ]; |
205 | - if ($addGroup) |
|
206 | - $opt[] = self::varToCode($group); |
|
208 | + if ($addGroup) { |
|
209 | + $opt[] = self::varToCode($group); |
|
210 | + } |
|
207 | 211 | return join(',', $opt); |
208 | 212 | } |
209 | 213 | |
@@ -239,10 +243,12 @@ discard block |
||
239 | 243 | $id = null; |
240 | 244 | $type = []; |
241 | 245 | foreach ($n['query'] ?? [] as $q) { |
242 | - if ($q['q'] === 'id') |
|
243 | - $id = $q['id'] ?? null; |
|
244 | - if ($q['q'] === 'type') |
|
245 | - $type = $q['id']; |
|
246 | + if ($q['q'] === 'id') { |
|
247 | + $id = $q['id'] ?? null; |
|
248 | + } |
|
249 | + if ($q['q'] === 'type') { |
|
250 | + $type = $q['id']; |
|
251 | + } |
|
246 | 252 | } |
247 | 253 | if ($n['query'] === null) { |
248 | 254 | $o = 'Hamle\Scope::get(0)'; |
@@ -291,8 +297,9 @@ discard block |
||
291 | 297 | foreach ($this->tree as $node) { |
292 | 298 | switch ($node['type']) { |
293 | 299 | case 'string': |
294 | - if ($node['body'] !== '') |
|
295 | - $out .= $node['body']; |
|
300 | + if ($node['body'] !== '') { |
|
301 | + $out .= $node['body']; |
|
302 | + } |
|
296 | 303 | break; |
297 | 304 | case 'scopeName': |
298 | 305 | $out .= '<?=' . self::renderScopeName($node) . '?>'; |
@@ -322,8 +329,9 @@ discard block |
||
322 | 329 | foreach ($this->tree as $node) { |
323 | 330 | switch ($node['type']) { |
324 | 331 | case 'string': |
325 | - if ($node['body'] !== '') |
|
326 | - $out[] = self::varToCode($node['body']); |
|
332 | + if ($node['body'] !== '') { |
|
333 | + $out[] = self::varToCode($node['body']); |
|
334 | + } |
|
327 | 335 | break; |
328 | 336 | case 'scopeThis': |
329 | 337 | $out[] = self::renderScopeThis($node); |
@@ -30,9 +30,9 @@ |
||
30 | 30 | |
31 | 31 | |
32 | 32 | public function toPHP():string { |
33 | - $o = "Hamle\\Scope::getName(" . Text::varToCode($this->name) . ")"; |
|
33 | + $o = "Hamle\\Scope::getName(".Text::varToCode($this->name).")"; |
|
34 | 34 | if ($this->immediate) $o = $this->immediate->apply($o); |
35 | - if($this->chain) $o = $this->chain->apply($o); |
|
35 | + if ($this->chain) $o = $this->chain->apply($o); |
|
36 | 36 | return $o; |
37 | 37 | } |
38 | 38 |
@@ -31,8 +31,12 @@ |
||
31 | 31 | |
32 | 32 | public function toPHP():string { |
33 | 33 | $o = "Hamle\\Scope::getName(" . Text::varToCode($this->name) . ")"; |
34 | - if ($this->immediate) $o = $this->immediate->apply($o); |
|
35 | - if($this->chain) $o = $this->chain->apply($o); |
|
34 | + if ($this->immediate) { |
|
35 | + $o = $this->immediate->apply($o); |
|
36 | + } |
|
37 | + if($this->chain) { |
|
38 | + $o = $this->chain->apply($o); |
|
39 | + } |
|
36 | 40 | return $o; |
37 | 41 | } |
38 | 42 |
@@ -23,8 +23,8 @@ |
||
23 | 23 | |
24 | 24 | public function apply(string $out): string |
25 | 25 | { |
26 | - $o = "{$out}->hamleGet(" . Text::varToCode($this->name) . ")"; |
|
27 | - if($this->chain) |
|
26 | + $o = "{$out}->hamleGet(".Text::varToCode($this->name).")"; |
|
27 | + if ($this->chain) |
|
28 | 28 | $o = $this->chain->apply($o); |
29 | 29 | return $o; |
30 | 30 | } |
@@ -24,8 +24,9 @@ |
||
24 | 24 | public function apply(string $out): string |
25 | 25 | { |
26 | 26 | $o = "{$out}->hamleGet(" . Text::varToCode($this->name) . ")"; |
27 | - if($this->chain) |
|
28 | - $o = $this->chain->apply($o); |
|
27 | + if($this->chain) { |
|
28 | + $o = $this->chain->apply($o); |
|
29 | + } |
|
29 | 30 | return $o; |
30 | 31 | } |
31 | 32 | } |
@@ -15,6 +15,6 @@ |
||
15 | 15 | |
16 | 16 | public function string(): string |
17 | 17 | { |
18 | - return (string)$this->int; |
|
18 | + return (string) $this->int; |
|
19 | 19 | } |
20 | 20 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | $this->chain = $chain; |
23 | 23 | $this->args = $args; |
24 | 24 | if (method_exists(Filter::class, $func)) { |
25 | - $this->func = Filter::class . '::' . $func; |
|
25 | + $this->func = Filter::class.'::'.$func; |
|
26 | 26 | } elseif (in_array($func, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) { |
27 | 27 | $this->func = $func; |
28 | 28 | } elseif ($func === 'json') { |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | { |
39 | 39 | $args = array_map(fn($v) => $v instanceof Literal ? Text::varToCode($v->string()) : $v->toPHP(), $this->args); |
40 | 40 | array_unshift($args, $out); |
41 | - $o = "{$this->func}(" . join(',', $args) . ")"; |
|
41 | + $o = "{$this->func}(".join(',', $args).")"; |
|
42 | 42 | if ($this->chain) $o = $this->chain->apply($o); |
43 | 43 | return $o; |
44 | 44 | } |
@@ -39,7 +39,9 @@ |
||
39 | 39 | $args = array_map(fn($v) => $v instanceof Literal ? Text::varToCode($v->string()) : $v->toPHP(), $this->args); |
40 | 40 | array_unshift($args, $out); |
41 | 41 | $o = "{$this->func}(" . join(',', $args) . ")"; |
42 | - if ($this->chain) $o = $this->chain->apply($o); |
|
42 | + if ($this->chain) { |
|
43 | + $o = $this->chain->apply($o); |
|
44 | + } |
|
43 | 45 | return $o; |
44 | 46 | } |
45 | 47 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | return join('.', $out); |
36 | 36 | } |
37 | 37 | |
38 | - public function toHtml(bool $escVar = false,bool $escFixed = true): string |
|
38 | + public function toHtml(bool $escVar = false, bool $escFixed = true): string |
|
39 | 39 | { |
40 | 40 | $out = []; |
41 | 41 | if ($escVar) { |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $code = false; |
54 | 54 | } |
55 | 55 | $s = $n->string(); |
56 | - if($escFixed) $s = htmlspecialchars($s); |
|
56 | + if ($escFixed) $s = htmlspecialchars($s); |
|
57 | 57 | $out[] = $s; |
58 | 58 | } else { |
59 | 59 | if (!$code) { |
@@ -53,7 +53,9 @@ discard block |
||
53 | 53 | $code = false; |
54 | 54 | } |
55 | 55 | $s = $n->string(); |
56 | - if($escFixed) $s = htmlspecialchars($s); |
|
56 | + if($escFixed) { |
|
57 | + $s = htmlspecialchars($s); |
|
58 | + } |
|
57 | 59 | $out[] = $s; |
58 | 60 | } else { |
59 | 61 | if (!$code) { |
@@ -63,7 +65,9 @@ discard block |
||
63 | 65 | $out[] = $n->toPHP(); |
64 | 66 | } |
65 | 67 | } |
66 | - if ($code) $out[] = $closeTag; |
|
68 | + if ($code) { |
|
69 | + $out[] = $closeTag; |
|
70 | + } |
|
67 | 71 | return join('', $out); |
68 | 72 | } |
69 | 73 | } |
@@ -36,8 +36,12 @@ |
||
36 | 36 | } else { |
37 | 37 | $o = "Hamle\\Scope::get({$this->id})"; |
38 | 38 | } |
39 | - if ($this->immediate) $o = $this->immediate->apply($o); |
|
40 | - if ($this->chain) $o = $this->chain->apply($o); |
|
39 | + if ($this->immediate) { |
|
40 | + $o = $this->immediate->apply($o); |
|
41 | + } |
|
42 | + if ($this->chain) { |
|
43 | + $o = $this->chain->apply($o); |
|
44 | + } |
|
41 | 45 | return $o; |
42 | 46 | } |
43 | 47 |
@@ -15,6 +15,6 @@ |
||
15 | 15 | |
16 | 16 | public function string(): string |
17 | 17 | { |
18 | - return (string)$this->float; |
|
18 | + return (string) $this->float; |
|
19 | 19 | } |
20 | 20 | } |
@@ -23,14 +23,14 @@ |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | |
26 | - static function for(string $rel, array $filters) { |
|
27 | - return new self($rel === '>'?Hamle::REL_CHILD:Hamle::REL_PARENT, $filters); |
|
26 | + static function for (string $rel, array $filters) { |
|
27 | + return new self($rel === '>' ?Hamle::REL_CHILD : Hamle::REL_PARENT, $filters); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function apply(string $s):string { |
31 | 31 | |
32 | - $s= $s."->hamleRel({$this->rel}," . Query::queryParams($this->filters, true) . ')'; |
|
33 | - if($this->chain) $s = $this->chain->apply($s); |
|
32 | + $s = $s."->hamleRel({$this->rel},".Query::queryParams($this->filters, true).')'; |
|
33 | + if ($this->chain) $s = $this->chain->apply($s); |
|
34 | 34 | return $s; |
35 | 35 | } |
36 | 36 |
@@ -30,7 +30,9 @@ |
||
30 | 30 | public function apply(string $s):string { |
31 | 31 | |
32 | 32 | $s= $s."->hamleRel({$this->rel}," . Query::queryParams($this->filters, true) . ')'; |
33 | - if($this->chain) $s = $this->chain->apply($s); |
|
33 | + if($this->chain) { |
|
34 | + $s = $this->chain->apply($s); |
|
35 | + } |
|
34 | 36 | return $s; |
35 | 37 | } |
36 | 38 |