Completed
Push — develop ( 0b0716...7823b4 )
by Paul
02:04
created
src/Services/Validator.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -557,7 +557,7 @@
 block discarded – undo
557 557
 	/**
558 558
 	 * Validate that a required attribute exists.
559 559
 	 *
560
-	 * @param mixed $value
560
+	 * @param string $value
561 561
 	 *
562 562
 	 * @return bool
563 563
 	 */
Please login to merge, or discard this patch.
Spacing   +114 added lines, -114 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;
@@ -444,11 +444,11 @@  discard block
 block discarded – undo
444 444
 	 *
445 445
 	 * @return bool
446 446
 	 */
447
-	protected function validateAccepted( $value, $attribute )
447
+	protected function validateAccepted($value, $attribute)
448 448
 	{
449 449
 		$acceptable = ['yes', 'on', '1', 1, true, 'true'];
450 450
 
451
-		return $this->validateRequired( $attribute, $value ) && in_array( $value, $acceptable, true );
451
+		return $this->validateRequired($attribute, $value) && in_array($value, $acceptable, true);
452 452
 	}
453 453
 
454 454
 	/**
@@ -460,26 +460,26 @@  discard block
 block discarded – undo
460 460
 	 * @return void
461 461
 	 * @throws BadMethodCallException
462 462
 	 */
463
-	protected function validateAttribute( $rule, $attribute )
463
+	protected function validateAttribute($rule, $attribute)
464 464
 	{
465
-		list( $rule, $parameters ) = $this->parseRule( $rule );
465
+		list($rule, $parameters) = $this->parseRule($rule);
466 466
 
467
-		if( $rule == '' )return;
467
+		if ($rule == '')return;
468 468
 
469
-		$value = $this->getValue( $attribute );
469
+		$value = $this->getValue($attribute);
470 470
 
471 471
 		// is the value filled or is the attribute required?
472 472
 		// - removed $validatable assignment
473
-		$this->validateRequired( $attribute, $value ) || in_array( $rule, $this->implicitRules );
473
+		$this->validateRequired($attribute, $value) || in_array($rule, $this->implicitRules);
474 474
 
475 475
 		$method = "validate{$rule}";
476 476
 
477
-		if( !method_exists( $this, $method )) {
478
-			throw new BadMethodCallException( "Method [$method] does not exist." );
477
+		if (!method_exists($this, $method)) {
478
+			throw new BadMethodCallException("Method [$method] does not exist.");
479 479
 		}
480 480
 
481
-		if( !$this->$method( $value, $attribute, $parameters )) {
482
-			$this->addFailure( $attribute, $rule, $parameters );
481
+		if (!$this->$method($value, $attribute, $parameters)) {
482
+			$this->addFailure($attribute, $rule, $parameters);
483 483
 		}
484 484
 	}
485 485
 
@@ -491,11 +491,11 @@  discard block
 block discarded – undo
491 491
 	 *
492 492
 	 * @return bool
493 493
 	 */
494
-	protected function validateBetween( $value, $attribute, array $parameters )
494
+	protected function validateBetween($value, $attribute, array $parameters)
495 495
 	{
496
-		$this->requireParameterCount( 2, $parameters, 'between' );
496
+		$this->requireParameterCount(2, $parameters, 'between');
497 497
 
498
-		$size = $this->getSize( $attribute, $value );
498
+		$size = $this->getSize($attribute, $value);
499 499
 
500 500
 		return $size >= $parameters[0] && $size <= $parameters[1];
501 501
 	}
@@ -507,9 +507,9 @@  discard block
 block discarded – undo
507 507
 	 *
508 508
 	 * @return bool
509 509
 	 */
510
-	protected function validateEmail( $value )
510
+	protected function validateEmail($value)
511 511
 	{
512
-		return filter_var( $value, FILTER_VALIDATE_EMAIL ) !== false;
512
+		return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
513 513
 	}
514 514
 
515 515
 	/**
@@ -520,11 +520,11 @@  discard block
 block discarded – undo
520 520
 	 *
521 521
 	 * @return bool
522 522
 	 */
523
-	protected function validateMax( $value, $attribute, array $parameters )
523
+	protected function validateMax($value, $attribute, array $parameters)
524 524
 	{
525
-		$this->requireParameterCount( 1, $parameters, 'max' );
525
+		$this->requireParameterCount(1, $parameters, 'max');
526 526
 
527
-		return $this->getSize( $attribute, $value ) <= $parameters[0];
527
+		return $this->getSize($attribute, $value) <= $parameters[0];
528 528
 	}
529 529
 
530 530
 	/**
@@ -535,11 +535,11 @@  discard block
 block discarded – undo
535 535
 	 *
536 536
 	 * @return bool
537 537
 	 */
538
-	protected function validateMin( $value, $attribute, array $parameters )
538
+	protected function validateMin($value, $attribute, array $parameters)
539 539
 	{
540
-		$this->requireParameterCount( 1, $parameters, 'min' );
540
+		$this->requireParameterCount(1, $parameters, 'min');
541 541
 
542
-		return $this->getSize( $attribute, $value ) >= $parameters[0];
542
+		return $this->getSize($attribute, $value) >= $parameters[0];
543 543
 	}
544 544
 
545 545
 	/**
@@ -549,9 +549,9 @@  discard block
 block discarded – undo
549 549
 	 *
550 550
 	 * @return bool
551 551
 	 */
552
-	protected function validateNumeric( $value )
552
+	protected function validateNumeric($value)
553 553
 	{
554
-		return is_numeric( $value );
554
+		return is_numeric($value);
555 555
 	}
556 556
 
557 557
 	/**
@@ -561,12 +561,12 @@  discard block
 block discarded – undo
561 561
 	 *
562 562
 	 * @return bool
563 563
 	 */
564
-	protected function validateRequired( $value )
564
+	protected function validateRequired($value)
565 565
 	{
566
-		if( is_string( $value )) {
567
-			$value = trim( $value );
566
+		if (is_string($value)) {
567
+			$value = trim($value);
568 568
 		}
569
-		return is_null( $value ) || empty( $value )
569
+		return is_null($value) || empty($value)
570 570
 			? false
571 571
 			: true;
572 572
 	}
Please login to merge, or discard this patch.
Braces   +14 added lines, -8 removed lines patch added patch discarded remove patch
@@ -78,7 +78,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 		$value = $this->getValue( $attribute );
470 476
 
Please login to merge, or discard this patch.
src/Services/Normalizer.php 2 patches
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'], $this->inputTypes )) {
212
+		if (!isset($this->args['type']) || !in_array($this->args['type'], $this->inputTypes)) {
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.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -148,7 +148,9 @@  discard block
 block discarded – undo
148 148
 
149 149
 		// normalize truthy boolean attributes
150 150
 		foreach( $filtered as $key => $value ) {
151
-			if( !in_array( $key, self::BOOLEAN_ATTRIBUTES ))continue;
151
+			if( !in_array( $key, self::BOOLEAN_ATTRIBUTES )) {
152
+				continue;
153
+			}
152 154
 
153 155
 			if( $value !== false ) {
154 156
 				$filtered[ $key ] = '';
@@ -187,11 +189,15 @@  discard block
 block discarded – undo
187 189
 
188 190
 				if( $result ) {
189 191
 					// only allow data attributes to have an empty value
190
-					if( $wildcard != 'data-' && empty( $value ))continue;
192
+					if( $wildcard != 'data-' && empty( $value )) {
193
+						continue;
194
+					}
191 195
 
192 196
 					if( is_array( $value )) {
193 197
 
194
-						if( $wildcard != 'data-' )continue;
198
+						if( $wildcard != 'data-' ) {
199
+							continue;
200
+						}
195 201
 
196 202
 						$value = json_encode( $value );
197 203
 					}
Please login to merge, or discard this patch.
src/Helpers/Render.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	public $theme;
15 15
 	public $utility;
16 16
 
17
-	public function __construct( Media $media, PostMeta $postmeta, Theme $theme, Utility $utility )
17
+	public function __construct(Media $media, PostMeta $postmeta, Theme $theme, Utility $utility)
18 18
 	{
19 19
 		$this->media    = $media;
20 20
 		$this->postmeta = $postmeta;
@@ -22,88 +22,88 @@  discard block
 block discarded – undo
22 22
 		$this->utility  = $utility;
23 23
 	}
24 24
 
25
-	public function blockquote( $metaKey = false, array $attributes = [] )
25
+	public function blockquote($metaKey = false, array $attributes = [])
26 26
 	{
27
-		if( $value = $this->postmeta->get( $metaKey )) {
28
-			$this->utility->printTag( 'blockquote', wp_strip_all_tags( $value ), $attributes );
27
+		if ($value = $this->postmeta->get($metaKey)) {
28
+			$this->utility->printTag('blockquote', wp_strip_all_tags($value), $attributes);
29 29
 		}
30 30
 	}
31 31
 
32
-	public function button( $postId = 0, $title = false )
32
+	public function button($postId = 0, $title = false)
33 33
 	{
34
-		$post = get_post( $postId );
34
+		$post = get_post($postId);
35 35
 
36
-		if( !$postId || !$post )return;
37
-		if( !$title ) {
36
+		if (!$postId || !$post)return;
37
+		if (!$title) {
38 38
 			$title = $post->post_title;
39 39
 		}
40
-		printf( '<a href="%s" class="button"><span>%s</span></a>',
41
-			get_permalink( $post->ID ),
40
+		printf('<a href="%s" class="button"><span>%s</span></a>',
41
+			get_permalink($post->ID),
42 42
 			$title
43 43
 		);
44 44
 	}
45 45
 
46
-	public function buttons( $postIds = [] )
46
+	public function buttons($postIds = [])
47 47
 	{
48
-		foreach( (array) $postIds as $postId ) {
49
-			$this->button( $postId );
48
+		foreach ((array) $postIds as $postId) {
49
+			$this->button($postId);
50 50
 		}
51 51
 	}
52 52
 
53
-	public function content( $metaKey = false )
53
+	public function content($metaKey = false)
54 54
 	{
55 55
 		$content = $metaKey
56
-			? $this->postmeta->get( $metaKey )
56
+			? $this->postmeta->get($metaKey)
57 57
 			: get_the_content();
58 58
 
59
-		echo str_replace( ']]>', ']]&gt;', apply_filters( 'the_content', $content ));
59
+		echo str_replace(']]>', ']]&gt;', apply_filters('the_content', $content));
60 60
 	}
61 61
 
62
-	public function featured( $args = [] )
62
+	public function featured($args = [])
63 63
 	{
64
-		$args = wp_parse_args( $args, [
64
+		$args = wp_parse_args($args, [
65 65
 			'class' => 'featured',
66 66
 			'image' => get_post_thumbnail_id(),
67 67
 			'video' => 'featured_video',
68 68
 		]);
69
-		$featuredHtml = $this->media->video( wp_parse_args( $args, [
69
+		$featuredHtml = $this->media->video(wp_parse_args($args, [
70 70
 			'url' => $args['video'],
71 71
 		]));
72
-		if( empty( $featuredHtml ) && $featuredImage = $this->media->getImage( $args['image'] )) {
73
-			$featuredHtml = sprintf( '<div class="featured-image"><img src="%s" alt="%s"></div><figcaption>%s</figcaption>',
72
+		if (empty($featuredHtml) && $featuredImage = $this->media->getImage($args['image'])) {
73
+			$featuredHtml = sprintf('<div class="featured-image"><img src="%s" alt="%s"></div><figcaption>%s</figcaption>',
74 74
 				$featuredImage->large['url'],
75 75
 				$featuredImage->alt,
76 76
 				$featuredImage->caption
77 77
 			);
78 78
 		}
79
-		if( !empty( $featuredHtml )) {
80
-			printf( '<figure class="%s">%s</figure>', $args['class'], $featuredHtml );
79
+		if (!empty($featuredHtml)) {
80
+			printf('<figure class="%s">%s</figure>', $args['class'], $featuredHtml);
81 81
 		}
82 82
 	}
83 83
 
84
-	public function field( $name, array $args = [] )
84
+	public function field($name, array $args = [])
85 85
 	{
86 86
 	}
87 87
 
88
-	public function form( $name, array $args = [] )
88
+	public function form($name, array $args = [])
89 89
 	{
90 90
 	}
91 91
 
92
-	public function gallery( array $args = [] )
92
+	public function gallery(array $args = [])
93 93
 	{
94
-		echo $this->media->gallery( $args );
94
+		echo $this->media->gallery($args);
95 95
 	}
96 96
 
97
-	public function title( $metaKey = false, array $attributes = [] )
97
+	public function title($metaKey = false, array $attributes = [])
98 98
 	{
99
-		$tag = apply_filters( 'castor/render/title/tag', 'h2' );
99
+		$tag = apply_filters('castor/render/title/tag', 'h2');
100 100
 		$value = $metaKey
101
-			? $this->postmeta->get( $metaKey )
101
+			? $this->postmeta->get($metaKey)
102 102
 			: $this->theme->pageTitle();
103 103
 
104
-		if( !$value )return;
104
+		if (!$value)return;
105 105
 
106
-		$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes );
106
+		$this->utility->printTag($tag, wp_strip_all_tags($value), $attributes);
107 107
 	}
108 108
 
109 109
 	/**
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
 	 *
112 112
 	 * @return string|null
113 113
 	 */
114
-	public function video( $args )
114
+	public function video($args)
115 115
 	{
116
-		echo $this->media->video( $args );
116
+		echo $this->media->video($args);
117 117
 	}
118 118
 }
Please login to merge, or discard this patch.