@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | * @return mixed |
27 | 27 | * @throws Exception |
28 | 28 | */ |
29 | - public function __get( $property ) |
|
29 | + public function __get($property) |
|
30 | 30 | { |
31 | - switch( $property ) { |
|
31 | + switch ($property) { |
|
32 | 32 | case 'args'; |
33 | 33 | case 'dependencies'; |
34 | 34 | return $this->$property; |
35 | 35 | } |
36 | - throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property )); |
|
36 | + throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property)); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | |
@@ -42,19 +42,19 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return mixed GeminiLabs\SiteReviews\Html\Fields\* |
44 | 44 | */ |
45 | - public function getField( array $args = [] ) |
|
45 | + public function getField(array $args = []) |
|
46 | 46 | { |
47 | - if( empty( $args )) { |
|
47 | + if (empty($args)) { |
|
48 | 48 | $args = $this->args; |
49 | 49 | } |
50 | 50 | |
51 | - $className = sprintf( 'GeminiLabs\Castor\Forms\Fields\%s', ucfirst( $args['type'] )); |
|
51 | + $className = sprintf('GeminiLabs\Castor\Forms\Fields\%s', ucfirst($args['type'])); |
|
52 | 52 | |
53 | - if( !class_exists( $className )) { |
|
54 | - throw new ReflectionException( "Class does not exist: {$className}" ); |
|
53 | + if (!class_exists($className)) { |
|
54 | + throw new ReflectionException("Class does not exist: {$className}"); |
|
55 | 55 | } |
56 | 56 | |
57 | - return (new $className( $args )); |
|
57 | + return (new $className($args)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return $this |
64 | 64 | */ |
65 | - public function normalize( array $args = [] ) |
|
65 | + public function normalize(array $args = []) |
|
66 | 66 | { |
67 | 67 | $defaults = [ |
68 | 68 | 'after' => '', |
@@ -86,23 +86,23 @@ discard block |
||
86 | 86 | 'value' => '', |
87 | 87 | ]; |
88 | 88 | |
89 | - $args = $atts = wp_parse_args( $args, $defaults ); |
|
89 | + $args = $atts = wp_parse_args($args, $defaults); |
|
90 | 90 | |
91 | - $args['attributes'] = $this->parseAttributes( $atts ); |
|
92 | - $args['id'] = $this->parseId( $atts ); |
|
93 | - $args['inline'] = $this->parseInline( $atts ); |
|
94 | - $args['type'] = $this->parseType( $atts ); |
|
95 | - $args['name'] = $this->parseName( $atts ); |
|
91 | + $args['attributes'] = $this->parseAttributes($atts); |
|
92 | + $args['id'] = $this->parseId($atts); |
|
93 | + $args['inline'] = $this->parseInline($atts); |
|
94 | + $args['type'] = $this->parseType($atts); |
|
95 | + $args['name'] = $this->parseName($atts); |
|
96 | 96 | $args['options'] = (array) $atts['options']; // make sure this is always an array |
97 | 97 | $args['path'] = $atts['name']; |
98 | - $args['prefix'] = $this->parsePrefix( $atts ); |
|
99 | - $args['value'] = $this->parseValue( $atts ); |
|
98 | + $args['prefix'] = $this->parsePrefix($atts); |
|
99 | + $args['value'] = $this->parseValue($atts); |
|
100 | 100 | |
101 | 101 | $this->args = $args; |
102 | - $this->dependencies = $this->getField( $args )->dependencies; |
|
102 | + $this->dependencies = $this->getField($args)->dependencies; |
|
103 | 103 | |
104 | 104 | $this->setDataDepends(); |
105 | - $this->checkForErrors( $atts ); |
|
105 | + $this->checkForErrors($atts); |
|
106 | 106 | |
107 | 107 | return $this; |
108 | 108 | } |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return string|void |
116 | 116 | */ |
117 | - public function render( $print = true ) |
|
117 | + public function render($print = true) |
|
118 | 118 | { |
119 | - if( $this->args['render'] === false )return; |
|
119 | + if ($this->args['render'] === false)return; |
|
120 | 120 | |
121 | 121 | $field = $this->getField(); |
122 | 122 | |
@@ -125,16 +125,16 @@ discard block |
||
125 | 125 | |
126 | 126 | $renderedString = '%s'; |
127 | 127 | |
128 | - if( ( isset( $field->args['required'] ) && $field->args['required'] ) |
|
129 | - || ( isset( $field->args['attributes']['required'] ) || in_array( 'required', $field->args['attributes'] )) ) { |
|
128 | + if ((isset($field->args['required']) && $field->args['required']) |
|
129 | + || (isset($field->args['attributes']['required']) || in_array('required', $field->args['attributes']))) { |
|
130 | 130 | $class .= ' glsr-required'; |
131 | 131 | } |
132 | 132 | |
133 | - if( $field->args['type'] !== 'hidden' ) { |
|
134 | - $renderedString = sprintf( '<div class="%s">%%s</div>', $class ); |
|
133 | + if ($field->args['type'] !== 'hidden') { |
|
134 | + $renderedString = sprintf('<div class="%s">%%s</div>', $class); |
|
135 | 135 | } |
136 | 136 | |
137 | - $rendered = sprintf( $renderedString, |
|
137 | + $rendered = sprintf($renderedString, |
|
138 | 138 | $this->args['before'] . |
139 | 139 | $field->generateLabel() . |
140 | 140 | $field->render() . |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | $this->args['errors'] |
143 | 143 | ); |
144 | 144 | |
145 | - $rendered = apply_filters( 'castor/rendered/field', $rendered, $field->args['type'] ); |
|
145 | + $rendered = apply_filters('castor/rendered/field', $rendered, $field->args['type']); |
|
146 | 146 | |
147 | - if( !!$print && $print !== 'return' ) { |
|
147 | + if (!!$print && $print !== 'return') { |
|
148 | 148 | echo $rendered; |
149 | 149 | } |
150 | 150 | |
@@ -168,22 +168,22 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return void |
170 | 170 | */ |
171 | - protected function checkForErrors( array $atts ) |
|
171 | + protected function checkForErrors(array $atts) |
|
172 | 172 | { |
173 | 173 | $args = $this->args; |
174 | 174 | |
175 | - if( !array_key_exists( $atts['name'], $args['errors'] )) { |
|
175 | + if (!array_key_exists($atts['name'], $args['errors'])) { |
|
176 | 176 | $this->args['errors'] = ''; // set to an empty string |
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | - $field_errors = $args['errors'][ $atts['name'] ]; |
|
180 | + $field_errors = $args['errors'][$atts['name']]; |
|
181 | 181 | |
182 | - $errors = array_reduce( $field_errors['errors'], function( $carry, $error ) { |
|
183 | - return $carry . sprintf( '<span>%s</span> ', $error ); |
|
182 | + $errors = array_reduce($field_errors['errors'], function($carry, $error) { |
|
183 | + return $carry . sprintf('<span>%s</span> ', $error); |
|
184 | 184 | }); |
185 | 185 | |
186 | - $this->args['errors'] = sprintf( '<span class="glsr-field-errors">%s</span>', $errors ); |
|
186 | + $this->args['errors'] = sprintf('<span class="glsr-field-errors">%s</span>', $errors); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return array |
193 | 193 | */ |
194 | - protected function parseAttributes( array $args ) |
|
194 | + protected function parseAttributes(array $args) |
|
195 | 195 | { |
196 | - if( empty( $args['attributes'] )) { |
|
196 | + if (empty($args['attributes'])) { |
|
197 | 197 | return []; |
198 | 198 | } |
199 | 199 | |
200 | 200 | $attributes = (array) $args['attributes']; |
201 | 201 | |
202 | - foreach( $attributes as $key => $value ) { |
|
203 | - if( is_string( $key ))continue; |
|
204 | - unset( $attributes[ $key ] ); |
|
205 | - if( !isset( $attributes[ $value ] )) { |
|
206 | - $attributes[ $value ] = ''; |
|
202 | + foreach ($attributes as $key => $value) { |
|
203 | + if (is_string($key))continue; |
|
204 | + unset($attributes[$key]); |
|
205 | + if (!isset($attributes[$value])) { |
|
206 | + $attributes[$value] = ''; |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
@@ -215,13 +215,13 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return null|string |
217 | 217 | */ |
218 | - protected function parseId( array $args ) |
|
218 | + protected function parseId(array $args) |
|
219 | 219 | { |
220 | - if( isset( $args['id'] ) && !$args['id'] )return; |
|
220 | + if (isset($args['id']) && !$args['id'])return; |
|
221 | 221 | |
222 | 222 | !$args['suffix'] ?: $args['suffix'] = "-{$args['suffix']}"; |
223 | 223 | |
224 | - return str_replace( ['[]','[',']','.'], ['','-','','-'], $this->parseName( $args ) . $args['suffix'] ); |
|
224 | + return str_replace(['[]', '[', ']', '.'], ['', '-', '', '-'], $this->parseName($args) . $args['suffix']); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return bool |
231 | 231 | */ |
232 | - protected function parseInline( array $args ) |
|
232 | + protected function parseInline(array $args) |
|
233 | 233 | { |
234 | - return false !== stripos( $args['type'], '_inline' ) |
|
234 | + return false !== stripos($args['type'], '_inline') |
|
235 | 235 | ? true |
236 | 236 | : $args['inline']; |
237 | 237 | } |
@@ -241,20 +241,20 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @return string |
243 | 243 | */ |
244 | - protected function parseName( array $args ) |
|
244 | + protected function parseName(array $args) |
|
245 | 245 | { |
246 | 246 | $name = $args['name']; |
247 | - $prefix = $this->parsePrefix( $args ); |
|
247 | + $prefix = $this->parsePrefix($args); |
|
248 | 248 | |
249 | - if( $prefix === false ) { |
|
249 | + if ($prefix === false) { |
|
250 | 250 | return $name; |
251 | 251 | } |
252 | 252 | |
253 | - $paths = explode( '.', $name ); |
|
253 | + $paths = explode('.', $name); |
|
254 | 254 | |
255 | - return array_reduce( $paths, function( $result, $value ) { |
|
255 | + return array_reduce($paths, function($result, $value) { |
|
256 | 256 | return $result .= "[$value]"; |
257 | - }, $prefix ); |
|
257 | + }, $prefix); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @return string|false |
264 | 264 | */ |
265 | - protected function parsePrefix( array $args ) |
|
265 | + protected function parsePrefix(array $args) |
|
266 | 266 | { |
267 | 267 | return $args['prefix']; |
268 | 268 | } |
@@ -272,12 +272,12 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return string |
274 | 274 | */ |
275 | - protected function parseType( array $args ) |
|
275 | + protected function parseType(array $args) |
|
276 | 276 | { |
277 | 277 | $type = $args['type']; |
278 | 278 | |
279 | - return false !== stripos( $type, '_inline' ) |
|
280 | - ? str_replace( '_inline', '', $type ) |
|
279 | + return false !== stripos($type, '_inline') |
|
280 | + ? str_replace('_inline', '', $type) |
|
281 | 281 | : $type; |
282 | 282 | } |
283 | 283 | |
@@ -286,18 +286,18 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @return string |
288 | 288 | */ |
289 | - protected function parseValue( array $args ) |
|
289 | + protected function parseValue(array $args) |
|
290 | 290 | { |
291 | 291 | $default = $args['default']; |
292 | 292 | $name = $args['name']; |
293 | 293 | $prefix = $args['prefix']; |
294 | 294 | $value = $args['value']; |
295 | 295 | |
296 | - if( $default == ':placeholder' ) { |
|
296 | + if ($default == ':placeholder') { |
|
297 | 297 | $default = ''; |
298 | 298 | } |
299 | 299 | |
300 | - return ( !empty( $value ) || !$name || $prefix === false ) |
|
300 | + return (!empty($value) || !$name || $prefix === false) |
|
301 | 301 | ? $value |
302 | 302 | : $default; |
303 | 303 | } |
@@ -329,15 +329,15 @@ discard block |
||
329 | 329 | */ |
330 | 330 | protected function setDataDepends() |
331 | 331 | { |
332 | - if( !( $depends = $this->args['depends'] ))return; |
|
332 | + if (!($depends = $this->args['depends']))return; |
|
333 | 333 | |
334 | 334 | $name = $depends; |
335 | 335 | $value = true; |
336 | 336 | |
337 | - if( is_array( $depends )) { |
|
338 | - reset( $depends ); |
|
339 | - $name = key( $depends ); |
|
340 | - $value = $depends[ $name ]; |
|
337 | + if (is_array($depends)) { |
|
338 | + reset($depends); |
|
339 | + $name = key($depends); |
|
340 | + $value = $depends[$name]; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | $name = $this->parseName([ |
@@ -116,7 +116,9 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function render( $print = true ) |
118 | 118 | { |
119 | - if( $this->args['render'] === false )return; |
|
119 | + if( $this->args['render'] === false ) { |
|
120 | + return; |
|
121 | + } |
|
120 | 122 | |
121 | 123 | $field = $this->getField(); |
122 | 124 | |
@@ -200,7 +202,9 @@ discard block |
||
200 | 202 | $attributes = (array) $args['attributes']; |
201 | 203 | |
202 | 204 | foreach( $attributes as $key => $value ) { |
203 | - if( is_string( $key ))continue; |
|
205 | + if( is_string( $key )) { |
|
206 | + continue; |
|
207 | + } |
|
204 | 208 | unset( $attributes[ $key ] ); |
205 | 209 | if( !isset( $attributes[ $value ] )) { |
206 | 210 | $attributes[ $value ] = ''; |
@@ -217,7 +221,9 @@ discard block |
||
217 | 221 | */ |
218 | 222 | protected function parseId( array $args ) |
219 | 223 | { |
220 | - if( isset( $args['id'] ) && !$args['id'] )return; |
|
224 | + if( isset( $args['id'] ) && !$args['id'] ) { |
|
225 | + return; |
|
226 | + } |
|
221 | 227 | |
222 | 228 | !$args['suffix'] ?: $args['suffix'] = "-{$args['suffix']}"; |
223 | 229 | |
@@ -329,7 +335,9 @@ discard block |
||
329 | 335 | */ |
330 | 336 | protected function setDataDepends() |
331 | 337 | { |
332 | - if( !( $depends = $this->args['depends'] ))return; |
|
338 | + if( !( $depends = $this->args['depends'] )) { |
|
339 | + return; |
|
340 | + } |
|
333 | 341 | |
334 | 342 | $name = $depends; |
335 | 343 | $value = true; |