@@ -78,7 +78,9 @@ discard block |
||
78 | 78 | foreach( $rules as $rule ) { |
79 | 79 | $this->validateAttribute( $rule, $attribute ); |
80 | 80 | |
81 | - if( $this->shouldStopValidating( $attribute ))break; |
|
81 | + if( $this->shouldStopValidating( $attribute )) { |
|
82 | + break; |
|
83 | + } |
|
82 | 84 | } |
83 | 85 | } |
84 | 86 | |
@@ -161,7 +163,9 @@ discard block |
||
161 | 163 | */ |
162 | 164 | protected function getRule( $attribute, $rules ) |
163 | 165 | { |
164 | - if( !array_key_exists( $attribute, $this->rules ))return; |
|
166 | + if( !array_key_exists( $attribute, $this->rules )) { |
|
167 | + return; |
|
168 | + } |
|
165 | 169 | |
166 | 170 | $rules = (array) $rules; |
167 | 171 | |
@@ -188,8 +192,7 @@ discard block |
||
188 | 192 | |
189 | 193 | if( is_numeric( $value ) && $hasNumeric ) { |
190 | 194 | return $value; |
191 | - } |
|
192 | - elseif( is_array( $value )) { |
|
195 | + } elseif( is_array( $value )) { |
|
193 | 196 | return count( $value ); |
194 | 197 | } |
195 | 198 | |
@@ -253,8 +256,7 @@ discard block |
||
253 | 256 | // If an object was provided, get its public properties |
254 | 257 | if( is_object( $data )) { |
255 | 258 | $this->data = get_object_vars( $data ); |
256 | - } |
|
257 | - else { |
|
259 | + } else { |
|
258 | 260 | $this->data = $data; |
259 | 261 | } |
260 | 262 | |
@@ -420,7 +422,9 @@ discard block |
||
420 | 422 | ? $strings[ $key ] |
421 | 423 | : false; |
422 | 424 | |
423 | - if( !$message )return; |
|
425 | + if( !$message ) { |
|
426 | + return; |
|
427 | + } |
|
424 | 428 | |
425 | 429 | $message = str_replace( ':attribute', $attribute, $message ); |
426 | 430 | |
@@ -464,7 +468,9 @@ discard block |
||
464 | 468 | { |
465 | 469 | list( $rule, $parameters ) = $this->parseRule( $rule ); |
466 | 470 | |
467 | - if( $rule == '' )return; |
|
471 | + if( $rule == '' ) { |
|
472 | + return; |
|
473 | + } |
|
468 | 474 | |
469 | 475 | $method = "validate{$rule}"; |
470 | 476 |
@@ -69,16 +69,16 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return array |
71 | 71 | */ |
72 | - public function validate( $data, array $rules = [] ) |
|
72 | + public function validate($data, array $rules = []) |
|
73 | 73 | { |
74 | - $this->normalizeData( $data ); |
|
75 | - $this->setRules( $rules ); |
|
74 | + $this->normalizeData($data); |
|
75 | + $this->setRules($rules); |
|
76 | 76 | |
77 | - foreach( $this->rules as $attribute => $rules ) { |
|
78 | - foreach( $rules as $rule ) { |
|
79 | - $this->validateAttribute( $rule, $attribute ); |
|
77 | + foreach ($this->rules as $attribute => $rules) { |
|
78 | + foreach ($rules as $rule) { |
|
79 | + $this->validateAttribute($rule, $attribute); |
|
80 | 80 | |
81 | - if( $this->shouldStopValidating( $attribute ))break; |
|
81 | + if ($this->shouldStopValidating($attribute))break; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return void |
95 | 95 | */ |
96 | - protected function addError( $attribute, $rule, array $parameters ) |
|
96 | + protected function addError($attribute, $rule, array $parameters) |
|
97 | 97 | { |
98 | - $message = $this->getMessage( $attribute, $rule, $parameters ); |
|
98 | + $message = $this->getMessage($attribute, $rule, $parameters); |
|
99 | 99 | |
100 | - $this->errors[ $attribute ]['errors'][] = $message; |
|
100 | + $this->errors[$attribute]['errors'][] = $message; |
|
101 | 101 | |
102 | - if( !isset( $this->errors[ $attribute ]['value'] )) { |
|
103 | - $this->errors[ $attribute ]['value'] = $this->getValue( $attribute ); |
|
102 | + if (!isset($this->errors[$attribute]['value'])) { |
|
103 | + $this->errors[$attribute]['value'] = $this->getValue($attribute); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - protected function addFailure( $attribute, $rule, array $parameters ) |
|
115 | + protected function addFailure($attribute, $rule, array $parameters) |
|
116 | 116 | { |
117 | - $this->addError( $attribute, $rule, $parameters ); |
|
117 | + $this->addError($attribute, $rule, $parameters); |
|
118 | 118 | |
119 | - $this->failedRules[ $attribute ][ $rule ] = $parameters; |
|
119 | + $this->failedRules[$attribute][$rule] = $parameters; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * @param string $attribute |
126 | 126 | * @return string |
127 | 127 | */ |
128 | - protected function getAttributeType( $attribute ) |
|
128 | + protected function getAttributeType($attribute) |
|
129 | 129 | { |
130 | - return $this->hasRule( $attribute, $this->numericRules ) |
|
130 | + return $this->hasRule($attribute, $this->numericRules) |
|
131 | 131 | ? 'numeric' |
132 | 132 | : 'string'; |
133 | 133 | } |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return string|null |
142 | 142 | */ |
143 | - protected function getMessage( $attribute, $rule, array $parameters ) |
|
143 | + protected function getMessage($attribute, $rule, array $parameters) |
|
144 | 144 | { |
145 | - if( in_array( $rule, $this->sizeRules )) { |
|
146 | - return $this->getSizeMessage( $attribute, $rule, $parameters ); |
|
145 | + if (in_array($rule, $this->sizeRules)) { |
|
146 | + return $this->getSizeMessage($attribute, $rule, $parameters); |
|
147 | 147 | } |
148 | 148 | |
149 | - $lowerRule = $this->snakeCase( $rule ); |
|
149 | + $lowerRule = $this->snakeCase($rule); |
|
150 | 150 | |
151 | - return $this->translator( $lowerRule, $rule, $attribute, $parameters ); |
|
151 | + return $this->translator($lowerRule, $rule, $attribute, $parameters); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return array|null |
161 | 161 | */ |
162 | - protected function getRule( $attribute, $rules ) |
|
162 | + protected function getRule($attribute, $rules) |
|
163 | 163 | { |
164 | - if( !array_key_exists( $attribute, $this->rules ))return; |
|
164 | + if (!array_key_exists($attribute, $this->rules))return; |
|
165 | 165 | |
166 | 166 | $rules = (array) $rules; |
167 | 167 | |
168 | - foreach( $this->rules[ $attribute ] as $rule ) { |
|
169 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
168 | + foreach ($this->rules[$attribute] as $rule) { |
|
169 | + list($rule, $parameters) = $this->parseRule($rule); |
|
170 | 170 | |
171 | - if( in_array( $rule, $rules )) { |
|
172 | - return [ $rule, $parameters ]; |
|
171 | + if (in_array($rule, $rules)) { |
|
172 | + return [$rule, $parameters]; |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | } |
@@ -182,18 +182,18 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return mixed |
184 | 184 | */ |
185 | - protected function getSize( $attribute, $value ) |
|
185 | + protected function getSize($attribute, $value) |
|
186 | 186 | { |
187 | - $hasNumeric = $this->hasRule( $attribute, $this->numericRules ); |
|
187 | + $hasNumeric = $this->hasRule($attribute, $this->numericRules); |
|
188 | 188 | |
189 | - if( is_numeric( $value ) && $hasNumeric ) { |
|
189 | + if (is_numeric($value) && $hasNumeric) { |
|
190 | 190 | return $value; |
191 | 191 | } |
192 | - elseif( is_array( $value )) { |
|
193 | - return count( $value ); |
|
192 | + elseif (is_array($value)) { |
|
193 | + return count($value); |
|
194 | 194 | } |
195 | 195 | |
196 | - return mb_strlen( $value ); |
|
196 | + return mb_strlen($value); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -204,14 +204,14 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @return string|null |
206 | 206 | */ |
207 | - protected function getSizeMessage( $attribute, $rule, array $parameters ) |
|
207 | + protected function getSizeMessage($attribute, $rule, array $parameters) |
|
208 | 208 | { |
209 | - $lowerRule = $this->snakeCase( $rule ); |
|
210 | - $type = $this->getAttributeType( $attribute ); |
|
209 | + $lowerRule = $this->snakeCase($rule); |
|
210 | + $type = $this->getAttributeType($attribute); |
|
211 | 211 | |
212 | 212 | $lowerRule .= ".{$type}"; |
213 | 213 | |
214 | - return $this->translator( $lowerRule, $rule, $attribute, $parameters ); |
|
214 | + return $this->translator($lowerRule, $rule, $attribute, $parameters); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @return mixed |
223 | 223 | */ |
224 | - protected function getValue( $attribute ) |
|
224 | + protected function getValue($attribute) |
|
225 | 225 | { |
226 | - if( isset( $this->data[ $attribute ] )) { |
|
227 | - return $this->data[ $attribute ]; |
|
226 | + if (isset($this->data[$attribute])) { |
|
227 | + return $this->data[$attribute]; |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @return bool |
238 | 238 | */ |
239 | - protected function hasRule( $attribute, $rules ) |
|
239 | + protected function hasRule($attribute, $rules) |
|
240 | 240 | { |
241 | - return !is_null( $this->getRule( $attribute, $rules )); |
|
241 | + return !is_null($this->getRule($attribute, $rules)); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @return $this |
250 | 250 | */ |
251 | - protected function normalizeData( $data ) |
|
251 | + protected function normalizeData($data) |
|
252 | 252 | { |
253 | 253 | // If an object was provided, get its public properties |
254 | - if( is_object( $data )) { |
|
255 | - $this->data = get_object_vars( $data ); |
|
254 | + if (is_object($data)) { |
|
255 | + $this->data = get_object_vars($data); |
|
256 | 256 | } |
257 | 257 | else { |
258 | 258 | $this->data = $data; |
@@ -269,13 +269,13 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return array |
271 | 271 | */ |
272 | - protected function parseParameters( $rule, $parameter ) |
|
272 | + protected function parseParameters($rule, $parameter) |
|
273 | 273 | { |
274 | - if( strtolower( $rule ) == 'regex' ) { |
|
275 | - return [ $parameter ]; |
|
274 | + if (strtolower($rule) == 'regex') { |
|
275 | + return [$parameter]; |
|
276 | 276 | } |
277 | 277 | |
278 | - return str_getcsv( $parameter ); |
|
278 | + return str_getcsv($parameter); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -285,22 +285,22 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return array |
287 | 287 | */ |
288 | - protected function parseRule( $rule ) |
|
288 | + protected function parseRule($rule) |
|
289 | 289 | { |
290 | 290 | $parameters = []; |
291 | 291 | |
292 | 292 | // example: {rule}:{parameters} |
293 | - if( strpos( $rule, ':' ) !== false ) { |
|
294 | - list( $rule, $parameter ) = explode( ':', $rule, 2 ); |
|
293 | + if (strpos($rule, ':') !== false) { |
|
294 | + list($rule, $parameter) = explode(':', $rule, 2); |
|
295 | 295 | |
296 | 296 | // example: {parameter1,parameter2,...} |
297 | - $parameters = $this->parseParameters( $rule, $parameter ); |
|
297 | + $parameters = $this->parseParameters($rule, $parameter); |
|
298 | 298 | } |
299 | 299 | |
300 | - $rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule ))); |
|
301 | - $rule = str_replace( ' ', '', $rule ); |
|
300 | + $rule = ucwords(str_replace(['-', '_'], ' ', trim($rule))); |
|
301 | + $rule = str_replace(' ', '', $rule); |
|
302 | 302 | |
303 | - return [ $rule, $parameters ]; |
|
303 | + return [$rule, $parameters]; |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -310,9 +310,9 @@ discard block |
||
310 | 310 | * |
311 | 311 | * @return string |
312 | 312 | */ |
313 | - protected function replaceBetween( $message, array $parameters ) |
|
313 | + protected function replaceBetween($message, array $parameters) |
|
314 | 314 | { |
315 | - return str_replace([':min', ':max'], $parameters, $message ); |
|
315 | + return str_replace([':min', ':max'], $parameters, $message); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @return string |
324 | 324 | */ |
325 | - protected function replaceMax( $message, array $parameters ) |
|
325 | + protected function replaceMax($message, array $parameters) |
|
326 | 326 | { |
327 | - return str_replace( ':max', $parameters[0], $message ); |
|
327 | + return str_replace(':max', $parameters[0], $message); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -334,9 +334,9 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @return string |
336 | 336 | */ |
337 | - protected function replaceMin( $message, array $parameters ) |
|
337 | + protected function replaceMin($message, array $parameters) |
|
338 | 338 | { |
339 | - return str_replace( ':min', $parameters[0], $message ); |
|
339 | + return str_replace(':min', $parameters[0], $message); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -348,10 +348,10 @@ discard block |
||
348 | 348 | * @return void |
349 | 349 | * @throws InvalidArgumentException |
350 | 350 | */ |
351 | - protected function requireParameterCount( $count, array $parameters, $rule ) |
|
351 | + protected function requireParameterCount($count, array $parameters, $rule) |
|
352 | 352 | { |
353 | - if( count( $parameters ) < $count ) { |
|
354 | - throw new InvalidArgumentException( "Validation rule $rule requires at least $count parameters." ); |
|
353 | + if (count($parameters) < $count) { |
|
354 | + throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @return $this |
362 | 362 | */ |
363 | - protected function setRules( array $rules ) |
|
363 | + protected function setRules(array $rules) |
|
364 | 364 | { |
365 | - foreach( $rules as $key => $rule ) { |
|
366 | - $rules[ $key ] = is_string( $rule ) ? explode( '|', $rule ) : $rule; |
|
365 | + foreach ($rules as $key => $rule) { |
|
366 | + $rules[$key] = is_string($rule) ? explode('|', $rule) : $rule; |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | $this->rules = $rules; |
@@ -378,11 +378,11 @@ discard block |
||
378 | 378 | * |
379 | 379 | * @return bool |
380 | 380 | */ |
381 | - protected function shouldStopValidating( $attribute ) |
|
381 | + protected function shouldStopValidating($attribute) |
|
382 | 382 | { |
383 | - return $this->hasRule( $attribute, $this->implicitRules ) |
|
384 | - && isset( $this->failedRules[ $attribute ] ) |
|
385 | - && array_intersect( array_keys( $this->failedRules[ $attribute ] ), $this->implicitRules ); |
|
383 | + return $this->hasRule($attribute, $this->implicitRules) |
|
384 | + && isset($this->failedRules[$attribute]) |
|
385 | + && array_intersect(array_keys($this->failedRules[$attribute]), $this->implicitRules); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -392,12 +392,12 @@ discard block |
||
392 | 392 | * |
393 | 393 | * @return string |
394 | 394 | */ |
395 | - protected function snakeCase( $string ) |
|
395 | + protected function snakeCase($string) |
|
396 | 396 | { |
397 | - if( !ctype_lower( $string )) { |
|
398 | - $string = preg_replace( '/\s+/u', '', $string ); |
|
399 | - $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
|
400 | - $string = mb_strtolower( $string, 'UTF-8' ); |
|
397 | + if (!ctype_lower($string)) { |
|
398 | + $string = preg_replace('/\s+/u', '', $string); |
|
399 | + $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
400 | + $string = mb_strtolower($string, 'UTF-8'); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | return $string; |
@@ -412,20 +412,20 @@ discard block |
||
412 | 412 | * |
413 | 413 | * @return string|null |
414 | 414 | */ |
415 | - protected function translator( $key, $rule, $attribute, array $parameters ) |
|
415 | + protected function translator($key, $rule, $attribute, array $parameters) |
|
416 | 416 | { |
417 | - $strings = glsr_resolve( 'Strings' )->validation(); |
|
417 | + $strings = glsr_resolve('Strings')->validation(); |
|
418 | 418 | |
419 | - $message = isset( $strings[ $key ] ) |
|
420 | - ? $strings[ $key ] |
|
419 | + $message = isset($strings[$key]) |
|
420 | + ? $strings[$key] |
|
421 | 421 | : false; |
422 | 422 | |
423 | - if( !$message )return; |
|
423 | + if (!$message)return; |
|
424 | 424 | |
425 | - $message = str_replace( ':attribute', $attribute, $message ); |
|
425 | + $message = str_replace(':attribute', $attribute, $message); |
|
426 | 426 | |
427 | - if( method_exists( $this, $replacer = "replace{$rule}" )) { |
|
428 | - $message = $this->$replacer( $message, $parameters ); |
|
427 | + if (method_exists($this, $replacer = "replace{$rule}")) { |
|
428 | + $message = $this->$replacer($message, $parameters); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | return $message; |
@@ -443,11 +443,11 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @return bool |
445 | 445 | */ |
446 | - protected function validateAccepted( $value ) |
|
446 | + protected function validateAccepted($value) |
|
447 | 447 | { |
448 | 448 | $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
449 | 449 | |
450 | - return $this->validateRequired( $value ) && in_array( $value, $acceptable, true ); |
|
450 | + return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -459,20 +459,20 @@ discard block |
||
459 | 459 | * @return void |
460 | 460 | * @throws BadMethodCallException |
461 | 461 | */ |
462 | - protected function validateAttribute( $rule, $attribute ) |
|
462 | + protected function validateAttribute($rule, $attribute) |
|
463 | 463 | { |
464 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
464 | + list($rule, $parameters) = $this->parseRule($rule); |
|
465 | 465 | |
466 | - if( $rule == '' )return; |
|
466 | + if ($rule == '')return; |
|
467 | 467 | |
468 | 468 | $method = "validate{$rule}"; |
469 | 469 | |
470 | - if( !method_exists( $this, $method )) { |
|
471 | - throw new BadMethodCallException( "Method [$method] does not exist." ); |
|
470 | + if (!method_exists($this, $method)) { |
|
471 | + throw new BadMethodCallException("Method [$method] does not exist."); |
|
472 | 472 | } |
473 | 473 | |
474 | - if( !$this->$method( $this->getValue( $attribute ), $attribute, $parameters )) { |
|
475 | - $this->addFailure( $attribute, $rule, $parameters ); |
|
474 | + if (!$this->$method($this->getValue($attribute), $attribute, $parameters)) { |
|
475 | + $this->addFailure($attribute, $rule, $parameters); |
|
476 | 476 | } |
477 | 477 | } |
478 | 478 | |
@@ -484,11 +484,11 @@ discard block |
||
484 | 484 | * |
485 | 485 | * @return bool |
486 | 486 | */ |
487 | - protected function validateBetween( $value, $attribute, array $parameters ) |
|
487 | + protected function validateBetween($value, $attribute, array $parameters) |
|
488 | 488 | { |
489 | - $this->requireParameterCount( 2, $parameters, 'between' ); |
|
489 | + $this->requireParameterCount(2, $parameters, 'between'); |
|
490 | 490 | |
491 | - $size = $this->getSize( $attribute, $value ); |
|
491 | + $size = $this->getSize($attribute, $value); |
|
492 | 492 | |
493 | 493 | return $size >= $parameters[0] && $size <= $parameters[1]; |
494 | 494 | } |
@@ -500,9 +500,9 @@ discard block |
||
500 | 500 | * |
501 | 501 | * @return bool |
502 | 502 | */ |
503 | - protected function validateEmail( $value ) |
|
503 | + protected function validateEmail($value) |
|
504 | 504 | { |
505 | - return filter_var( $value, FILTER_VALIDATE_EMAIL ) !== false; |
|
505 | + return filter_var($value, FILTER_VALIDATE_EMAIL) !== false; |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | * |
514 | 514 | * @return bool |
515 | 515 | */ |
516 | - protected function validateMax( $value, $attribute, array $parameters ) |
|
516 | + protected function validateMax($value, $attribute, array $parameters) |
|
517 | 517 | { |
518 | - $this->requireParameterCount( 1, $parameters, 'max' ); |
|
518 | + $this->requireParameterCount(1, $parameters, 'max'); |
|
519 | 519 | |
520 | - return $this->getSize( $attribute, $value ) <= $parameters[0]; |
|
520 | + return $this->getSize($attribute, $value) <= $parameters[0]; |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
@@ -528,11 +528,11 @@ discard block |
||
528 | 528 | * |
529 | 529 | * @return bool |
530 | 530 | */ |
531 | - protected function validateMin( $value, $attribute, array $parameters ) |
|
531 | + protected function validateMin($value, $attribute, array $parameters) |
|
532 | 532 | { |
533 | - $this->requireParameterCount( 1, $parameters, 'min' ); |
|
533 | + $this->requireParameterCount(1, $parameters, 'min'); |
|
534 | 534 | |
535 | - return $this->getSize( $attribute, $value ) >= $parameters[0]; |
|
535 | + return $this->getSize($attribute, $value) >= $parameters[0]; |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -542,9 +542,9 @@ discard block |
||
542 | 542 | * |
543 | 543 | * @return bool |
544 | 544 | */ |
545 | - protected function validateNumeric( $value ) |
|
545 | + protected function validateNumeric($value) |
|
546 | 546 | { |
547 | - return is_numeric( $value ); |
|
547 | + return is_numeric($value); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | /** |
@@ -554,12 +554,12 @@ discard block |
||
554 | 554 | * |
555 | 555 | * @return bool |
556 | 556 | */ |
557 | - protected function validateRequired( $value ) |
|
557 | + protected function validateRequired($value) |
|
558 | 558 | { |
559 | - if( is_string( $value )) { |
|
560 | - $value = trim( $value ); |
|
559 | + if (is_string($value)) { |
|
560 | + $value = trim($value); |
|
561 | 561 | } |
562 | - return is_null( $value ) || empty( $value ) |
|
562 | + return is_null($value) || empty($value) |
|
563 | 563 | ? false |
564 | 564 | : true; |
565 | 565 | } |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | { |
9 | 9 | protected $element = 'input'; |
10 | 10 | |
11 | - public function __construct( array $args = [] ) |
|
11 | + public function __construct(array $args = []) |
|
12 | 12 | { |
13 | - parent::__construct( $args ); |
|
13 | + parent::__construct($args); |
|
14 | 14 | |
15 | - if( count( $args['options'] ) > 1 ) { |
|
15 | + if (count($args['options']) > 1) { |
|
16 | 16 | $this->multi = true; |
17 | 17 | } |
18 | 18 | } |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | { |
25 | 25 | $inline = $this->args['inline'] ? ' class="inline"' : ''; |
26 | 26 | |
27 | - if( $this->multi ) { |
|
28 | - return sprintf( '<ul%s>%s</ul>%s', |
|
27 | + if ($this->multi) { |
|
28 | + return sprintf('<ul%s>%s</ul>%s', |
|
29 | 29 | $inline, |
30 | - $this->implodeOptions( 'multi_input_checkbox' ), |
|
30 | + $this->implodeOptions('multi_input_checkbox'), |
|
31 | 31 | $this->generateDescription() |
32 | 32 | ); |
33 | 33 | } |
34 | 34 | |
35 | - return sprintf( '%s%s', |
|
36 | - $this->implodeOptions( 'single_input' ), |
|
35 | + return sprintf('%s%s', |
|
36 | + $this->implodeOptions('single_input'), |
|
37 | 37 | $this->generateDescription() |
38 | 38 | ); |
39 | 39 | } |
@@ -11,13 +11,13 @@ |
||
11 | 11 | /** |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function render( $default = null ) |
|
14 | + public function render($default = null) |
|
15 | 15 | { |
16 | 16 | $inline = $this->args['inline'] ? ' class="inline"' : ''; |
17 | 17 | |
18 | - return sprintf( '<ul%s>%s</ul>%s', |
|
18 | + return sprintf('<ul%s>%s</ul>%s', |
|
19 | 19 | $inline, |
20 | - $this->implodeOptions( 'multi_input', $default ), |
|
20 | + $this->implodeOptions('multi_input', $default), |
|
21 | 21 | $this->generateDescription() |
22 | 22 | ); |
23 | 23 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | */ |
12 | 12 | public function render() |
13 | 13 | { |
14 | - if( isset( $this->args['name'] )) { |
|
14 | + if (isset($this->args['name'])) { |
|
15 | 15 | $this->args['name'] = 'submit'; |
16 | 16 | } |
17 | 17 |
@@ -11,15 +11,15 @@ |
||
11 | 11 | /** |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function render( array $defaults = [] ) |
|
14 | + public function render(array $defaults = []) |
|
15 | 15 | { |
16 | - $defaults = wp_parse_args( $defaults, [ |
|
16 | + $defaults = wp_parse_args($defaults, [ |
|
17 | 17 | 'type' => 'select', |
18 | 18 | ]); |
19 | 19 | |
20 | - return sprintf( '<select %s>%s</select>%s', |
|
21 | - $this->implodeAttributes( $defaults ), |
|
22 | - $this->implodeOptions( 'select_option' ), |
|
20 | + return sprintf('<select %s>%s</select>%s', |
|
21 | + $this->implodeAttributes($defaults), |
|
22 | + $this->implodeOptions('select_option'), |
|
23 | 23 | $this->generateDescription() |
24 | 24 | ); |
25 | 25 | } |
@@ -11,16 +11,16 @@ |
||
11 | 11 | */ |
12 | 12 | public function render() |
13 | 13 | { |
14 | - if( isset( $this->args['label'] )) { |
|
15 | - unset( $this->args['label'] ); |
|
14 | + if (isset($this->args['label'])) { |
|
15 | + unset($this->args['label']); |
|
16 | 16 | } |
17 | 17 | |
18 | - if( isset( $this->args['desc'] )) { |
|
19 | - unset( $this->args['desc'] ); |
|
18 | + if (isset($this->args['desc'])) { |
|
19 | + unset($this->args['desc']); |
|
20 | 20 | } |
21 | 21 | |
22 | - if( isset( $this->args['id'] )) { |
|
23 | - unset( $this->args['id'] ); |
|
22 | + if (isset($this->args['id'])) { |
|
23 | + unset($this->args['id']); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | return parent::render([ |
@@ -11,16 +11,16 @@ |
||
11 | 11 | /** |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function render( array $defaults = [] ) |
|
14 | + public function render(array $defaults = []) |
|
15 | 15 | { |
16 | - $defaults = wp_parse_args( $defaults, [ |
|
16 | + $defaults = wp_parse_args($defaults, [ |
|
17 | 17 | 'class' => 'large-text', |
18 | 18 | 'rows' => 3, |
19 | 19 | 'type' => 'textarea', |
20 | 20 | ]); |
21 | 21 | |
22 | - return sprintf( '<textarea %s>%s</textarea>%s', |
|
23 | - $this->implodeAttributes( $defaults ), |
|
22 | + return sprintf('<textarea %s>%s</textarea>%s', |
|
23 | + $this->implodeAttributes($defaults), |
|
24 | 24 | $this->args['value'], |
25 | 25 | $this->generateDescription() |
26 | 26 | ); |
@@ -72,7 +72,9 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function generateDescription( $paragraph = true ) |
74 | 74 | { |
75 | - if( !isset( $this->args['desc'] ) || !$this->args['desc'] )return; |
|
75 | + if( !isset( $this->args['desc'] ) || !$this->args['desc'] ) { |
|
76 | + return; |
|
77 | + } |
|
76 | 78 | |
77 | 79 | $tag = ( !!$paragraph || $paragraph == 'p' ) ? 'p' : 'span'; |
78 | 80 | |
@@ -86,7 +88,9 @@ discard block |
||
86 | 88 | */ |
87 | 89 | public function generateLabel() |
88 | 90 | { |
89 | - if( empty( $this->args['label'] ))return; |
|
91 | + if( empty( $this->args['label'] )) { |
|
92 | + return; |
|
93 | + } |
|
90 | 94 | |
91 | 95 | $for = !!$this->args['id'] |
92 | 96 | ? " for=\"{$this->args['id']}\"" |
@@ -145,7 +149,9 @@ discard block |
||
145 | 149 | |
146 | 150 | if( $method === 'singleInput' ) { |
147 | 151 | |
148 | - if( !isset( $this->args['options'] ) || empty( $this->args['options'] ))return; |
|
152 | + if( !isset( $this->args['options'] ) || empty( $this->args['options'] )) { |
|
153 | + return; |
|
154 | + } |
|
149 | 155 | |
150 | 156 | // hack to make sure unset single checkbox values start at 1 instead of 0 |
151 | 157 | if( key( $this->args['options'] ) === 0 ) { |
@@ -188,7 +194,9 @@ discard block |
||
188 | 194 | { |
189 | 195 | // similar to array_merge except overwrite empty values |
190 | 196 | foreach( $defaults as $key => $value ) { |
191 | - if( isset( $this->args[ $key ] ) && !empty( $this->args[ $key ] ))continue; |
|
197 | + if( isset( $this->args[ $key ] ) && !empty( $this->args[ $key ] )) { |
|
198 | + continue; |
|
199 | + } |
|
192 | 200 | $this->args[ $key ] = $value; |
193 | 201 | } |
194 | 202 | |
@@ -211,7 +219,9 @@ discard block |
||
211 | 219 | { |
212 | 220 | $args = $this->multiInputArgs( $type, $optionKey, $number ); |
213 | 221 | |
214 | - if( !$args )return; |
|
222 | + if( !$args ) { |
|
223 | + return; |
|
224 | + } |
|
215 | 225 | |
216 | 226 | $attributes = ''; |
217 | 227 | |
@@ -262,7 +272,9 @@ discard block |
||
262 | 272 | |
263 | 273 | $args = wp_parse_args( $args, $defaults ); |
264 | 274 | |
265 | - if( !isset( $label ) || $args['name'] === '' )return; |
|
275 | + if( !isset( $label ) || $args['name'] === '' ) { |
|
276 | + return; |
|
277 | + } |
|
266 | 278 | |
267 | 279 | $args['id'] = $this->args['id'] . "-{$number}"; |
268 | 280 | $args['name'] = $this->args['name'] . ( $type === 'checkbox' && $this->multi ? '[]' : '' ); |
@@ -275,11 +287,9 @@ discard block |
||
275 | 287 | if( in_array( $args['value'], $this->args['value'] )) { |
276 | 288 | $this->args['default'] = $args['value']; |
277 | 289 | } |
278 | - } |
|
279 | - else if( $this->args['value'] ) { |
|
290 | + } else if( $this->args['value'] ) { |
|
280 | 291 | $this->args['default'] = $this->args['value']; |
281 | - } |
|
282 | - else if( $type == 'radio' && !$this->args['default'] ) { |
|
292 | + } else if( $type == 'radio' && !$this->args['default'] ) { |
|
283 | 293 | $this->args['default'] = 0; |
284 | 294 | } |
285 | 295 | |
@@ -332,7 +342,9 @@ discard block |
||
332 | 342 | |
333 | 343 | $args = $this->multiInputArgs( $type, $optionKey, 1 ); |
334 | 344 | |
335 | - if( !$args )return; |
|
345 | + if( !$args ) { |
|
346 | + return; |
|
347 | + } |
|
336 | 348 | |
337 | 349 | $atts = $this->normalize(); |
338 | 350 | $atts = wp_parse_args( $args['attributes'], $atts ); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected $element; |
40 | 40 | |
41 | - public function __construct( array $args = [] ) |
|
41 | + public function __construct(array $args = []) |
|
42 | 42 | { |
43 | 43 | $this->args = $args; |
44 | 44 | } |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * @return mixed |
50 | 50 | * @throws Exception |
51 | 51 | */ |
52 | - public function __get( $property ) |
|
52 | + public function __get($property) |
|
53 | 53 | { |
54 | - switch( $property ) { |
|
54 | + switch ($property) { |
|
55 | 55 | case 'args': |
56 | 56 | case 'dependencies': |
57 | 57 | case 'element': |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | case 'outside': |
60 | 60 | return $this->$property; |
61 | 61 | } |
62 | - throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property )); |
|
62 | + throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property)); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return null|string |
71 | 71 | */ |
72 | - public function generateDescription( $paragraph = true ) |
|
72 | + public function generateDescription($paragraph = true) |
|
73 | 73 | { |
74 | - if( !isset( $this->args['desc'] ) || !$this->args['desc'] )return; |
|
74 | + if (!isset($this->args['desc']) || !$this->args['desc'])return; |
|
75 | 75 | |
76 | - $tag = ( !!$paragraph || $paragraph == 'p' ) ? 'p' : 'span'; |
|
76 | + $tag = (!!$paragraph || $paragraph == 'p') ? 'p' : 'span'; |
|
77 | 77 | |
78 | - return sprintf( '<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc'] ); |
|
78 | + return sprintf('<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc']); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function generateLabel() |
87 | 87 | { |
88 | - if( empty( $this->args['label'] ))return; |
|
88 | + if (empty($this->args['label']))return; |
|
89 | 89 | |
90 | 90 | $for = !!$this->args['id'] |
91 | 91 | ? " for=\"{$this->args['id']}\"" |
92 | 92 | : ''; |
93 | 93 | |
94 | - return sprintf( '<label%s>%s</label>', $for, $this->args['label'] ); |
|
94 | + return sprintf('<label%s>%s</label>', $for, $this->args['label']); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - protected function camelCase( $value ) |
|
111 | + protected function camelCase($value) |
|
112 | 112 | { |
113 | - $value = ucwords( str_replace( ['-', '_'], ' ', $value )); |
|
113 | + $value = ucwords(str_replace(['-', '_'], ' ', $value)); |
|
114 | 114 | |
115 | - return lcfirst( str_replace( ' ', '', $value )); |
|
115 | + return lcfirst(str_replace(' ', '', $value)); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - protected function implodeAttributes( $defaults = [] ) |
|
123 | + protected function implodeAttributes($defaults = []) |
|
124 | 124 | { |
125 | - return $this->normalize( $defaults, 'implode' ); |
|
125 | + return $this->normalize($defaults, 'implode'); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,24 +130,24 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return null|string |
132 | 132 | */ |
133 | - protected function implodeOptions( $method = 'select_option', $default = null ) |
|
133 | + protected function implodeOptions($method = 'select_option', $default = null) |
|
134 | 134 | { |
135 | 135 | $this->args['default'] ?: $this->args['default'] = $default; |
136 | 136 | |
137 | - $method = $this->camelCase( $method ); |
|
137 | + $method = $this->camelCase($method); |
|
138 | 138 | |
139 | - $method = method_exists( $this, $method ) |
|
139 | + $method = method_exists($this, $method) |
|
140 | 140 | ? $method |
141 | 141 | : 'selectOption'; |
142 | 142 | |
143 | 143 | $i = 0; |
144 | 144 | |
145 | - if( $method === 'singleInput' ) { |
|
145 | + if ($method === 'singleInput') { |
|
146 | 146 | |
147 | - if( !isset( $this->args['options'] ) || empty( $this->args['options'] ))return; |
|
147 | + if (!isset($this->args['options']) || empty($this->args['options']))return; |
|
148 | 148 | |
149 | 149 | // hack to make sure unset single checkbox values start at 1 instead of 0 |
150 | - if( key( $this->args['options'] ) === 0 ) { |
|
150 | + if (key($this->args['options']) === 0) { |
|
151 | 151 | $options = ['1' => $this->args['options'][0]]; |
152 | 152 | $this->args['options'] = $options; |
153 | 153 | } |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | return $this->singleInput(); |
156 | 156 | } |
157 | 157 | |
158 | - return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use ( &$i, $method ) { |
|
159 | - return $carry .= $this->$method( $key, $i++ ); |
|
158 | + return array_reduce(array_keys($this->args['options']), function($carry, $key) use (&$i, $method) { |
|
159 | + return $carry .= $this->$method($key, $i++); |
|
160 | 160 | }); |
161 | 161 | } |
162 | 162 | |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - protected function normalize( array $defaults = [], $implode = false ) |
|
170 | + protected function normalize(array $defaults = [], $implode = false) |
|
171 | 171 | { |
172 | - $args = $this->mergeAttributesWith( $defaults ); |
|
172 | + $args = $this->mergeAttributesWith($defaults); |
|
173 | 173 | |
174 | 174 | $normalize = new Normalize; |
175 | 175 | |
176 | - return ( $this->element && method_exists( $normalize, $this->element )) |
|
177 | - ? $normalize->{$this->element}( $args, $implode ) |
|
178 | - : ( !!$implode ? '' : [] ); |
|
176 | + return ($this->element && method_exists($normalize, $this->element)) |
|
177 | + ? $normalize->{$this->element}($args, $implode) |
|
178 | + : (!!$implode ? '' : []); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -183,18 +183,18 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return array |
185 | 185 | */ |
186 | - protected function mergeAttributesWith( array $defaults ) |
|
186 | + protected function mergeAttributesWith(array $defaults) |
|
187 | 187 | { |
188 | 188 | // similar to array_merge except overwrite empty values |
189 | - foreach( $defaults as $key => $value ) { |
|
190 | - if( isset( $this->args[ $key ] ) && !empty( $this->args[ $key ] ))continue; |
|
191 | - $this->args[ $key ] = $value; |
|
189 | + foreach ($defaults as $key => $value) { |
|
190 | + if (isset($this->args[$key]) && !empty($this->args[$key]))continue; |
|
191 | + $this->args[$key] = $value; |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | $attributes = $this->args['attributes']; |
195 | 195 | |
196 | 196 | // prioritize $attributes over $this->args, don't worry about duplicates |
197 | - return array_merge( $this->args, $attributes ); |
|
197 | + return array_merge($this->args, $attributes); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -206,22 +206,22 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return null|string |
208 | 208 | */ |
209 | - protected function multiInput( $optionKey, $number, $type = 'radio' ) |
|
209 | + protected function multiInput($optionKey, $number, $type = 'radio') |
|
210 | 210 | { |
211 | - $args = $this->multiInputArgs( $type, $optionKey, $number ); |
|
211 | + $args = $this->multiInputArgs($type, $optionKey, $number); |
|
212 | 212 | |
213 | - if( !$args )return; |
|
213 | + if (!$args)return; |
|
214 | 214 | |
215 | 215 | $attributes = ''; |
216 | 216 | |
217 | - foreach( $args['attributes'] as $key => $val ) { |
|
218 | - $attributes .= sprintf( '%s="%s" ', $key, $val ); |
|
217 | + foreach ($args['attributes'] as $key => $val) { |
|
218 | + $attributes .= sprintf('%s="%s" ', $key, $val); |
|
219 | 219 | } |
220 | 220 | |
221 | - return sprintf( '<li><label for="%s"><input %s%s/> %s</label></li>', |
|
221 | + return sprintf('<li><label for="%s"><input %s%s/> %s</label></li>', |
|
222 | 222 | $args['attributes']['id'], |
223 | 223 | $attributes, |
224 | - checked( $args['value'], $args['attributes']['value'], false ), |
|
224 | + checked($args['value'], $args['attributes']['value'], false), |
|
225 | 225 | $args['label'] |
226 | 226 | ); |
227 | 227 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return array|null |
237 | 237 | */ |
238 | - protected function multiInputArgs( $type, $optionName, $number ) |
|
238 | + protected function multiInputArgs($type, $optionName, $number) |
|
239 | 239 | { |
240 | 240 | $defaults = [ |
241 | 241 | 'class' => '', |
@@ -246,39 +246,39 @@ discard block |
||
246 | 246 | |
247 | 247 | $args = []; |
248 | 248 | |
249 | - $value = $this->args['options'][ $optionName ]; |
|
249 | + $value = $this->args['options'][$optionName]; |
|
250 | 250 | |
251 | - if( is_array( $value )) { |
|
251 | + if (is_array($value)) { |
|
252 | 252 | $args = $value; |
253 | 253 | } |
254 | 254 | |
255 | - if( is_string( $value )) { |
|
255 | + if (is_string($value)) { |
|
256 | 256 | $label = $value; |
257 | 257 | } |
258 | 258 | |
259 | - isset( $args['name'] ) ?: $args['name'] = $optionName; |
|
260 | - isset( $args['value'] ) ?: $args['value'] = $optionName; |
|
259 | + isset($args['name']) ?: $args['name'] = $optionName; |
|
260 | + isset($args['value']) ?: $args['value'] = $optionName; |
|
261 | 261 | |
262 | - $args = wp_parse_args( $args, $defaults ); |
|
262 | + $args = wp_parse_args($args, $defaults); |
|
263 | 263 | |
264 | - if( !isset( $label ) || $args['name'] === '' )return; |
|
264 | + if (!isset($label) || $args['name'] === '')return; |
|
265 | 265 | |
266 | 266 | $args['id'] = $this->args['id'] . "-{$number}"; |
267 | - $args['name'] = $this->args['name'] . ( $type === 'checkbox' && $this->multi ? '[]' : '' ); |
|
267 | + $args['name'] = $this->args['name'] . ($type === 'checkbox' && $this->multi ? '[]' : ''); |
|
268 | 268 | |
269 | - $args = array_filter( $args, function( $value ) { |
|
269 | + $args = array_filter($args, function($value) { |
|
270 | 270 | return $value !== ''; |
271 | 271 | }); |
272 | 272 | |
273 | - if( is_array( $this->args['value'] )) { |
|
274 | - if( in_array( $args['value'], $this->args['value'] )) { |
|
273 | + if (is_array($this->args['value'])) { |
|
274 | + if (in_array($args['value'], $this->args['value'])) { |
|
275 | 275 | $this->args['default'] = $args['value']; |
276 | 276 | } |
277 | 277 | } |
278 | - else if( $this->args['value'] ) { |
|
278 | + else if ($this->args['value']) { |
|
279 | 279 | $this->args['default'] = $this->args['value']; |
280 | 280 | } |
281 | - else if( $type == 'radio' && !$this->args['default'] ) { |
|
281 | + else if ($type == 'radio' && !$this->args['default']) { |
|
282 | 282 | $this->args['default'] = 0; |
283 | 283 | } |
284 | 284 | |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @return null|string |
299 | 299 | */ |
300 | - protected function multiInputCheckbox( $optionKey, $number ) |
|
300 | + protected function multiInputCheckbox($optionKey, $number) |
|
301 | 301 | { |
302 | - return $this->multiInput( $optionKey, $number, 'checkbox' ); |
|
302 | + return $this->multiInput($optionKey, $number, 'checkbox'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -309,12 +309,12 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @return string |
311 | 311 | */ |
312 | - protected function selectOption( $optionKey ) |
|
312 | + protected function selectOption($optionKey) |
|
313 | 313 | { |
314 | - return sprintf( '<option value="%s"%s>%s</option>', |
|
314 | + return sprintf('<option value="%s"%s>%s</option>', |
|
315 | 315 | $optionKey, |
316 | - selected( $this->args['value'], $optionKey, false ), |
|
317 | - $this->args['options'][ $optionKey ] |
|
316 | + selected($this->args['value'], $optionKey, false), |
|
317 | + $this->args['options'][$optionKey] |
|
318 | 318 | ); |
319 | 319 | } |
320 | 320 | |
@@ -325,27 +325,27 @@ discard block |
||
325 | 325 | * |
326 | 326 | * @return null|string |
327 | 327 | */ |
328 | - protected function singleInput( $type = 'checkbox' ) |
|
328 | + protected function singleInput($type = 'checkbox') |
|
329 | 329 | { |
330 | - $optionKey = key( $this->args['options'] ); |
|
330 | + $optionKey = key($this->args['options']); |
|
331 | 331 | |
332 | - $args = $this->multiInputArgs( $type, $optionKey, 1 ); |
|
332 | + $args = $this->multiInputArgs($type, $optionKey, 1); |
|
333 | 333 | |
334 | - if( !$args )return; |
|
334 | + if (!$args)return; |
|
335 | 335 | |
336 | 336 | $atts = $this->normalize(); |
337 | - $atts = wp_parse_args( $args['attributes'], $atts ); |
|
337 | + $atts = wp_parse_args($args['attributes'], $atts); |
|
338 | 338 | |
339 | 339 | $attributes = ''; |
340 | 340 | |
341 | - foreach( $atts as $key => $val ) { |
|
342 | - $attributes .= sprintf( '%s="%s" ', $key, $val ); |
|
341 | + foreach ($atts as $key => $val) { |
|
342 | + $attributes .= sprintf('%s="%s" ', $key, $val); |
|
343 | 343 | } |
344 | 344 | |
345 | - return sprintf( '<label for="%s"><input %s%s/> %s</label>', |
|
345 | + return sprintf('<label for="%s"><input %s%s/> %s</label>', |
|
346 | 346 | $atts['id'], |
347 | 347 | $attributes, |
348 | - checked( $args['value'], $atts['value'], false ), |
|
348 | + checked($args['value'], $atts['value'], false), |
|
349 | 349 | $args['label'] |
350 | 350 | ); |
351 | 351 | } |
@@ -11,15 +11,15 @@ |
||
11 | 11 | /** |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function render( array $defaults = [] ) |
|
14 | + public function render(array $defaults = []) |
|
15 | 15 | { |
16 | - $defaults = wp_parse_args( $defaults, [ |
|
16 | + $defaults = wp_parse_args($defaults, [ |
|
17 | 17 | 'class' => 'regular-text', |
18 | 18 | 'type' => 'text', |
19 | 19 | ]); |
20 | 20 | |
21 | - return sprintf( '<input %s/>%s', |
|
22 | - $this->implodeAttributes( $defaults ), |
|
21 | + return sprintf('<input %s/>%s', |
|
22 | + $this->implodeAttributes($defaults), |
|
23 | 23 | $this->generateDescription() |
24 | 24 | ); |
25 | 25 | } |