Completed
Push — develop ( 556e46...dfa7d2 )
by Paul
02:07
created
src/Services/Validator.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -69,16 +69,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
src/Services/Normalizer.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	protected $args;
56 56
 
57
-	public function __construct( array $args = [] )
57
+	public function __construct(array $args = [])
58 58
 	{
59 59
 		$this->args = $args;
60 60
 	}
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
 	 *
65 65
 	 * @return array|string
66 66
 	 */
67
-	public function form( array $args = [], $implode = false )
67
+	public function form(array $args = [], $implode = false)
68 68
 	{
69
-		$attributes = $this->parseAttributes( self::FORM_ATTRIBUTES, $args );
69
+		$attributes = $this->parseAttributes(self::FORM_ATTRIBUTES, $args);
70 70
 
71
-		return $this->maybeImplode( $attributes, $implode );
71
+		return $this->maybeImplode($attributes, $implode);
72 72
 	}
73 73
 
74 74
 	/**
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return array|string
78 78
 	 */
79
-	public function input( array $args = [], $implode = false )
79
+	public function input(array $args = [], $implode = false)
80 80
 	{
81 81
 		$this->filterInputType();
82 82
 
83
-		$attributes = $this->parseAttributes( self::INPUT_ATTRIBUTES, $args );
83
+		$attributes = $this->parseAttributes(self::INPUT_ATTRIBUTES, $args);
84 84
 
85
-		return $this->maybeImplode( $attributes, $implode );
85
+		return $this->maybeImplode($attributes, $implode);
86 86
 	}
87 87
 
88 88
 	/**
@@ -92,24 +92,24 @@  discard block
 block discarded – undo
92 92
 	 *
93 93
 	 * @return array|string
94 94
 	 */
95
-	public function maybeImplode( array $attributes, $implode = true )
95
+	public function maybeImplode(array $attributes, $implode = true)
96 96
 	{
97
-		if( !$implode || $implode !== 'implode' ) {
97
+		if (!$implode || $implode !== 'implode') {
98 98
 			return $attributes;
99 99
 		}
100 100
 		$results = [];
101
-		foreach( $attributes as $key => $value ) {
101
+		foreach ($attributes as $key => $value) {
102 102
 			// if data attributes, use single quotes in case of json encoded values
103
-			$quotes = false !== stripos( $key, 'data-' ) ? "'" : '"';
104
-			if( is_array( $value )) {
105
-				$value = json_encode( $value );
103
+			$quotes = false !== stripos($key, 'data-') ? "'" : '"';
104
+			if (is_array($value)) {
105
+				$value = json_encode($value);
106 106
 				$quotes = "'";
107 107
 			}
108
-			$results[] = is_string( $key )
109
-				? sprintf( '%1$s=%3$s%2$s%3$s', $key, $value, $quotes )
108
+			$results[] = is_string($key)
109
+				? sprintf('%1$s=%3$s%2$s%3$s', $key, $value, $quotes)
110 110
 				: $value;
111 111
 		}
112
-		return implode( ' ', $results );
112
+		return implode(' ', $results);
113 113
 	}
114 114
 
115 115
 	/**
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @return array|string
119 119
 	 */
120
-	public function select( array $args = [], $implode = false )
120
+	public function select(array $args = [], $implode = false)
121 121
 	{
122
-		$attributes = $this->parseAttributes( self::SELECT_ATTRIBUTES, $args );
122
+		$attributes = $this->parseAttributes(self::SELECT_ATTRIBUTES, $args);
123 123
 
124
-		return $this->maybeImplode( $attributes, $implode );
124
+		return $this->maybeImplode($attributes, $implode);
125 125
 	}
126 126
 
127 127
 	/**
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @return array|string
131 131
 	 */
132
-	public function textarea( array $args = [], $implode = false )
132
+	public function textarea(array $args = [], $implode = false)
133 133
 	{
134
-		$attributes = $this->parseAttributes( self::TEXTAREA_ATTRIBUTES, $args );
134
+		$attributes = $this->parseAttributes(self::TEXTAREA_ATTRIBUTES, $args);
135 135
 
136
-		return $this->maybeImplode( $attributes, $implode );
136
+		return $this->maybeImplode($attributes, $implode);
137 137
 	}
138 138
 
139 139
 	/**
@@ -142,31 +142,31 @@  discard block
 block discarded – undo
142 142
 	 *
143 143
 	 * @return array
144 144
 	 */
145
-	protected function filterAttributes( array $attributeKeys )
145
+	protected function filterAttributes(array $attributeKeys)
146 146
 	{
147
-		$filtered = array_intersect_key( $this->args, array_flip( $attributeKeys ));
147
+		$filtered = array_intersect_key($this->args, array_flip($attributeKeys));
148 148
 
149 149
 		// normalize truthy boolean attributes
150
-		foreach( $filtered as $key => $value ) {
151
-			if( !in_array( $key, self::BOOLEAN_ATTRIBUTES ))continue;
150
+		foreach ($filtered as $key => $value) {
151
+			if (!in_array($key, self::BOOLEAN_ATTRIBUTES))continue;
152 152
 
153
-			if( $value !== false ) {
154
-				$filtered[ $key ] = '';
153
+			if ($value !== false) {
154
+				$filtered[$key] = '';
155 155
 				continue;
156 156
 			}
157 157
 
158
-			unset( $filtered[ $key ] );
158
+			unset($filtered[$key]);
159 159
 		}
160 160
 
161
-		$filteredKeys = array_filter( array_keys( $filtered ), function( $key ) use ( $filtered ) {
161
+		$filteredKeys = array_filter(array_keys($filtered), function($key) use ($filtered) {
162 162
 			return !(
163
-				empty( $filtered[ $key ] )
164
-				&& !is_numeric( $filtered[ $key ] )
165
-				&& !in_array( $key, self::BOOLEAN_ATTRIBUTES )
163
+				empty($filtered[$key])
164
+				&& !is_numeric($filtered[$key])
165
+				&& !in_array($key, self::BOOLEAN_ATTRIBUTES)
166 166
 			);
167 167
 		});
168 168
 
169
-		return array_intersect_key( $filtered, array_flip( $filteredKeys ));
169
+		return array_intersect_key($filtered, array_flip($filteredKeys));
170 170
 	}
171 171
 
172 172
 	/**
@@ -174,34 +174,34 @@  discard block
 block discarded – undo
174 174
 	 */
175 175
 	protected function filterGlobalAttributes()
176 176
 	{
177
-		$global = $this->filterAttributes( self::GLOBAL_ATTRIBUTES );
177
+		$global = $this->filterAttributes(self::GLOBAL_ATTRIBUTES);
178 178
 
179 179
 		$wildcards = [];
180 180
 
181
-		foreach( self::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard ) {
181
+		foreach (self::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) {
182 182
 
183
-			foreach( $this->args as $key => $value ) {
183
+			foreach ($this->args as $key => $value) {
184 184
 
185
-				$length = strlen( $wildcard );
186
-				$result = substr( $key, 0, $length) === $wildcard;
185
+				$length = strlen($wildcard);
186
+				$result = substr($key, 0, $length) === $wildcard;
187 187
 
188
-				if( $result ) {
188
+				if ($result) {
189 189
 					// only allow data attributes to have an empty value
190
-					if( $wildcard != 'data-' && empty( $value ))continue;
190
+					if ($wildcard != 'data-' && empty($value))continue;
191 191
 
192
-					if( is_array( $value )) {
192
+					if (is_array($value)) {
193 193
 
194
-						if( $wildcard != 'data-' )continue;
194
+						if ($wildcard != 'data-')continue;
195 195
 
196
-						$value = json_encode( $value );
196
+						$value = json_encode($value);
197 197
 					}
198 198
 
199
-					$wildcards[ $key ] = $value;
199
+					$wildcards[$key] = $value;
200 200
 				}
201 201
 			}
202 202
 		}
203 203
 
204
-		return array_merge( $global, $wildcards );
204
+		return array_merge($global, $wildcards);
205 205
 	}
206 206
 
207 207
 	/**
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 */
210 210
 	protected function filterInputType()
211 211
 	{
212
-		if( !isset( $this->args['type'] ) || !in_array( $this->args['type'], self::INPUT_TYPES )) {
212
+		if (!isset($this->args['type']) || !in_array($this->args['type'], self::INPUT_TYPES)) {
213 213
 			$this->args['type'] = 'text';
214 214
 		}
215 215
 	}
@@ -217,15 +217,15 @@  discard block
 block discarded – undo
217 217
 	/**
218 218
 	 * @return array
219 219
 	 */
220
-	protected function parseAttributes( array $attributes, array $args = [] )
220
+	protected function parseAttributes(array $attributes, array $args = [])
221 221
 	{
222
-		if( !empty( $args )) {
223
-			$this->args = array_change_key_case( $args );
222
+		if (!empty($args)) {
223
+			$this->args = array_change_key_case($args);
224 224
 		}
225 225
 
226 226
 		$global = $this->filterGlobalAttributes();
227
-		$local  = $this->filterAttributes( $attributes );
227
+		$local  = $this->filterAttributes($attributes);
228 228
 
229
-		return array_merge( $global, $local );
229
+		return array_merge($global, $local);
230 230
 	}
231 231
 }
Please login to merge, or discard this patch.
src/Forms/Form.php 2 patches
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 */
34 34
 	protected $normalize;
35 35
 
36
-	public function __construct( Field $field, Normalizer $normalize )
36
+	public function __construct(Field $field, Normalizer $normalize)
37 37
 	{
38 38
 		$this->args         = [];
39 39
 		$this->dependencies = [];
@@ -48,15 +48,15 @@  discard block
 block discarded – undo
48 48
 	 * @return mixed
49 49
 	 * @throws Exception
50 50
 	 */
51
-	public function __get( $property )
51
+	public function __get($property)
52 52
 	{
53
-		switch( $property ) {
53
+		switch ($property) {
54 54
 			case 'args':
55 55
 			case 'dependencies':
56 56
 			case 'fields':
57 57
 				return $this->$property;
58 58
 		}
59
-		throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property ));
59
+		throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property));
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
 	 * @return void
67 67
 	 * @throws Exception
68 68
 	 */
69
-	public function __set( $property, $value )
69
+	public function __set($property, $value)
70 70
 	{
71
-		switch( $property ) {
71
+		switch ($property) {
72 72
 			case 'args':
73 73
 			case 'dependencies':
74 74
 			case 'fields':
75 75
 				$this->$property = $value;
76 76
 				break;
77 77
 			default:
78
-				throw new Exception( sprintf( 'Invalid %s property: %s', __CLASS__, $property ));
78
+				throw new Exception(sprintf('Invalid %s property: %s', __CLASS__, $property));
79 79
 		}
80 80
 	}
81 81
 
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @return Form
86 86
 	 */
87
-	public function addField( array $args = [] )
87
+	public function addField(array $args = [])
88 88
 	{
89
-		$field = $this->field->normalize( $args );
89
+		$field = $this->field->normalize($args);
90 90
 
91
-		if( $field->args['render'] !== false ) {
91
+		if ($field->args['render'] !== false) {
92 92
 			$this->dependencies = array_unique(
93
-				array_merge( $field->dependencies, $this->dependencies )
93
+				array_merge($field->dependencies, $this->dependencies)
94 94
 			);
95 95
 			$this->fields[] = $field;
96 96
 		}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @return Form
105 105
 	 */
106
-	public function normalize( array $args = [] )
106
+	public function normalize(array $args = [])
107 107
 	{
108 108
 		$defaults = [
109 109
 			'action'     => '',
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 			'enctype'    => 'multipart/form-data',
114 114
 			'method'     => 'post',
115 115
 			'nonce'      => '',
116
-			'submit'     => __( 'Submit', 'site-reviews' ),
116
+			'submit'     => __('Submit', 'site-reviews'),
117 117
 		];
118 118
 
119
-		$this->args = array_merge( $defaults, $args );
119
+		$this->args = array_merge($defaults, $args);
120 120
 
121
-		$attributes = $this->normalize->form( $this->args, 'implode' );
121
+		$attributes = $this->normalize->form($this->args, 'implode');
122 122
 
123 123
 		$this->args['attributes'] = $attributes;
124 124
 
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
 	 *
133 133
 	 * @return string|void
134 134
 	 */
135
-	public function render( $print = true )
135
+	public function render($print = true)
136 136
 	{
137
-		$rendered = sprintf( '<form %s>%s%s</form>',
137
+		$rendered = sprintf('<form %s>%s%s</form>',
138 138
 			$this->args['attributes'],
139 139
 			$this->generateFields(),
140 140
 			$this->generateSubmitButton()
141 141
 		);
142 142
 
143
-		if( !!$print && $print !== 'return' ) {
143
+		if (!!$print && $print !== 'return') {
144 144
 			echo $rendered;
145 145
 		}
146 146
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	{
170 170
 		$hiddenFields = '';
171 171
 
172
-		$fields = array_reduce( $this->fields, function( $carry, $formField ) use ( &$hiddenFields ) {
172
+		$fields = array_reduce($this->fields, function($carry, $formField) use (&$hiddenFields) {
173 173
 
174 174
 			$stringLegend    = '<legend class="screen-reader-text"><span>%s</span></legend>';
175 175
 			$stringFieldset  = '<fieldset%s>%s%s</fieldset>';
@@ -185,30 +185,30 @@  discard block
 block discarded – undo
185 185
 			$rendered = $field->render();
186 186
 
187 187
 			// render hidden inputs outside the table
188
-			if( $field->args['type'] === 'hidden' ) {
188
+			if ($field->args['type'] === 'hidden') {
189 189
 				$hiddenFields .= $rendered;
190 190
 				return $carry;
191 191
 			}
192 192
 
193
-			$hiddenClass = $this->isFieldHidden( $formField ) ? 'hidden' : '';
193
+			$hiddenClass = $this->isFieldHidden($formField) ? 'hidden' : '';
194 194
 
195
-			if( $multi ) {
196
-				if( $depends = $formField->getDataDepends() ) {
197
-					$depends = sprintf( ' data-depends=\'%s\'', json_encode( $depends ));
195
+			if ($multi) {
196
+				if ($depends = $formField->getDataDepends()) {
197
+					$depends = sprintf(' data-depends=\'%s\'', json_encode($depends));
198 198
 				}
199 199
 
200
-				$legend = $label ? sprintf( $stringLegend, $label ) : '';
201
-				$rendered = sprintf( $stringFieldset, $depends, $legend, $rendered );
200
+				$legend = $label ? sprintf($stringLegend, $label) : '';
201
+				$rendered = sprintf($stringFieldset, $depends, $legend, $rendered);
202 202
 			}
203 203
 
204 204
 			$renderedField = $field->outside
205
-				? sprintf( $outsideRendered, $rendered )
206
-				: sprintf( $stringRendered, $hiddenClass, $label, $rendered );
205
+				? sprintf($outsideRendered, $rendered)
206
+				: sprintf($stringRendered, $hiddenClass, $label, $rendered);
207 207
 
208 208
 			return $carry . $renderedField;
209 209
 		});
210 210
 
211
-		return sprintf( '<table class="form-table"><tbody>%s</tbody></table>%s', $fields, $hiddenFields );
211
+		return sprintf('<table class="form-table"><tbody>%s</tbody></table>%s', $fields, $hiddenFields);
212 212
 	}
213 213
 
214 214
 	/**
@@ -220,19 +220,19 @@  discard block
 block discarded – undo
220 220
 	{
221 221
 		$args = $this->args['submit'];
222 222
 
223
-		is_array( $args ) ?: $args = ['text' => $args ];
223
+		is_array($args) ?: $args = ['text' => $args];
224 224
 
225 225
 		$args = shortcode_atts([
226
-			'text' => __( 'Save Changes', 'site-reviews' ),
226
+			'text' => __('Save Changes', 'site-reviews'),
227 227
 			'type' => 'primary',
228 228
 			'name' => 'submit',
229 229
 			'wrap' => true,
230 230
 			'other_attributes' => null,
231
-		], $args );
231
+		], $args);
232 232
 
233
-		if( is_admin() ) {
233
+		if (is_admin()) {
234 234
 			ob_start();
235
-			submit_button( $args['text'], $args['type'], $args['name'], $args['wrap'], $args['other_attributes'] );
235
+			submit_button($args['text'], $args['type'], $args['name'], $args['wrap'], $args['other_attributes']);
236 236
 			return ob_get_clean();
237 237
 		}
238 238
 	}
@@ -242,15 +242,15 @@  discard block
 block discarded – undo
242 242
 	 *
243 243
 	 * @return bool|null
244 244
 	 */
245
-	protected function isFieldHidden( $field )
245
+	protected function isFieldHidden($field)
246 246
 	{
247
-		if( !( $dependsOn = $field->getDataDepends() ))return;
247
+		if (!($dependsOn = $field->getDataDepends()))return;
248 248
 
249
-		foreach( $this->fields as $formField ) {
250
-			if( $dependsOn['name'] !== $formField->args['name'] )continue;
249
+		foreach ($this->fields as $formField) {
250
+			if ($dependsOn['name'] !== $formField->args['name'])continue;
251 251
 
252
-			if( is_array( $dependsOn['value'] )) {
253
-				return !in_array( $formField->args['value'], $dependsOn['value'] );
252
+			if (is_array($dependsOn['value'])) {
253
+				return !in_array($formField->args['value'], $dependsOn['value']);
254 254
 			}
255 255
 
256 256
 			return $dependsOn['value'] != $formField->args['value'];
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -244,10 +244,14 @@
 block discarded – undo
244 244
 	 */
245 245
 	protected function isFieldHidden( $field )
246 246
 	{
247
-		if( !( $dependsOn = $field->getDataDepends() ))return;
247
+		if( !( $dependsOn = $field->getDataDepends() )) {
248
+			return;
249
+		}
248 250
 
249 251
 		foreach( $this->fields as $formField ) {
250
-			if( $dependsOn['name'] !== $formField->args['name'] )continue;
252
+			if( $dependsOn['name'] !== $formField->args['name'] ) {
253
+				continue;
254
+			}
251 255
 
252 256
 			if( is_array( $dependsOn['value'] )) {
253 257
 				return !in_array( $formField->args['value'], $dependsOn['value'] );
Please login to merge, or discard this patch.
src/Forms/Fields/Base.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
src/Forms/Field.php 2 patches
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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([
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -116,7 +116,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.