@@ -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 |
@@ -31,15 +31,19 @@ discard block |
||
31 | 31 | |
32 | 32 | $type = $matches[2][$key]; $name = $matches[3][$key]; $contents = ($matches[4][$key] ?? ''); |
33 | 33 | |
34 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
34 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
35 | + continue; |
|
36 | + } |
|
35 | 37 | |
36 | 38 | $this->contents = str_replace($match, ('{ ' . $type . ':' . $name . ' / }'), $this->contents); |
37 | 39 | |
38 | - if ($type === 'block') $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
39 | - |
|
40 | - else if ($type === 'for') $this->loops[$name] = new Loop($contents); |
|
41 | - |
|
42 | - else if ($type === 'widget') $this->widgets[] = $name; |
|
40 | + if ($type === 'block') { |
|
41 | + $this->blocks[$name] = (new Block($contents))->$toggle(); |
|
42 | + } else if ($type === 'for') { |
|
43 | + $this->loops[$name] = new Loop($contents); |
|
44 | + } else if ($type === 'widget') { |
|
45 | + $this->widgets[] = $name; |
|
46 | + } |
|
43 | 47 | } |
44 | 48 | } |
45 | 49 | |
@@ -59,7 +63,9 @@ discard block |
||
59 | 63 | |
60 | 64 | foreach ($matches[1] as $index => $name) { |
61 | 65 | |
62 | - if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) continue; |
|
66 | + if (!preg_match(REGEX_TEMPLATE_COMPONENT_NAME, $name)) { |
|
67 | + continue; |
|
68 | + } |
|
63 | 69 | |
64 | 70 | $elementaries['stack'][$name] = false; |
65 | 71 | } |
@@ -143,11 +149,17 @@ discard block |
||
143 | 149 | |
144 | 150 | public function __clone() { |
145 | 151 | |
146 | - foreach ($this->blocks as $name => $block) $this->blocks[$name] = clone $block; |
|
152 | + foreach ($this->blocks as $name => $block) { |
|
153 | + $this->blocks[$name] = clone $block; |
|
154 | + } |
|
147 | 155 | |
148 | - foreach ($this->loops as $name => $loop) $this->loops[$name] = clone $loop; |
|
156 | + foreach ($this->loops as $name => $loop) { |
|
157 | + $this->loops[$name] = clone $loop; |
|
158 | + } |
|
149 | 159 | |
150 | - foreach ($this->items as $name => $item) $this->items[$name] = clone $item; |
|
160 | + foreach ($this->items as $name => $item) { |
|
161 | + $this->items[$name] = clone $item; |
|
162 | + } |
|
151 | 163 | } |
152 | 164 | |
153 | 165 | /** |
@@ -158,11 +170,13 @@ discard block |
||
158 | 170 | |
159 | 171 | public function set(string $name, $value) : Block { |
160 | 172 | |
161 | - if ($value instanceof Block) $this->setBlock($name, $value); |
|
162 | - |
|
163 | - else if (is_array($value)) $this->setLoop($name, $value); |
|
164 | - |
|
165 | - else if (is_scalar($value)) $this->setVar($name, $value); |
|
173 | + if ($value instanceof Block) { |
|
174 | + $this->setBlock($name, $value); |
|
175 | + } else if (is_array($value)) { |
|
176 | + $this->setLoop($name, $value); |
|
177 | + } else if (is_scalar($value)) { |
|
178 | + $this->setVar($name, $value); |
|
179 | + } |
|
166 | 180 | |
167 | 181 | # ------------------------ |
168 | 182 | |
@@ -177,7 +191,9 @@ discard block |
||
177 | 191 | |
178 | 192 | public function setArray(array $components) : Block { |
179 | 193 | |
180 | - foreach ($components as $name => $component) $this->set($name, $component); |
|
194 | + foreach ($components as $name => $component) { |
|
195 | + $this->set($name, $component); |
|
196 | + } |
|
181 | 197 | |
182 | 198 | return $this; |
183 | 199 | } |
@@ -190,7 +206,9 @@ discard block |
||
190 | 206 | |
191 | 207 | public function setBlock(string $name, Block $block) : Block { |
192 | 208 | |
193 | - if (isset($this->blocks[$name])) $this->blocks[$name] = $block; |
|
209 | + if (isset($this->blocks[$name])) { |
|
210 | + $this->blocks[$name] = $block; |
|
211 | + } |
|
194 | 212 | |
195 | 213 | return $this; |
196 | 214 | } |
@@ -203,7 +221,9 @@ discard block |
||
203 | 221 | |
204 | 222 | public function setLoop(string $name, array $items) : Block { |
205 | 223 | |
206 | - if (isset($this->loops[$name])) $this->loops[$name]->setItems($items); |
|
224 | + if (isset($this->loops[$name])) { |
|
225 | + $this->loops[$name]->setItems($items); |
|
226 | + } |
|
207 | 227 | |
208 | 228 | return $this; |
209 | 229 | } |
@@ -216,7 +236,9 @@ discard block |
||
216 | 236 | |
217 | 237 | public function setVar(string $name, string $value) : Block { |
218 | 238 | |
219 | - if (isset($this->variables[$name])) $this->variables[$name] = $value; |
|
239 | + if (isset($this->variables[$name])) { |
|
240 | + $this->variables[$name] = $value; |
|
241 | + } |
|
220 | 242 | |
221 | 243 | return $this; |
222 | 244 | } |
@@ -298,7 +320,9 @@ discard block |
||
298 | 320 | |
299 | 321 | public function getContents() : string { |
300 | 322 | |
301 | - if (!$this->enabled) return ''; |
|
323 | + if (!$this->enabled) { |
|
324 | + return ''; |
|
325 | + } |
|
302 | 326 | |
303 | 327 | # Lock the block |
304 | 328 |
@@ -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 |
@@ -19,9 +19,13 @@ discard block |
||
19 | 19 | |
20 | 20 | public static function validate(string $date, string $format) { |
21 | 21 | |
22 | - if (false === ($datetime = date_create_from_format($format, $date))) return false; |
|
22 | + if (false === ($datetime = date_create_from_format($format, $date))) { |
|
23 | + return false; |
|
24 | + } |
|
23 | 25 | |
24 | - if (false === ($formatted = $datetime->format($format))) return false; |
|
26 | + if (false === ($formatted = $datetime->format($format))) { |
|
27 | + return false; |
|
28 | + } |
|
25 | 29 | |
26 | 30 | # ------------------------ |
27 | 31 | |
@@ -58,7 +62,9 @@ discard block |
||
58 | 62 | |
59 | 63 | public static function validateYear(int $year) { |
60 | 64 | |
61 | - if (false === ($year = self::validate($year, 'Y'))) return false; |
|
65 | + if (false === ($year = self::validate($year, 'Y'))) { |
|
66 | + return false; |
|
67 | + } |
|
62 | 68 | |
63 | 69 | return (($year > '1900') ? (($year > self::getYear()) ? self::getYear() : $year) : '1900'); |
64 | 70 | } |
@@ -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 |
@@ -19,18 +19,24 @@ |
||
19 | 19 | |
20 | 20 | public function __construct(string $url = '') { |
21 | 21 | |
22 | - if (false === ($url = parse_url($url))) return; |
|
22 | + if (false === ($url = parse_url($url))) { |
|
23 | + return; |
|
24 | + } |
|
23 | 25 | |
24 | 26 | # Parse path |
25 | 27 | |
26 | - if (isset($url['path'])) foreach (explode('/', $url['path']) as $part) { |
|
28 | + if (isset($url['path'])) { |
|
29 | + foreach (explode('/', $url['path']) as $part) { |
|
27 | 30 | |
28 | 31 | if ('' !== $part) $this->path[] = urldecode($part); |
29 | 32 | } |
33 | + } |
|
30 | 34 | |
31 | 35 | # Parse query |
32 | 36 | |
33 | - if (isset($url['query'])) parse_str($url['query'], $this->query); |
|
37 | + if (isset($url['query'])) { |
|
38 | + parse_str($url['query'], $this->query); |
|
39 | + } |
|
34 | 40 | } |
35 | 41 | |
36 | 42 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | public function getPath() : string { |
74 | 74 | |
75 | - return ('/' . implode('/', array_map('urlencode', $this->path))); |
|
75 | + return ('/'.implode('/', array_map('urlencode', $this->path))); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | public function getQuery() : string { |
83 | 83 | |
84 | - return (($query = http_build_query($this->query)) ? ('?' . $query) : ''); |
|
84 | + return (($query = http_build_query($this->query)) ? ('?'.$query) : ''); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | public function getString(bool $include_query = true) : string { |
110 | 110 | |
111 | - return ($this->getPath() . ($include_query ? $this->getQuery() : '')); |
|
111 | + return ($this->getPath().($include_query ? $this->getQuery() : '')); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
@@ -47,10 +47,10 @@ |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | - * Get a query attribute |
|
51 | - * |
|
52 | - * @return string|false : the value or false if the attribute does not exist |
|
53 | - */ |
|
50 | + * Get a query attribute |
|
51 | + * |
|
52 | + * @return string|false : the value or false if the attribute does not exist |
|
53 | + */ |
|
54 | 54 | |
55 | 55 | public function getAttribute(string $name) { |
56 | 56 |
@@ -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; |
@@ -53,7 +53,9 @@ |
||
53 | 53 | |
54 | 54 | $tag->setAttribute('type', 'checkbox'); |
55 | 55 | |
56 | - if ($this->value) $tag->setAttribute('checked', 'checked'); |
|
56 | + if ($this->value) { |
|
57 | + $tag->setAttribute('checked', 'checked'); |
|
58 | + } |
|
57 | 59 | |
58 | 60 | # ------------------------ |
59 | 61 |
@@ -31,9 +31,9 @@ |
||
31 | 31 | |
32 | 32 | if (preg_match(REGEX_FORM_FIELD_KEY, $key)) { |
33 | 33 | |
34 | - $prefix = (('' !== $this->form->getName()) ? ($this->form->getName() . '_') : ''); |
|
34 | + $prefix = (('' !== $this->form->getName()) ? ($this->form->getName().'_') : ''); |
|
35 | 35 | |
36 | - $this->key = $key; $this->name = ($prefix . $key); $this->id = str_replace('_', '-', $this->name); |
|
36 | + $this->key = $key; $this->name = ($prefix.$key); $this->id = str_replace('_', '-', $this->name); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | # Set configuration |
@@ -57,11 +57,17 @@ discard block |
||
57 | 57 | |
58 | 58 | # Set appearance |
59 | 59 | |
60 | - if ($this->disabled) $data['disabled'] = 'disabled'; |
|
60 | + if ($this->disabled) { |
|
61 | + $data['disabled'] = 'disabled'; |
|
62 | + } |
|
61 | 63 | |
62 | - if ($this->required) $data['data-required'] = 'required'; |
|
64 | + if ($this->required) { |
|
65 | + $data['data-required'] = 'required'; |
|
66 | + } |
|
63 | 67 | |
64 | - if ($this->error) $data['data-error'] = 'error'; |
|
68 | + if ($this->error) { |
|
69 | + $data['data-error'] = 'error'; |
|
70 | + } |
|
65 | 71 | |
66 | 72 | # ------------------------ |
67 | 73 | |
@@ -76,7 +82,9 @@ discard block |
||
76 | 82 | |
77 | 83 | public function post() : bool { |
78 | 84 | |
79 | - if ($this->posted || $this->disabled || ('' === $this->key)) return false; |
|
85 | + if ($this->posted || $this->disabled || ('' === $this->key)) { |
|
86 | + return false; |
|
87 | + } |
|
80 | 88 | |
81 | 89 | $this->error = (!$this->setValue(Request::post($this->name)) && $this->required); |
82 | 90 |