@@ -17,7 +17,7 @@ |
||
17 | 17 | |
18 | 18 | protected function getValue(string $value) { |
19 | 19 | |
20 | - return ('\'' . addslashes($value) . '\''); |
|
20 | + return ('\''.addslashes($value).'\''); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | # Get field sort |
@@ -31,7 +31,9 @@ discard block |
||
31 | 31 | |
32 | 32 | protected function getString($source = null, string $pattern = '', string $separator = '') { |
33 | 33 | |
34 | - if (!is_array($source)) return (is_scalar($source) ? strval($source) : ''); |
|
34 | + if (!is_array($source)) { |
|
35 | + return (is_scalar($source) ? strval($source) : ''); |
|
36 | + } |
|
35 | 37 | |
36 | 38 | $regexs = ['key' => '/\^([a-z]+)/', 'value' => '/\$([a-z]+)/']; $matches = ['key' => [], 'value' => []]; |
37 | 39 | |
@@ -39,18 +41,25 @@ discard block |
||
39 | 41 | |
40 | 42 | # Parse pattern |
41 | 43 | |
42 | - foreach ($regexs as $name => $regex) preg_match($regex, $pattern, $matches[$name]); |
|
44 | + foreach ($regexs as $name => $regex) { |
|
45 | + preg_match($regex, $pattern, $matches[$name]); |
|
46 | + } |
|
43 | 47 | |
44 | 48 | # Process replacements |
45 | 49 | |
46 | - foreach ($source as $key => $value) if (is_scalar($value)) { |
|
50 | + foreach ($source as $key => $value) { |
|
51 | + if (is_scalar($value)) { |
|
47 | 52 | |
48 | - $output[$count] = $pattern; $item = &$output[$count++]; |
|
53 | + $output[$count] = $pattern; |
|
54 | + } |
|
55 | + $item = &$output[$count++]; |
|
49 | 56 | |
50 | - foreach ($matches as $name => $match) if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
57 | + foreach ($matches as $name => $match) { |
|
58 | + if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
51 | 59 | |
52 | 60 | $item = str_replace($match[0], [$this, $parsers[$match[1]]]($$name), $item); |
53 | 61 | } |
62 | + } |
|
54 | 63 | }; |
55 | 64 | |
56 | 65 | # ------------------------ |
@@ -56,7 +56,9 @@ discard block |
||
56 | 56 | |
57 | 57 | public function getRow() { |
58 | 58 | |
59 | - if (!is_object($this->result)) return null; |
|
59 | + if (!is_object($this->result)) { |
|
60 | + return null; |
|
61 | + } |
|
60 | 62 | |
61 | 63 | return mysqli_fetch_assoc($this->result); |
62 | 64 | } |
@@ -67,9 +69,13 @@ discard block |
||
67 | 69 | |
68 | 70 | public function getRows() { |
69 | 71 | |
70 | - if (!is_object($this->result)) return []; |
|
72 | + if (!is_object($this->result)) { |
|
73 | + return []; |
|
74 | + } |
|
71 | 75 | |
72 | - $rows = []; while (null !== ($row = $this->getRow())) $rows[] = $row; |
|
76 | + $rows = []; while (null !== ($row = $this->getRow())) { |
|
77 | + $rows[] = $row; |
|
78 | + } |
|
73 | 79 | |
74 | 80 | # ------------------------ |
75 | 81 |
@@ -36,7 +36,9 @@ |
||
36 | 36 | |
37 | 37 | public function addItems(array $items) { |
38 | 38 | |
39 | - foreach ($items as $item) if (is_array($item)) $this->addItem($item); |
|
39 | + foreach ($items as $item) { |
|
40 | + if (is_array($item)) $this->addItem($item); |
|
41 | + } |
|
40 | 42 | |
41 | 43 | return $this; |
42 | 44 | } |
@@ -95,7 +95,9 @@ |
||
95 | 95 | |
96 | 96 | public static function output(Template\Block $block, int $status = STATUS_CODE_200) { |
97 | 97 | |
98 | - if (!Headers::isStatusCode($status)) $status = STATUS_CODE_200; |
|
98 | + if (!Headers::isStatusCode($status)) { |
|
99 | + $status = STATUS_CODE_200; |
|
100 | + } |
|
99 | 101 | |
100 | 102 | Headers::sendNoCache(); Headers::sendStatus($status); Headers::sendContent(MIME_TYPE_HTML); |
101 | 103 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
37 | 37 | |
38 | - $this->contents = str_replace($match, ('{ ' . $type . ':' . $name . ' / }'), $this->contents); |
|
38 | + $this->contents = str_replace($match, ('{ '.$type.':'.$name.' / }'), $this->contents); |
|
39 | 39 | |
40 | 40 | if ($type === 'block') $this->blocks[$name] = (new Block($contents))->$toggle(); |
41 | 41 | |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | |
52 | 52 | private function parseElementaries() { |
53 | 53 | |
54 | - $variables = ['pattern' => REGEX_TEMPLATE_VARIABLE, 'stack' => &$this->variables ]; |
|
54 | + $variables = ['pattern' => REGEX_TEMPLATE_VARIABLE, 'stack' => &$this->variables]; |
|
55 | 55 | |
56 | - $phrases = ['pattern' => REGEX_TEMPLATE_PHRASE, 'stack' => &$this->phrases ]; |
|
56 | + $phrases = ['pattern' => REGEX_TEMPLATE_PHRASE, 'stack' => &$this->phrases]; |
|
57 | 57 | |
58 | 58 | foreach ([$variables, $phrases] as $elementaries) { |
59 | 59 | |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | |
81 | 81 | foreach ($this->blocks as $name => $block) { |
82 | 82 | |
83 | - $insertions['{ block:' . $name . ' / }'] = $block->getContents(); |
|
83 | + $insertions['{ block:'.$name.' / }'] = $block->getContents(); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | # Process loops |
87 | 87 | |
88 | 88 | foreach ($this->loops as $name => $loop) { |
89 | 89 | |
90 | - $insertions['{ for:' . $name . ' / }'] = $loop->getContents(); |
|
90 | + $insertions['{ for:'.$name.' / }'] = $loop->getContents(); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | # Process widgets |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | $contents = ((false !== $widget) ? $widget->getContents() : ''); |
100 | 100 | |
101 | - $insertions['{ widget:' . $name . ' / }'] = $contents; |
|
101 | + $insertions['{ widget:'.$name.' / }'] = $contents; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | # Process variables |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | $value = ((false === $value) ? Template::getGlobal($name) : $value); |
109 | 109 | |
110 | - $insertions['$' . $name . '$'] = Str::formatOutput($value); |
|
110 | + $insertions['$'.$name.'$'] = Str::formatOutput($value); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | # Process phrases |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | $value = Language::get($name); |
118 | 118 | |
119 | - $insertions['%' . $name . '%'] = Str::formatOutput($value); |
|
119 | + $insertions['%'.$name.'%'] = Str::formatOutput($value); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | # Process insertions |
@@ -33,15 +33,19 @@ discard block |
||
33 | 33 | |
34 | 34 | $type = $matches[2][$key]; $name = $matches[3][$key]; $contents = ($matches[4][$key] ?? ''); |
35 | 35 | |
36 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
36 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
37 | + continue; |
|
38 | + } |
|
37 | 39 | |
38 | 40 | $this->contents = str_replace($match, ('{ ' . $type . ':' . $name . ' / }'), $this->contents); |
39 | 41 | |
40 | - if ($type === 'block') $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
41 | - |
|
42 | - else if ($type === 'for') $this->loops[$name] = new Loop($contents); |
|
43 | - |
|
44 | - else if ($type === 'widget') $this->widgets[] = $name; |
|
42 | + if ($type === 'block') { |
|
43 | + $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
44 | + } else if ($type === 'for') { |
|
45 | + $this->loops[$name] = new Loop($contents); |
|
46 | + } else if ($type === 'widget') { |
|
47 | + $this->widgets[] = $name; |
|
48 | + } |
|
45 | 49 | } |
46 | 50 | } |
47 | 51 | |
@@ -61,7 +65,9 @@ discard block |
||
61 | 65 | |
62 | 66 | foreach ($matches[1] as $index => $name) { |
63 | 67 | |
64 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
68 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
69 | + continue; |
|
70 | + } |
|
65 | 71 | |
66 | 72 | $elementaries['stack'][$name] = false; |
67 | 73 | } |
@@ -138,7 +144,9 @@ discard block |
||
138 | 144 | |
139 | 145 | # Process items |
140 | 146 | |
141 | - foreach ($this->items as $block) $contents .= $block->getContents(); |
|
147 | + foreach ($this->items as $block) { |
|
148 | + $contents .= $block->getContents(); |
|
149 | + } |
|
142 | 150 | |
143 | 151 | # ------------------------ |
144 | 152 | |
@@ -177,7 +185,9 @@ discard block |
||
177 | 185 | |
178 | 186 | public function addItems(array $items) : Block { |
179 | 187 | |
180 | - foreach ($items as $item) if ($item instanceof Block) $this->addItem($item); |
|
188 | + foreach ($items as $item) { |
|
189 | + if ($item instanceof Block) $this->addItem($item); |
|
190 | + } |
|
181 | 191 | |
182 | 192 | return $this; |
183 | 193 | } |
@@ -203,11 +213,13 @@ discard block |
||
203 | 213 | |
204 | 214 | public function set(string $name, $value) : Block { |
205 | 215 | |
206 | - if ($value instanceof Block) $this->setBlock($name, $value); |
|
207 | - |
|
208 | - else if (is_array($value)) $this->setLoop($name, $value); |
|
209 | - |
|
210 | - else if (is_scalar($value)) $this->setVar($name, $value); |
|
216 | + if ($value instanceof Block) { |
|
217 | + $this->setBlock($name, $value); |
|
218 | + } else if (is_array($value)) { |
|
219 | + $this->setLoop($name, $value); |
|
220 | + } else if (is_scalar($value)) { |
|
221 | + $this->setVar($name, $value); |
|
222 | + } |
|
211 | 223 | |
212 | 224 | # ------------------------ |
213 | 225 | |
@@ -222,7 +234,9 @@ discard block |
||
222 | 234 | |
223 | 235 | public function setArray(array $components) : Block { |
224 | 236 | |
225 | - foreach ($components as $name => $component) $this->set($name, $component); |
|
237 | + foreach ($components as $name => $component) { |
|
238 | + $this->set($name, $component); |
|
239 | + } |
|
226 | 240 | |
227 | 241 | return $this; |
228 | 242 | } |
@@ -235,7 +249,9 @@ discard block |
||
235 | 249 | |
236 | 250 | public function setBlock(string $name, Block $block) : Block { |
237 | 251 | |
238 | - if (isset($this->blocks[$name])) $this->blocks[$name] = $block; |
|
252 | + if (isset($this->blocks[$name])) { |
|
253 | + $this->blocks[$name] = $block; |
|
254 | + } |
|
239 | 255 | |
240 | 256 | return $this; |
241 | 257 | } |
@@ -248,7 +264,9 @@ discard block |
||
248 | 264 | |
249 | 265 | public function setLoop(string $name, array $items) : Block { |
250 | 266 | |
251 | - if (isset($this->loops[$name])) $this->loops[$name]->setItems($items); |
|
267 | + if (isset($this->loops[$name])) { |
|
268 | + $this->loops[$name]->setItems($items); |
|
269 | + } |
|
252 | 270 | |
253 | 271 | return $this; |
254 | 272 | } |
@@ -261,7 +279,9 @@ discard block |
||
261 | 279 | |
262 | 280 | public function setVar(string $name, string $value) : Block { |
263 | 281 | |
264 | - if (isset($this->variables[$name])) $this->variables[$name] = $value; |
|
282 | + if (isset($this->variables[$name])) { |
|
283 | + $this->variables[$name] = $value; |
|
284 | + } |
|
265 | 285 | |
266 | 286 | return $this; |
267 | 287 | } |
@@ -374,7 +394,9 @@ discard block |
||
374 | 394 | |
375 | 395 | public function getContents() : string { |
376 | 396 | |
377 | - if (!$this->enabled) return ''; |
|
397 | + if (!$this->enabled) { |
|
398 | + return ''; |
|
399 | + } |
|
378 | 400 | |
379 | 401 | # Lock the block |
380 | 402 | |
@@ -434,11 +456,17 @@ discard block |
||
434 | 456 | |
435 | 457 | public function __clone() { |
436 | 458 | |
437 | - foreach ($this->blocks as $name => $block) $this->blocks[$name] = clone $block; |
|
459 | + foreach ($this->blocks as $name => $block) { |
|
460 | + $this->blocks[$name] = clone $block; |
|
461 | + } |
|
438 | 462 | |
439 | - foreach ($this->loops as $name => $loop) $this->loops[$name] = clone $loop; |
|
463 | + foreach ($this->loops as $name => $loop) { |
|
464 | + $this->loops[$name] = clone $loop; |
|
465 | + } |
|
440 | 466 | |
441 | - foreach ($this->items as $name => $item) $this->items[$name] = clone $item; |
|
467 | + foreach ($this->items as $name => $item) { |
|
468 | + $this->items[$name] = clone $item; |
|
469 | + } |
|
442 | 470 | } |
443 | 471 | |
444 | 472 | /** |
@@ -19,7 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | public static function start(string $name, int $lifetime) { |
21 | 21 | |
22 | - if (session_id()) return true; |
|
22 | + if (session_id()) { |
|
23 | + return true; |
|
24 | + } |
|
23 | 25 | |
24 | 26 | ini_set('session.gc_maxlifetime', $lifetime); |
25 | 27 | |
@@ -47,7 +49,9 @@ discard block |
||
47 | 49 | |
48 | 50 | public static function set(string $name, $value) { |
49 | 51 | |
50 | - if (session_id()) $_SESSION[$name] = $value; |
|
52 | + if (session_id()) { |
|
53 | + $_SESSION[$name] = $value; |
|
54 | + } |
|
51 | 55 | } |
52 | 56 | |
53 | 57 | /** |
@@ -76,7 +80,9 @@ discard block |
||
76 | 80 | |
77 | 81 | public static function delete(string $name) { |
78 | 82 | |
79 | - if (isset($_SESSION[$name])) unset($_SESSION[$name]); |
|
83 | + if (isset($_SESSION[$name])) { |
|
84 | + unset($_SESSION[$name]); |
|
85 | + } |
|
80 | 86 | } |
81 | 87 | } |
82 | 88 | } |
@@ -22,7 +22,12 @@ discard block |
||
22 | 22 | |
23 | 23 | $value = null; |
24 | 24 | |
25 | - foreach ($path as $item) if (isset($array[$item])) $value = ($array = $array[$item]); else return null; |
|
25 | + foreach ($path as $item) { |
|
26 | + if (isset($array[$item])) $value = ($array = $array[$item]); |
|
27 | + } |
|
28 | + else { |
|
29 | + return null; |
|
30 | + } |
|
26 | 31 | |
27 | 32 | # ------------------------ |
28 | 33 | |
@@ -38,7 +43,9 @@ discard block |
||
38 | 43 | |
39 | 44 | $selected = array_intersect_key($array, array_flip($keys)); |
40 | 45 | |
41 | - if (null !== $filter) $selected = array_filter($array, $filter); |
|
46 | + if (null !== $filter) { |
|
47 | + $selected = array_filter($array, $filter); |
|
48 | + } |
|
42 | 49 | |
43 | 50 | # ------------------------ |
44 | 51 | |
@@ -54,7 +61,9 @@ discard block |
||
54 | 61 | |
55 | 62 | $indexed = []; |
56 | 63 | |
57 | - foreach ($array as $key => $value) $indexed[] = [$key_name => $key, $value_name => $value]; |
|
64 | + foreach ($array as $key => $value) { |
|
65 | + $indexed[] = [$key_name => $key, $value_name => $value]; |
|
66 | + } |
|
58 | 67 | |
59 | 68 | # ------------------------ |
60 | 69 | |
@@ -71,9 +80,15 @@ discard block |
||
71 | 80 | |
72 | 81 | $sorted = []; $column = array_map($select_key, $array); |
73 | 82 | |
74 | - if (!$descending) asort($column); else arsort($column); |
|
83 | + if (!$descending) { |
|
84 | + asort($column); |
|
85 | + } else { |
|
86 | + arsort($column); |
|
87 | + } |
|
75 | 88 | |
76 | - foreach (array_keys($column) as $key) $sorted[$key] = $array[$key]; |
|
89 | + foreach (array_keys($column) as $key) { |
|
90 | + $sorted[$key] = $array[$key]; |
|
91 | + } |
|
77 | 92 | |
78 | 93 | # ------------------------ |
79 | 94 |
@@ -21,7 +21,9 @@ discard block |
||
21 | 21 | |
22 | 22 | public function set(string $name, $value) { |
23 | 23 | |
24 | - if (!in_array($name, ['error', 'status'], true)) $this->data[$name] = $value; |
|
24 | + if (!in_array($name, ['error', 'status'], true)) { |
|
25 | + $this->data[$name] = $value; |
|
26 | + } |
|
25 | 27 | |
26 | 28 | return $this; |
27 | 29 | } |
@@ -82,7 +84,9 @@ discard block |
||
82 | 84 | |
83 | 85 | $data = ['status' => $this->status]; |
84 | 86 | |
85 | - if (null !== $this->error) $data['error'] = $this->error; |
|
87 | + if (null !== $this->error) { |
|
88 | + $data['error'] = $this->error; |
|
89 | + } |
|
86 | 90 | |
87 | 91 | # ------------------------ |
88 | 92 |
@@ -181,7 +181,7 @@ |
||
181 | 181 | |
182 | 182 | foreach ($this->fields as $field) { |
183 | 183 | |
184 | - $block->setBlock(('field_' . $field->getName()), $field->getBlock()); |
|
184 | + $block->setBlock(('field_'.$field->getName()), $field->getBlock()); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | } |
@@ -23,7 +23,9 @@ discard block |
||
23 | 23 | |
24 | 24 | private function addField(Form\Field $field) { |
25 | 25 | |
26 | - if ($this->posted || ('' === ($key = $field->getKey()))) return false; |
|
26 | + if ($this->posted || ('' === ($key = $field->getKey()))) { |
|
27 | + return false; |
|
28 | + } |
|
27 | 29 | |
28 | 30 | $this->fields[$key] = $field; |
29 | 31 | |
@@ -38,7 +40,9 @@ discard block |
||
38 | 40 | |
39 | 41 | public function __construct(string $name = '') { |
40 | 42 | |
41 | - if (preg_match(REGEX_FORM_NAME, $name)) $this->name = $name; |
|
43 | + if (preg_match(REGEX_FORM_NAME, $name)) { |
|
44 | + $this->name = $name; |
|
45 | + } |
|
42 | 46 | } |
43 | 47 | |
44 | 48 | /** |
@@ -90,9 +94,15 @@ discard block |
||
90 | 94 | |
91 | 95 | foreach ($this->fields as $field) { |
92 | 96 | |
93 | - if (($field instanceof Form\Field\Checkbox) || $field->disabled) continue; |
|
97 | + if (($field instanceof Form\Field\Checkbox) || $field->disabled) { |
|
98 | + continue; |
|
99 | + } |
|
94 | 100 | |
95 | - if (false !== Request::post($field->getName())) $check = true; else return false; |
|
101 | + if (false !== Request::post($field->getName())) { |
|
102 | + $check = true; |
|
103 | + } else { |
|
104 | + return false; |
|
105 | + } |
|
96 | 106 | } |
97 | 107 | |
98 | 108 | # ------------------------ |
@@ -108,7 +118,9 @@ discard block |
||
108 | 118 | |
109 | 119 | public function post() { |
110 | 120 | |
111 | - if ($this->posted || !$this->check()) return false; |
|
121 | + if ($this->posted || !$this->check()) { |
|
122 | + return false; |
|
123 | + } |
|
112 | 124 | |
113 | 125 | $post = []; $errors = false; |
114 | 126 | |
@@ -116,7 +128,9 @@ discard block |
||
116 | 128 | |
117 | 129 | $field->post(); $post[$field->getKey()] = $field->getValue(); |
118 | 130 | |
119 | - if ($field->error) $errors = true; |
|
131 | + if ($field->error) { |
|
132 | + $errors = true; |
|
133 | + } |
|
120 | 134 | } |
121 | 135 | |
122 | 136 | $this->posted = true; $this->errors = $errors; |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * Add a field to the form |
20 | 20 | * |
21 | - * @return true if the field was successfully added, otherwise false |
|
21 | + * @return boolean if the field was successfully added, otherwise false |
|
22 | 22 | */ |
23 | 23 | |
24 | 24 | private function addField(Form\Field $field) : bool { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | /** |
45 | 45 | * Add a text field |
46 | 46 | * |
47 | - * @return true if the field was successfully added, otherwise false |
|
47 | + * @return boolean if the field was successfully added, otherwise false |
|
48 | 48 | */ |
49 | 49 | |
50 | 50 | public function addText(string $key, string $value = '', |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * Add a select field |
59 | 59 | * |
60 | - * @return true if the field was successfully added, otherwise false |
|
60 | + * @return boolean if the field was successfully added, otherwise false |
|
61 | 61 | */ |
62 | 62 | |
63 | 63 | public function addSelect(string $key, string $value = '', |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * Add a checkbox field |
72 | 72 | * |
73 | - * @return true if the field was successfully added, otherwise false |
|
73 | + * @return boolean if the field was successfully added, otherwise false |
|
74 | 74 | */ |
75 | 75 | |
76 | 76 | public function addCheckbox(string $key, string $value = '') : bool { |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * Check if valid POST data has been recieved |
83 | 83 | * |
84 | - * @return true if the data has been recieved, otherwise false |
|
84 | + * @return boolean if the data has been recieved, otherwise false |
|
85 | 85 | */ |
86 | 86 | |
87 | 87 | public function check() : bool { |