@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | * @param bool|false $throwValidationError |
8 | 8 | * @return Assert |
9 | 9 | */ |
10 | -function Assert($value, $throwValidationError=false) |
|
10 | +function Assert($value, $throwValidationError = false) |
|
11 | 11 | { |
12 | 12 | $assert = new Assert($value); |
13 | - if ( ! $throwValidationError ) |
|
13 | + if ( ! $throwValidationError) |
|
14 | 14 | { |
15 | 15 | return $assert; |
16 | 16 | } |
@@ -24,19 +24,19 @@ discard block |
||
24 | 24 | * @param string $error |
25 | 25 | * @return Assert |
26 | 26 | */ |
27 | -function Validate($value, $name='', $code=0, $error='') |
|
27 | +function Validate($value, $name = '', $code = 0, $error = '') |
|
28 | 28 | { |
29 | 29 | $assert = new Assert($value); |
30 | 30 | $assert->setExceptionClass('Terah\Assert\ValidationFailedException'); |
31 | - if ( $name ) |
|
31 | + if ($name) |
|
32 | 32 | { |
33 | 33 | $assert->name($name); |
34 | 34 | } |
35 | - if ( $code ) |
|
35 | + if ($code) |
|
36 | 36 | { |
37 | 37 | $assert->code($code); |
38 | 38 | } |
39 | - if ( $error ) |
|
39 | + if ($error) |
|
40 | 40 | { |
41 | 41 | $assert->error($error); |
42 | 42 | } |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | const INVALID_IP_ADDRESS = 313; |
93 | 93 | |
94 | 94 | /** @var bool */ |
95 | - protected $nullOr = false; |
|
95 | + protected $nullOr = false; |
|
96 | 96 | |
97 | 97 | /** @var bool */ |
98 | - protected $emptyOr = false; |
|
98 | + protected $emptyOr = false; |
|
99 | 99 | |
100 | 100 | /** @var mixed */ |
101 | 101 | protected $value = null; |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | protected $propertyPath = null; |
108 | 108 | |
109 | 109 | /** @var int */ |
110 | - protected $overrideCode = null; |
|
110 | + protected $overrideCode = null; |
|
111 | 111 | |
112 | 112 | /** @var string */ |
113 | - protected $overrideError = ''; |
|
113 | + protected $overrideError = ''; |
|
114 | 114 | /** |
115 | 115 | * Exception to throw when an assertion failed. |
116 | 116 | * |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @param array $constraints |
196 | 196 | * @return AssertionFailedException |
197 | 197 | */ |
198 | - protected function createException($message, $code, $propertyPath, array $constraints = []) |
|
198 | + protected function createException($message, $code, $propertyPath, array $constraints = [ ]) |
|
199 | 199 | { |
200 | 200 | $exceptionClass = $this->exceptionClass; |
201 | 201 | $propertyPath = is_null($propertyPath) ? $this->propertyPath : $propertyPath; |
@@ -253,11 +253,11 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function eq($value2, $message = null, $propertyPath = null) |
255 | 255 | { |
256 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
256 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
257 | 257 | { |
258 | 258 | return $this; |
259 | 259 | } |
260 | - if ( $this->value != $value2 ) |
|
260 | + if ($this->value != $value2) |
|
261 | 261 | { |
262 | 262 | $message = $message ?: $this->overrideError; |
263 | 263 | $message = sprintf( |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | $this->stringify($this->value), |
266 | 266 | $this->stringify($value2) |
267 | 267 | ); |
268 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
268 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
269 | 269 | } |
270 | 270 | return $this; |
271 | 271 | } |
@@ -280,11 +280,11 @@ discard block |
||
280 | 280 | */ |
281 | 281 | public function greaterThan($value2, $message = null, $propertyPath = null) |
282 | 282 | { |
283 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
283 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
284 | 284 | { |
285 | 285 | return $this; |
286 | 286 | } |
287 | - if ( ! ( $this->value > $value2 ) ) |
|
287 | + if ( ! ($this->value > $value2)) |
|
288 | 288 | { |
289 | 289 | $message = $message ?: $this->overrideError; |
290 | 290 | $message = sprintf( |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | $this->stringify($this->value), |
293 | 293 | $this->stringify($value2) |
294 | 294 | ); |
295 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
295 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
296 | 296 | } |
297 | 297 | return $this; |
298 | 298 | } |
@@ -307,11 +307,11 @@ discard block |
||
307 | 307 | */ |
308 | 308 | public function greaterThanOrEq($value2, $message = null, $propertyPath = null) |
309 | 309 | { |
310 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
310 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
311 | 311 | { |
312 | 312 | return $this; |
313 | 313 | } |
314 | - if ( ! ( $this->value >= $value2 ) ) |
|
314 | + if ( ! ($this->value >= $value2)) |
|
315 | 315 | { |
316 | 316 | $message = $message ?: $this->overrideError; |
317 | 317 | $message = sprintf( |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | $this->stringify($this->value), |
320 | 320 | $this->stringify($value2) |
321 | 321 | ); |
322 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
322 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
323 | 323 | } |
324 | 324 | return $this; |
325 | 325 | } |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | */ |
335 | 335 | public function lessThan($value2, $message = null, $propertyPath = null) |
336 | 336 | { |
337 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
337 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
338 | 338 | { |
339 | 339 | return $this; |
340 | 340 | } |
341 | - if ( ! ( $this->value < $value2 ) ) |
|
341 | + if ( ! ($this->value < $value2)) |
|
342 | 342 | { |
343 | 343 | $message = $message ?: $this->overrideError; |
344 | 344 | $message = sprintf( |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | $this->stringify($this->value), |
347 | 347 | $this->stringify($value2) |
348 | 348 | ); |
349 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $propertyPath, ['expected' => $value2]); |
|
349 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $propertyPath, [ 'expected' => $value2 ]); |
|
350 | 350 | } |
351 | 351 | return $this; |
352 | 352 | } |
@@ -361,11 +361,11 @@ discard block |
||
361 | 361 | */ |
362 | 362 | public function lessThanOrEq($value2, $message = null, $propertyPath = null) |
363 | 363 | { |
364 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
364 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
365 | 365 | { |
366 | 366 | return $this; |
367 | 367 | } |
368 | - if ( ! ( $this->value <= $value2 ) ) |
|
368 | + if ( ! ($this->value <= $value2)) |
|
369 | 369 | { |
370 | 370 | $message = $message ?: $this->overrideError; |
371 | 371 | $message = sprintf( |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | $this->stringify($this->value), |
374 | 374 | $this->stringify($value2) |
375 | 375 | ); |
376 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $propertyPath, ['expected' => $value2]); |
|
376 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
377 | 377 | } |
378 | 378 | return $this; |
379 | 379 | } |
@@ -389,11 +389,11 @@ discard block |
||
389 | 389 | */ |
390 | 390 | public function same($value2, $message = null, $propertyPath = null) |
391 | 391 | { |
392 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
392 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
393 | 393 | { |
394 | 394 | return $this; |
395 | 395 | } |
396 | - if ( $this->value !== $value2 ) |
|
396 | + if ($this->value !== $value2) |
|
397 | 397 | { |
398 | 398 | $message = $message ?: $this->overrideError; |
399 | 399 | $message = sprintf( |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | $this->stringify($this->value), |
402 | 402 | $this->stringify($value2) |
403 | 403 | ); |
404 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $propertyPath, ['expected' => $value2]); |
|
404 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $propertyPath, [ 'expected' => $value2 ]); |
|
405 | 405 | } |
406 | 406 | return $this; |
407 | 407 | } |
@@ -417,11 +417,11 @@ discard block |
||
417 | 417 | */ |
418 | 418 | public function notEq($value2, $message = null, $propertyPath = null) |
419 | 419 | { |
420 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
420 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
421 | 421 | { |
422 | 422 | return $this; |
423 | 423 | } |
424 | - if ( $this->value == $value2 ) |
|
424 | + if ($this->value == $value2) |
|
425 | 425 | { |
426 | 426 | $message = $message ?: $this->overrideError; |
427 | 427 | $message = sprintf( |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | $this->stringify($this->value), |
430 | 430 | $this->stringify($value2) |
431 | 431 | ); |
432 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $propertyPath, ['expected' => $value2]); |
|
432 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
433 | 433 | } |
434 | 434 | return $this; |
435 | 435 | } |
@@ -443,11 +443,11 @@ discard block |
||
443 | 443 | */ |
444 | 444 | public function isCallable($message = null, $propertyPath = null) |
445 | 445 | { |
446 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
446 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
447 | 447 | { |
448 | 448 | return $this; |
449 | 449 | } |
450 | - if ( !is_callable($this->value) ) |
|
450 | + if ( ! is_callable($this->value)) |
|
451 | 451 | { |
452 | 452 | $message = $message ?: $this->overrideError; |
453 | 453 | $message = sprintf( |
@@ -470,11 +470,11 @@ discard block |
||
470 | 470 | */ |
471 | 471 | public function notSame($value2, $message = null, $propertyPath = null) |
472 | 472 | { |
473 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
473 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
474 | 474 | { |
475 | 475 | return $this; |
476 | 476 | } |
477 | - if ( $this->value === $value2 ) |
|
477 | + if ($this->value === $value2) |
|
478 | 478 | { |
479 | 479 | $message = $message ?: $this->overrideError; |
480 | 480 | $message = sprintf( |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | $this->stringify($this->value), |
483 | 483 | $this->stringify($value2) |
484 | 484 | ); |
485 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $propertyPath, ['expected' => $value2]); |
|
485 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $propertyPath, [ 'expected' => $value2 ]); |
|
486 | 486 | } |
487 | 487 | return $this; |
488 | 488 | } |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | { |
524 | 524 | $message = $message ?: $this->overrideError; |
525 | 525 | $message = $message ?: 'Value "%s" is not a valid status.'; |
526 | - return $this->integer($message, $propertyPath)->inArray([-1, 0, 1]); |
|
526 | + return $this->integer($message, $propertyPath)->inArray([-1, 0, 1 ]); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -567,11 +567,11 @@ discard block |
||
567 | 567 | */ |
568 | 568 | public function integer($message = null, $propertyPath = null) |
569 | 569 | { |
570 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
570 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
571 | 571 | { |
572 | 572 | return $this; |
573 | 573 | } |
574 | - if ( !is_int($this->value) ) |
|
574 | + if ( ! is_int($this->value)) |
|
575 | 575 | { |
576 | 576 | $message = $message ?: $this->overrideError; |
577 | 577 | $message = sprintf( |
@@ -593,11 +593,11 @@ discard block |
||
593 | 593 | */ |
594 | 594 | public function float($message = null, $propertyPath = null) |
595 | 595 | { |
596 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
596 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
597 | 597 | { |
598 | 598 | return $this; |
599 | 599 | } |
600 | - if ( ! is_float($this->value) ) |
|
600 | + if ( ! is_float($this->value)) |
|
601 | 601 | { |
602 | 602 | $message = $message ?: $this->overrideError; |
603 | 603 | $message = sprintf( |
@@ -619,11 +619,11 @@ discard block |
||
619 | 619 | */ |
620 | 620 | public function digit($message = null, $propertyPath = null) |
621 | 621 | { |
622 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
622 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
623 | 623 | { |
624 | 624 | return $this; |
625 | 625 | } |
626 | - if ( ! ctype_digit((string)$this->value) ) |
|
626 | + if ( ! ctype_digit((string)$this->value)) |
|
627 | 627 | { |
628 | 628 | $message = $message ?: $this->overrideError; |
629 | 629 | $message = sprintf( |
@@ -645,12 +645,12 @@ discard block |
||
645 | 645 | */ |
646 | 646 | public function date($message = null, $propertyPath = null) |
647 | 647 | { |
648 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
648 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
649 | 649 | { |
650 | 650 | return $this; |
651 | 651 | } |
652 | 652 | $this->notEmpty($message, $propertyPath); |
653 | - if ( strtotime($this->value) === false ) |
|
653 | + if (strtotime($this->value) === false) |
|
654 | 654 | { |
655 | 655 | $message = $message ?: $this->overrideError; |
656 | 656 | $message = sprintf( |
@@ -672,11 +672,11 @@ discard block |
||
672 | 672 | */ |
673 | 673 | public function integerish($message = null, $propertyPath = null) |
674 | 674 | { |
675 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
675 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
676 | 676 | { |
677 | 677 | return $this; |
678 | 678 | } |
679 | - if ( is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value) ) |
|
679 | + if (is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value)) |
|
680 | 680 | { |
681 | 681 | $message = $message ?: $this->overrideError; |
682 | 682 | $message = sprintf( |
@@ -698,11 +698,11 @@ discard block |
||
698 | 698 | */ |
699 | 699 | public function boolean($message = null, $propertyPath = null) |
700 | 700 | { |
701 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
701 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
702 | 702 | { |
703 | 703 | return $this; |
704 | 704 | } |
705 | - if ( ! is_bool($this->value) ) |
|
705 | + if ( ! is_bool($this->value)) |
|
706 | 706 | { |
707 | 707 | $message = $message ?: $this->overrideError; |
708 | 708 | $message = sprintf( |
@@ -724,11 +724,11 @@ discard block |
||
724 | 724 | */ |
725 | 725 | public function scalar($message = null, $propertyPath = null) |
726 | 726 | { |
727 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
727 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
728 | 728 | { |
729 | 729 | return $this; |
730 | 730 | } |
731 | - if ( !is_scalar($this->value) ) |
|
731 | + if ( ! is_scalar($this->value)) |
|
732 | 732 | { |
733 | 733 | $message = $message ?: $this->overrideError; |
734 | 734 | $message = sprintf( |
@@ -750,11 +750,11 @@ discard block |
||
750 | 750 | */ |
751 | 751 | public function notEmpty($message = null, $propertyPath = null) |
752 | 752 | { |
753 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
753 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
754 | 754 | { |
755 | 755 | return $this; |
756 | 756 | } |
757 | - if ( ( is_object($this->value) && empty((array)$this->value) ) || empty($this->value) ) |
|
757 | + if ((is_object($this->value) && empty((array)$this->value)) || empty($this->value)) |
|
758 | 758 | { |
759 | 759 | $message = $message ?: $this->overrideError; |
760 | 760 | $message = sprintf( |
@@ -776,11 +776,11 @@ discard block |
||
776 | 776 | */ |
777 | 777 | public function noContent($message = null, $propertyPath = null) |
778 | 778 | { |
779 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
779 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
780 | 780 | { |
781 | 781 | return $this; |
782 | 782 | } |
783 | - if ( !empty( $this->value ) ) |
|
783 | + if ( ! empty($this->value)) |
|
784 | 784 | { |
785 | 785 | $message = $message ?: $this->overrideError; |
786 | 786 | $message = sprintf( |
@@ -802,11 +802,11 @@ discard block |
||
802 | 802 | */ |
803 | 803 | public function notNull($message = null, $propertyPath = null) |
804 | 804 | { |
805 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
805 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
806 | 806 | { |
807 | 807 | return $this; |
808 | 808 | } |
809 | - if ( $this->value === null ) |
|
809 | + if ($this->value === null) |
|
810 | 810 | { |
811 | 811 | $message = $message ?: $this->overrideError; |
812 | 812 | $message = sprintf( |
@@ -828,11 +828,11 @@ discard block |
||
828 | 828 | */ |
829 | 829 | public function string($message = null, $propertyPath = null) |
830 | 830 | { |
831 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
831 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
832 | 832 | { |
833 | 833 | return $this; |
834 | 834 | } |
835 | - if ( !is_string($this->value) ) |
|
835 | + if ( ! is_string($this->value)) |
|
836 | 836 | { |
837 | 837 | $message = $message ?: $this->overrideError; |
838 | 838 | $message = sprintf( |
@@ -854,21 +854,21 @@ discard block |
||
854 | 854 | * @return Assert |
855 | 855 | * @throws AssertionFailedException |
856 | 856 | */ |
857 | - public function regex($pattern, $message=null, $propertyPath=null) |
|
857 | + public function regex($pattern, $message = null, $propertyPath = null) |
|
858 | 858 | { |
859 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
859 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
860 | 860 | { |
861 | 861 | return $this; |
862 | 862 | } |
863 | 863 | $this->string($message, $propertyPath); |
864 | - if ( ! preg_match($pattern, $this->value) ) |
|
864 | + if ( ! preg_match($pattern, $this->value)) |
|
865 | 865 | { |
866 | 866 | $message = $message ?: $this->overrideError; |
867 | 867 | $message = sprintf( |
868 | 868 | $message ?: 'Value "%s" does not match expression.', |
869 | 869 | $this->stringify($this->value) |
870 | 870 | ); |
871 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, ['pattern' => $pattern]); |
|
871 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, [ 'pattern' => $pattern ]); |
|
872 | 872 | } |
873 | 873 | return $this; |
874 | 874 | } |
@@ -881,13 +881,13 @@ discard block |
||
881 | 881 | */ |
882 | 882 | public function ipAddress($message = null, $propertyPath = null) |
883 | 883 | { |
884 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
884 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
885 | 885 | { |
886 | 886 | return $this; |
887 | 887 | } |
888 | 888 | $this->string($message, $propertyPath); |
889 | - $pattern = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'; |
|
890 | - if ( ! preg_match($pattern, $this->value) ) |
|
889 | + $pattern = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'; |
|
890 | + if ( ! preg_match($pattern, $this->value)) |
|
891 | 891 | { |
892 | 892 | $message = $message ?: $this->overrideError; |
893 | 893 | $message = sprintf( |
@@ -908,19 +908,19 @@ discard block |
||
908 | 908 | */ |
909 | 909 | public function notRegex($pattern, $message = null, $propertyPath = null) |
910 | 910 | { |
911 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
911 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
912 | 912 | { |
913 | 913 | return $this; |
914 | 914 | } |
915 | 915 | $this->string($message, $propertyPath); |
916 | - if ( preg_match($pattern, $this->value) ) |
|
916 | + if (preg_match($pattern, $this->value)) |
|
917 | 917 | { |
918 | 918 | $message = $message ?: $this->overrideError; |
919 | 919 | $message = sprintf( |
920 | 920 | $message ?: 'Value "%s" does not match expression.', |
921 | 921 | $this->stringify($this->value) |
922 | 922 | ); |
923 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, ['pattern' => $pattern]); |
|
923 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, [ 'pattern' => $pattern ]); |
|
924 | 924 | } |
925 | 925 | return $this; |
926 | 926 | } |
@@ -937,12 +937,12 @@ discard block |
||
937 | 937 | */ |
938 | 938 | public function length($length, $message = null, $propertyPath = null, $encoding = 'utf8') |
939 | 939 | { |
940 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
940 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
941 | 941 | { |
942 | 942 | return $this; |
943 | 943 | } |
944 | 944 | $this->string($message, $propertyPath); |
945 | - if ( mb_strlen($this->value, $encoding) !== $length ) |
|
945 | + if (mb_strlen($this->value, $encoding) !== $length) |
|
946 | 946 | { |
947 | 947 | $message = $message ?: $this->overrideError; |
948 | 948 | $message = sprintf( |
@@ -951,7 +951,7 @@ discard block |
||
951 | 951 | $length, |
952 | 952 | mb_strlen($this->value, $encoding) |
953 | 953 | ); |
954 | - $constraints = ['length' => $length, 'encoding' => $encoding]; |
|
954 | + $constraints = [ 'length' => $length, 'encoding' => $encoding ]; |
|
955 | 955 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_LENGTH, $propertyPath, $constraints); |
956 | 956 | } |
957 | 957 | return $this; |
@@ -969,22 +969,22 @@ discard block |
||
969 | 969 | */ |
970 | 970 | public function minLength($minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
971 | 971 | { |
972 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
972 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
973 | 973 | { |
974 | 974 | return $this; |
975 | 975 | } |
976 | 976 | $this->string($message, $propertyPath); |
977 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
977 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
978 | 978 | { |
979 | 979 | $message = $message ?: $this->overrideError; |
980 | - $message = sprintf( |
|
980 | + $message = sprintf( |
|
981 | 981 | $message |
982 | 982 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
983 | 983 | $this->stringify($this->value), |
984 | 984 | $minLength, |
985 | 985 | mb_strlen($this->value, $encoding) |
986 | 986 | ); |
987 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
987 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
988 | 988 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $propertyPath, $constraints); |
989 | 989 | } |
990 | 990 | return $this; |
@@ -1002,21 +1002,21 @@ discard block |
||
1002 | 1002 | */ |
1003 | 1003 | public function maxLength($maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
1004 | 1004 | { |
1005 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1005 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1006 | 1006 | { |
1007 | 1007 | return $this; |
1008 | 1008 | } |
1009 | 1009 | $this->string($message, $propertyPath); |
1010 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1010 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1011 | 1011 | { |
1012 | 1012 | $message = $message ?: $this->overrideError; |
1013 | - $message = sprintf( |
|
1013 | + $message = sprintf( |
|
1014 | 1014 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1015 | 1015 | $this->stringify($this->value), |
1016 | 1016 | $maxLength, |
1017 | 1017 | mb_strlen($this->value, $encoding) |
1018 | 1018 | ); |
1019 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1019 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1020 | 1020 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $propertyPath, $constraints); |
1021 | 1021 | } |
1022 | 1022 | return $this; |
@@ -1035,34 +1035,34 @@ discard block |
||
1035 | 1035 | */ |
1036 | 1036 | public function betweenLength($minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
1037 | 1037 | { |
1038 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1038 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1039 | 1039 | { |
1040 | 1040 | return $this; |
1041 | 1041 | } |
1042 | 1042 | $this->string($message, $propertyPath); |
1043 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
1043 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
1044 | 1044 | { |
1045 | 1045 | $message = $message ?: $this->overrideError; |
1046 | - $message = sprintf( |
|
1046 | + $message = sprintf( |
|
1047 | 1047 | $message |
1048 | 1048 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
1049 | 1049 | $this->stringify($this->value), |
1050 | 1050 | $minLength, |
1051 | 1051 | mb_strlen($this->value, $encoding) |
1052 | 1052 | ); |
1053 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
1053 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
1054 | 1054 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $propertyPath, $constraints); |
1055 | 1055 | } |
1056 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
1056 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
1057 | 1057 | { |
1058 | 1058 | $message = $message ?: $this->overrideError; |
1059 | - $message = sprintf( |
|
1059 | + $message = sprintf( |
|
1060 | 1060 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
1061 | 1061 | $this->stringify($this->value), |
1062 | 1062 | $maxLength, |
1063 | 1063 | mb_strlen($this->value, $encoding) |
1064 | 1064 | ); |
1065 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
1065 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
1066 | 1066 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $propertyPath, $constraints); |
1067 | 1067 | } |
1068 | 1068 | return $this; |
@@ -1080,20 +1080,20 @@ discard block |
||
1080 | 1080 | */ |
1081 | 1081 | public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
1082 | 1082 | { |
1083 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1083 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1084 | 1084 | { |
1085 | 1085 | return $this; |
1086 | 1086 | } |
1087 | 1087 | $this->string($message, $propertyPath); |
1088 | - if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 ) |
|
1088 | + if (mb_strpos($this->value, $needle, null, $encoding) !== 0) |
|
1089 | 1089 | { |
1090 | 1090 | $message = $message ?: $this->overrideError; |
1091 | - $message = sprintf( |
|
1091 | + $message = sprintf( |
|
1092 | 1092 | $message ?: 'Value "%s" does not start with "%s".', |
1093 | 1093 | $this->stringify($this->value), |
1094 | 1094 | $this->stringify($needle) |
1095 | 1095 | ); |
1096 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1096 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1097 | 1097 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints); |
1098 | 1098 | } |
1099 | 1099 | return $this; |
@@ -1111,21 +1111,21 @@ discard block |
||
1111 | 1111 | */ |
1112 | 1112 | public function endsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
1113 | 1113 | { |
1114 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1114 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1115 | 1115 | { |
1116 | 1116 | return $this; |
1117 | 1117 | } |
1118 | 1118 | $this->string($message, $propertyPath); |
1119 | 1119 | $stringPosition = mb_strlen($this->value, $encoding) - mb_strlen($needle, $encoding); |
1120 | - if ( mb_strripos($this->value, $needle, null, $encoding) !== $stringPosition ) |
|
1120 | + if (mb_strripos($this->value, $needle, null, $encoding) !== $stringPosition) |
|
1121 | 1121 | { |
1122 | 1122 | $message = $message ?: $this->overrideError; |
1123 | - $message = sprintf( |
|
1123 | + $message = sprintf( |
|
1124 | 1124 | $message ?: 'Value "%s" does not end with "%s".', |
1125 | 1125 | $this->stringify($this->value), |
1126 | 1126 | $this->stringify($needle) |
1127 | 1127 | ); |
1128 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1128 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1129 | 1129 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_END, $propertyPath, $constraints); |
1130 | 1130 | } |
1131 | 1131 | return $this; |
@@ -1143,20 +1143,20 @@ discard block |
||
1143 | 1143 | */ |
1144 | 1144 | public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
1145 | 1145 | { |
1146 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1146 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1147 | 1147 | { |
1148 | 1148 | return $this; |
1149 | 1149 | } |
1150 | 1150 | $this->string($message, $propertyPath); |
1151 | - if ( mb_strpos($this->value, $needle, null, $encoding) === false ) |
|
1151 | + if (mb_strpos($this->value, $needle, null, $encoding) === false) |
|
1152 | 1152 | { |
1153 | 1153 | $message = $message ?: $this->overrideError; |
1154 | - $message = sprintf( |
|
1154 | + $message = sprintf( |
|
1155 | 1155 | $message ?: 'Value "%s" does not contain "%s".', |
1156 | 1156 | $this->stringify($this->value), |
1157 | 1157 | $this->stringify($needle) |
1158 | 1158 | ); |
1159 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
1159 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
1160 | 1160 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints); |
1161 | 1161 | } |
1162 | 1162 | return $this; |
@@ -1173,11 +1173,11 @@ discard block |
||
1173 | 1173 | */ |
1174 | 1174 | public function choice(array $choices, $message = null, $propertyPath = null) |
1175 | 1175 | { |
1176 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1176 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1177 | 1177 | { |
1178 | 1178 | return $this; |
1179 | 1179 | } |
1180 | - if ( !in_array($this->value, $choices, true) ) |
|
1180 | + if ( ! in_array($this->value, $choices, true)) |
|
1181 | 1181 | { |
1182 | 1182 | $message = $message ?: $this->overrideError; |
1183 | 1183 | $message = sprintf( |
@@ -1185,7 +1185,7 @@ discard block |
||
1185 | 1185 | $this->stringify($this->value), |
1186 | 1186 | implode(", ", array_map('Terah\Assert\Assert::stringify', $choices)) |
1187 | 1187 | ); |
1188 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $propertyPath, ['choices' => $choices]); |
|
1188 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $propertyPath, [ 'choices' => $choices ]); |
|
1189 | 1189 | } |
1190 | 1190 | return $this; |
1191 | 1191 | } |
@@ -1202,7 +1202,7 @@ discard block |
||
1202 | 1202 | */ |
1203 | 1203 | public function inArray(array $choices, $message = null, $propertyPath = null) |
1204 | 1204 | { |
1205 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1205 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1206 | 1206 | { |
1207 | 1207 | return $this; |
1208 | 1208 | } |
@@ -1220,11 +1220,11 @@ discard block |
||
1220 | 1220 | */ |
1221 | 1221 | public function numeric($message = null, $propertyPath = null) |
1222 | 1222 | { |
1223 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1223 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1224 | 1224 | { |
1225 | 1225 | return $this; |
1226 | 1226 | } |
1227 | - if ( ! is_numeric($this->value) ) |
|
1227 | + if ( ! is_numeric($this->value)) |
|
1228 | 1228 | { |
1229 | 1229 | $message = $message ?: $this->overrideError; |
1230 | 1230 | $message = sprintf( |
@@ -1282,11 +1282,11 @@ discard block |
||
1282 | 1282 | */ |
1283 | 1283 | public function isArray($message = null, $propertyPath = null) |
1284 | 1284 | { |
1285 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1285 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1286 | 1286 | { |
1287 | 1287 | return $this; |
1288 | 1288 | } |
1289 | - if ( !is_array($this->value) ) |
|
1289 | + if ( ! is_array($this->value)) |
|
1290 | 1290 | { |
1291 | 1291 | $message = $message ?: $this->overrideError; |
1292 | 1292 | $message = sprintf( |
@@ -1308,11 +1308,11 @@ discard block |
||
1308 | 1308 | */ |
1309 | 1309 | public function isTraversable($message = null, $propertyPath = null) |
1310 | 1310 | { |
1311 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1311 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1312 | 1312 | { |
1313 | 1313 | return $this; |
1314 | 1314 | } |
1315 | - if ( !is_array($this->value) && !$this->value instanceof \Traversable ) |
|
1315 | + if ( ! is_array($this->value) && ! $this->value instanceof \Traversable) |
|
1316 | 1316 | { |
1317 | 1317 | $message = $message ?: $this->overrideError; |
1318 | 1318 | $message = sprintf( |
@@ -1334,11 +1334,11 @@ discard block |
||
1334 | 1334 | */ |
1335 | 1335 | public function isArrayAccessible($message = null, $propertyPath = null) |
1336 | 1336 | { |
1337 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1337 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1338 | 1338 | { |
1339 | 1339 | return $this; |
1340 | 1340 | } |
1341 | - if ( !is_array($this->value) && !$this->value instanceof \ArrayAccess ) |
|
1341 | + if ( ! is_array($this->value) && ! $this->value instanceof \ArrayAccess) |
|
1342 | 1342 | { |
1343 | 1343 | $message = $message ?: $this->overrideError; |
1344 | 1344 | $message = sprintf( |
@@ -1361,19 +1361,19 @@ discard block |
||
1361 | 1361 | */ |
1362 | 1362 | public function keyExists($key, $message = null, $propertyPath = null) |
1363 | 1363 | { |
1364 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1364 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1365 | 1365 | { |
1366 | 1366 | return $this; |
1367 | 1367 | } |
1368 | 1368 | $this->isArray($message, $propertyPath); |
1369 | - if ( !array_key_exists($key, $this->value) ) |
|
1369 | + if ( ! array_key_exists($key, $this->value)) |
|
1370 | 1370 | { |
1371 | 1371 | $message = $message ?: $this->overrideError; |
1372 | 1372 | $message = sprintf( |
1373 | 1373 | $message ?: 'Array does not contain an element with key "%s"', |
1374 | 1374 | $this->stringify($key) |
1375 | 1375 | ); |
1376 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $propertyPath, ['key' => $key]); |
|
1376 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $propertyPath, [ 'key' => $key ]); |
|
1377 | 1377 | } |
1378 | 1378 | return $this; |
1379 | 1379 | } |
@@ -1389,21 +1389,21 @@ discard block |
||
1389 | 1389 | */ |
1390 | 1390 | public function keysExist($keys, $message = null, $propertyPath = null) |
1391 | 1391 | { |
1392 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1392 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1393 | 1393 | { |
1394 | 1394 | return $this; |
1395 | 1395 | } |
1396 | 1396 | $this->isArray($message, $propertyPath); |
1397 | - foreach ( $keys as $key ) |
|
1397 | + foreach ($keys as $key) |
|
1398 | 1398 | { |
1399 | - if ( !array_key_exists($key, $this->value) ) |
|
1399 | + if ( ! array_key_exists($key, $this->value)) |
|
1400 | 1400 | { |
1401 | 1401 | $message = $message |
1402 | 1402 | ?: sprintf( |
1403 | 1403 | 'Array does not contain an element with key "%s"', |
1404 | 1404 | $this->stringify($key) |
1405 | 1405 | ); |
1406 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $propertyPath, ['key' => $key]); |
|
1406 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $propertyPath, [ 'key' => $key ]); |
|
1407 | 1407 | } |
1408 | 1408 | } |
1409 | 1409 | return $this; |
@@ -1420,19 +1420,19 @@ discard block |
||
1420 | 1420 | */ |
1421 | 1421 | public function propertyExists($key, $message = null, $propertyPath = null) |
1422 | 1422 | { |
1423 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1423 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1424 | 1424 | { |
1425 | 1425 | return $this; |
1426 | 1426 | } |
1427 | 1427 | $this->isObject($message, $propertyPath); |
1428 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1428 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1429 | 1429 | { |
1430 | 1430 | $message = $message |
1431 | 1431 | ?: sprintf( |
1432 | 1432 | 'Object does not contain a property with key "%s"', |
1433 | 1433 | $this->stringify($key) |
1434 | 1434 | ); |
1435 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $propertyPath, ['key' => $key]); |
|
1435 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $propertyPath, [ 'key' => $key ]); |
|
1436 | 1436 | } |
1437 | 1437 | return $this; |
1438 | 1438 | } |
@@ -1448,22 +1448,22 @@ discard block |
||
1448 | 1448 | */ |
1449 | 1449 | public function propertiesExist(array $keys, $message = null, $propertyPath = null) |
1450 | 1450 | { |
1451 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1451 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1452 | 1452 | { |
1453 | 1453 | return $this; |
1454 | 1454 | } |
1455 | 1455 | $this->isObject($message, $propertyPath); |
1456 | - foreach ( $keys as $key ) |
|
1456 | + foreach ($keys as $key) |
|
1457 | 1457 | { |
1458 | 1458 | // Using isset to allow resolution of magically defined properties |
1459 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
1459 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
1460 | 1460 | { |
1461 | 1461 | $message = $message |
1462 | 1462 | ?: sprintf( |
1463 | 1463 | 'Object does not contain a property with key "%s"', |
1464 | 1464 | $this->stringify($key) |
1465 | 1465 | ); |
1466 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $propertyPath, ['key' => $key]); |
|
1466 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $propertyPath, [ 'key' => $key ]); |
|
1467 | 1467 | } |
1468 | 1468 | } |
1469 | 1469 | return $this; |
@@ -1479,12 +1479,12 @@ discard block |
||
1479 | 1479 | */ |
1480 | 1480 | public function utf8($message = null, $propertyPath = null) |
1481 | 1481 | { |
1482 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1482 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1483 | 1483 | { |
1484 | 1484 | return $this; |
1485 | 1485 | } |
1486 | 1486 | $this->string($message, $propertyPath); |
1487 | - if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
1487 | + if (mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8') |
|
1488 | 1488 | { |
1489 | 1489 | $message = $message |
1490 | 1490 | ?: sprintf( |
@@ -1507,12 +1507,12 @@ discard block |
||
1507 | 1507 | */ |
1508 | 1508 | public function ascii($message = null, $propertyPath = null) |
1509 | 1509 | { |
1510 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1510 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1511 | 1511 | { |
1512 | 1512 | return $this; |
1513 | 1513 | } |
1514 | 1514 | $this->string($message, $propertyPath); |
1515 | - if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
1515 | + if ( ! preg_match('/^[ -~]+$/', $this->value)) |
|
1516 | 1516 | { |
1517 | 1517 | $message = $message |
1518 | 1518 | ?: sprintf( |
@@ -1535,19 +1535,19 @@ discard block |
||
1535 | 1535 | */ |
1536 | 1536 | public function keyIsset($key, $message = null, $propertyPath = null) |
1537 | 1537 | { |
1538 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1538 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1539 | 1539 | { |
1540 | 1540 | return $this; |
1541 | 1541 | } |
1542 | 1542 | $this->isArrayAccessible($message, $propertyPath); |
1543 | - if ( !isset( $this->value[$key] ) ) |
|
1543 | + if ( ! isset($this->value[ $key ])) |
|
1544 | 1544 | { |
1545 | 1545 | $message = $message ?: $this->overrideError; |
1546 | 1546 | $message = sprintf( |
1547 | 1547 | $message ?: 'The element with key "%s" was not found', |
1548 | 1548 | $this->stringify($key) |
1549 | 1549 | ); |
1550 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $propertyPath, ['key' => $key]); |
|
1550 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $propertyPath, [ 'key' => $key ]); |
|
1551 | 1551 | } |
1552 | 1552 | return $this; |
1553 | 1553 | } |
@@ -1563,12 +1563,12 @@ discard block |
||
1563 | 1563 | */ |
1564 | 1564 | public function notEmptyKey($key, $message = null, $propertyPath = null) |
1565 | 1565 | { |
1566 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1566 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1567 | 1567 | { |
1568 | 1568 | return $this; |
1569 | 1569 | } |
1570 | 1570 | $this->keyIsset($key, $message, $propertyPath); |
1571 | - (new Assert($this->value[$key]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $propertyPath); |
|
1571 | + (new Assert($this->value[ $key ]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $propertyPath); |
|
1572 | 1572 | return $this; |
1573 | 1573 | } |
1574 | 1574 | |
@@ -1582,11 +1582,11 @@ discard block |
||
1582 | 1582 | */ |
1583 | 1583 | public function notBlank($message = null, $propertyPath = null) |
1584 | 1584 | { |
1585 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1585 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1586 | 1586 | { |
1587 | 1587 | return $this; |
1588 | 1588 | } |
1589 | - if ( false === $this->value || ( empty( $this->value ) && '0' != $this->value ) ) |
|
1589 | + if (false === $this->value || (empty($this->value) && '0' != $this->value)) |
|
1590 | 1590 | { |
1591 | 1591 | $message = $message ?: $this->overrideError; |
1592 | 1592 | $message = sprintf( |
@@ -1609,11 +1609,11 @@ discard block |
||
1609 | 1609 | */ |
1610 | 1610 | public function isInstanceOf($className, $message = null, $propertyPath = null) |
1611 | 1611 | { |
1612 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1612 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1613 | 1613 | { |
1614 | 1614 | return $this; |
1615 | 1615 | } |
1616 | - if ( !( $this->value instanceof $className ) ) |
|
1616 | + if ( ! ($this->value instanceof $className)) |
|
1617 | 1617 | { |
1618 | 1618 | $message = $message ?: $this->overrideError; |
1619 | 1619 | $message = sprintf( |
@@ -1621,7 +1621,7 @@ discard block |
||
1621 | 1621 | $this->stringify($this->value), |
1622 | 1622 | $className |
1623 | 1623 | ); |
1624 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $propertyPath, ['class' => $className]); |
|
1624 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $propertyPath, [ 'class' => $className ]); |
|
1625 | 1625 | } |
1626 | 1626 | return $this; |
1627 | 1627 | } |
@@ -1637,11 +1637,11 @@ discard block |
||
1637 | 1637 | */ |
1638 | 1638 | public function notIsInstanceOf($className, $message = null, $propertyPath = null) |
1639 | 1639 | { |
1640 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1640 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1641 | 1641 | { |
1642 | 1642 | return $this; |
1643 | 1643 | } |
1644 | - if ( $this->value instanceof $className ) |
|
1644 | + if ($this->value instanceof $className) |
|
1645 | 1645 | { |
1646 | 1646 | $message = $message ?: $this->overrideError; |
1647 | 1647 | $message = sprintf( |
@@ -1649,7 +1649,7 @@ discard block |
||
1649 | 1649 | $this->stringify($this->value), |
1650 | 1650 | $className |
1651 | 1651 | ); |
1652 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $propertyPath, ['class' => $className]); |
|
1652 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $propertyPath, [ 'class' => $className ]); |
|
1653 | 1653 | } |
1654 | 1654 | return $this; |
1655 | 1655 | } |
@@ -1665,11 +1665,11 @@ discard block |
||
1665 | 1665 | */ |
1666 | 1666 | public function subclassOf($className, $message = null, $propertyPath = null) |
1667 | 1667 | { |
1668 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1668 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1669 | 1669 | { |
1670 | 1670 | return $this; |
1671 | 1671 | } |
1672 | - if ( !is_subclass_of($this->value, $className) ) |
|
1672 | + if ( ! is_subclass_of($this->value, $className)) |
|
1673 | 1673 | { |
1674 | 1674 | $message = $message ?: $this->overrideError; |
1675 | 1675 | $message = sprintf( |
@@ -1677,7 +1677,7 @@ discard block |
||
1677 | 1677 | $this->stringify($this->value), |
1678 | 1678 | $className |
1679 | 1679 | ); |
1680 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $propertyPath, ['class' => $className]); |
|
1680 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $propertyPath, [ 'class' => $className ]); |
|
1681 | 1681 | } |
1682 | 1682 | return $this; |
1683 | 1683 | } |
@@ -1694,12 +1694,12 @@ discard block |
||
1694 | 1694 | */ |
1695 | 1695 | public function range($minValue, $maxValue, $message = null, $propertyPath = null) |
1696 | 1696 | { |
1697 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1697 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1698 | 1698 | { |
1699 | 1699 | return $this; |
1700 | 1700 | } |
1701 | 1701 | $this->numeric($message, $propertyPath); |
1702 | - if ( $this->value < $minValue || $this->value > $maxValue ) |
|
1702 | + if ($this->value < $minValue || $this->value > $maxValue) |
|
1703 | 1703 | { |
1704 | 1704 | $message = $message ?: $this->overrideError; |
1705 | 1705 | $message = sprintf( |
@@ -1727,12 +1727,12 @@ discard block |
||
1727 | 1727 | */ |
1728 | 1728 | public function min($minValue, $message = null, $propertyPath = null) |
1729 | 1729 | { |
1730 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1730 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1731 | 1731 | { |
1732 | 1732 | return $this; |
1733 | 1733 | } |
1734 | 1734 | $this->numeric($message, $propertyPath); |
1735 | - if ( $this->value < $minValue ) |
|
1735 | + if ($this->value < $minValue) |
|
1736 | 1736 | { |
1737 | 1737 | $message = $message ?: $this->overrideError; |
1738 | 1738 | $message = sprintf( |
@@ -1740,7 +1740,7 @@ discard block |
||
1740 | 1740 | $this->stringify($this->value), |
1741 | 1741 | $this->stringify($minValue) |
1742 | 1742 | ); |
1743 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $propertyPath, ['min' => $minValue]); |
|
1743 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $propertyPath, [ 'min' => $minValue ]); |
|
1744 | 1744 | } |
1745 | 1745 | return $this; |
1746 | 1746 | } |
@@ -1756,12 +1756,12 @@ discard block |
||
1756 | 1756 | */ |
1757 | 1757 | public function max($maxValue, $message = null, $propertyPath = null) |
1758 | 1758 | { |
1759 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1759 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1760 | 1760 | { |
1761 | 1761 | return $this; |
1762 | 1762 | } |
1763 | 1763 | $this->numeric($message, $propertyPath); |
1764 | - if ( $this->value > $maxValue ) |
|
1764 | + if ($this->value > $maxValue) |
|
1765 | 1765 | { |
1766 | 1766 | $message = $message ?: $this->overrideError; |
1767 | 1767 | $message = sprintf( |
@@ -1769,7 +1769,7 @@ discard block |
||
1769 | 1769 | $this->stringify($this->value), |
1770 | 1770 | $this->stringify($maxValue) |
1771 | 1771 | ); |
1772 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $propertyPath, ['max' => $maxValue]); |
|
1772 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $propertyPath, [ 'max' => $maxValue ]); |
|
1773 | 1773 | } |
1774 | 1774 | return $this; |
1775 | 1775 | } |
@@ -1784,13 +1784,13 @@ discard block |
||
1784 | 1784 | */ |
1785 | 1785 | public function file($message = null, $propertyPath = null) |
1786 | 1786 | { |
1787 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1787 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1788 | 1788 | { |
1789 | 1789 | return $this; |
1790 | 1790 | } |
1791 | 1791 | $this->string($message, $propertyPath); |
1792 | 1792 | $this->notEmpty($message, $propertyPath); |
1793 | - if ( !is_file($this->value) ) |
|
1793 | + if ( ! is_file($this->value)) |
|
1794 | 1794 | { |
1795 | 1795 | $message = $message ?: $this->overrideError; |
1796 | 1796 | $message = sprintf( |
@@ -1810,13 +1810,13 @@ discard block |
||
1810 | 1810 | */ |
1811 | 1811 | public function fileExists($message = null, $propertyPath = null) |
1812 | 1812 | { |
1813 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1813 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1814 | 1814 | { |
1815 | 1815 | return $this; |
1816 | 1816 | } |
1817 | 1817 | $this->string($message, $propertyPath); |
1818 | 1818 | $this->notEmpty($message, $propertyPath); |
1819 | - if ( ! file_exists($this->value) ) |
|
1819 | + if ( ! file_exists($this->value)) |
|
1820 | 1820 | { |
1821 | 1821 | $message = $message ?: $this->overrideError; |
1822 | 1822 | $message = sprintf( |
@@ -1838,12 +1838,12 @@ discard block |
||
1838 | 1838 | */ |
1839 | 1839 | public function directory($message = null, $propertyPath = null) |
1840 | 1840 | { |
1841 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1841 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1842 | 1842 | { |
1843 | 1843 | return $this; |
1844 | 1844 | } |
1845 | 1845 | $this->string($message, $propertyPath); |
1846 | - if ( !is_dir($this->value) ) |
|
1846 | + if ( ! is_dir($this->value)) |
|
1847 | 1847 | { |
1848 | 1848 | $message = $message ?: $this->overrideError; |
1849 | 1849 | $message = sprintf( |
@@ -1865,12 +1865,12 @@ discard block |
||
1865 | 1865 | */ |
1866 | 1866 | public function readable($message = null, $propertyPath = null) |
1867 | 1867 | { |
1868 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1868 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1869 | 1869 | { |
1870 | 1870 | return $this; |
1871 | 1871 | } |
1872 | 1872 | $this->string($message, $propertyPath); |
1873 | - if ( !is_readable($this->value) ) |
|
1873 | + if ( ! is_readable($this->value)) |
|
1874 | 1874 | { |
1875 | 1875 | $message = $message ?: $this->overrideError; |
1876 | 1876 | $message = sprintf( |
@@ -1892,12 +1892,12 @@ discard block |
||
1892 | 1892 | */ |
1893 | 1893 | public function writeable($message = null, $propertyPath = null) |
1894 | 1894 | { |
1895 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1895 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1896 | 1896 | { |
1897 | 1897 | return $this; |
1898 | 1898 | } |
1899 | 1899 | $this->string($message, $propertyPath); |
1900 | - if ( !is_writeable($this->value) ) |
|
1900 | + if ( ! is_writeable($this->value)) |
|
1901 | 1901 | { |
1902 | 1902 | $message = $message ?: $this->overrideError; |
1903 | 1903 | $message = sprintf( |
@@ -1920,12 +1920,12 @@ discard block |
||
1920 | 1920 | */ |
1921 | 1921 | public function email($message = null, $propertyPath = null) |
1922 | 1922 | { |
1923 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1923 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1924 | 1924 | { |
1925 | 1925 | return $this; |
1926 | 1926 | } |
1927 | 1927 | $this->string($message, $propertyPath); |
1928 | - if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL) ) |
|
1928 | + if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL)) |
|
1929 | 1929 | { |
1930 | 1930 | $message = $message ?: $this->overrideError; |
1931 | 1931 | $message = sprintf( |
@@ -1938,7 +1938,7 @@ discard block |
||
1938 | 1938 | { |
1939 | 1939 | $host = substr($this->value, strpos($this->value, '@') + 1); |
1940 | 1940 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
1941 | - if ( version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false ) |
|
1941 | + if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) |
|
1942 | 1942 | { |
1943 | 1943 | $message = $message ?: $this->overrideError; |
1944 | 1944 | $message = sprintf( |
@@ -1959,7 +1959,7 @@ discard block |
||
1959 | 1959 | */ |
1960 | 1960 | public function emailPrefix($message = null, $propertyPath = null) |
1961 | 1961 | { |
1962 | - $this->value($this->value . '@example.com'); |
|
1962 | + $this->value($this->value.'@example.com'); |
|
1963 | 1963 | return $this->email($message, $propertyPath); |
1964 | 1964 | } |
1965 | 1965 | |
@@ -1979,12 +1979,12 @@ discard block |
||
1979 | 1979 | */ |
1980 | 1980 | public function url($message = null, $propertyPath = null) |
1981 | 1981 | { |
1982 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1982 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
1983 | 1983 | { |
1984 | 1984 | return $this; |
1985 | 1985 | } |
1986 | 1986 | $this->string($message, $propertyPath); |
1987 | - $protocols = ['http', 'https']; |
|
1987 | + $protocols = [ 'http', 'https' ]; |
|
1988 | 1988 | $pattern = '~^ |
1989 | 1989 | (%s):// # protocol |
1990 | 1990 | ( |
@@ -1999,8 +1999,8 @@ discard block |
||
1999 | 1999 | (:[0-9]+)? # a port (optional) |
2000 | 2000 | (/?|/\S+) # a /, nothing or a / with something |
2001 | 2001 | $~ixu'; |
2002 | - $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2003 | - if ( !preg_match($pattern, $this->value) ) |
|
2002 | + $pattern = sprintf($pattern, implode('|', $protocols)); |
|
2003 | + if ( ! preg_match($pattern, $this->value)) |
|
2004 | 2004 | { |
2005 | 2005 | $message = $message ?: $this->overrideError; |
2006 | 2006 | $message = sprintf( |
@@ -2025,13 +2025,13 @@ discard block |
||
2025 | 2025 | */ |
2026 | 2026 | public function domainName($message = null, $propertyPath = null) |
2027 | 2027 | { |
2028 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2028 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2029 | 2029 | { |
2030 | 2030 | return $this; |
2031 | 2031 | } |
2032 | 2032 | $this->string($message, $propertyPath); |
2033 | - $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2034 | - if ( ! preg_match($pattern, $this->value) ) |
|
2033 | + $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
2034 | + if ( ! preg_match($pattern, $this->value)) |
|
2035 | 2035 | { |
2036 | 2036 | $message = $message ?: $this->overrideError; |
2037 | 2037 | $message = sprintf( |
@@ -2053,7 +2053,7 @@ discard block |
||
2053 | 2053 | */ |
2054 | 2054 | public function alnum($message = null, $propertyPath = null) |
2055 | 2055 | { |
2056 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2056 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2057 | 2057 | { |
2058 | 2058 | return $this; |
2059 | 2059 | } |
@@ -2084,11 +2084,11 @@ discard block |
||
2084 | 2084 | */ |
2085 | 2085 | public function true($message = null, $propertyPath = null) |
2086 | 2086 | { |
2087 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2087 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2088 | 2088 | { |
2089 | 2089 | return $this; |
2090 | 2090 | } |
2091 | - if ( $this->value !== true ) |
|
2091 | + if ($this->value !== true) |
|
2092 | 2092 | { |
2093 | 2093 | $message = $message ?: $this->overrideError; |
2094 | 2094 | $message = sprintf( |
@@ -2110,11 +2110,11 @@ discard block |
||
2110 | 2110 | */ |
2111 | 2111 | public function truthy($message = null, $propertyPath = null) |
2112 | 2112 | { |
2113 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2113 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2114 | 2114 | { |
2115 | 2115 | return $this; |
2116 | 2116 | } |
2117 | - if ( ! $this->value ) |
|
2117 | + if ( ! $this->value) |
|
2118 | 2118 | { |
2119 | 2119 | $message = $message ?: $this->overrideError; |
2120 | 2120 | $message = sprintf( |
@@ -2136,11 +2136,11 @@ discard block |
||
2136 | 2136 | */ |
2137 | 2137 | public function false($message = null, $propertyPath = null) |
2138 | 2138 | { |
2139 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2139 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2140 | 2140 | { |
2141 | 2141 | return $this; |
2142 | 2142 | } |
2143 | - if ( $this->value !== false ) |
|
2143 | + if ($this->value !== false) |
|
2144 | 2144 | { |
2145 | 2145 | $message = $message ?: $this->overrideError; |
2146 | 2146 | $message = sprintf( |
@@ -2162,11 +2162,11 @@ discard block |
||
2162 | 2162 | */ |
2163 | 2163 | public function notFalse($message = null, $propertyPath = null) |
2164 | 2164 | { |
2165 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2165 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2166 | 2166 | { |
2167 | 2167 | return $this; |
2168 | 2168 | } |
2169 | - if ( $this->value === false ) |
|
2169 | + if ($this->value === false) |
|
2170 | 2170 | { |
2171 | 2171 | $message = $message ?: $this->overrideError; |
2172 | 2172 | $message = sprintf( |
@@ -2188,11 +2188,11 @@ discard block |
||
2188 | 2188 | */ |
2189 | 2189 | public function classExists($message = null, $propertyPath = null) |
2190 | 2190 | { |
2191 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2191 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2192 | 2192 | { |
2193 | 2193 | return $this; |
2194 | 2194 | } |
2195 | - if ( !class_exists($this->value) ) |
|
2195 | + if ( ! class_exists($this->value)) |
|
2196 | 2196 | { |
2197 | 2197 | $message = $message ?: $this->overrideError; |
2198 | 2198 | $message = sprintf( |
@@ -2215,12 +2215,12 @@ discard block |
||
2215 | 2215 | */ |
2216 | 2216 | public function implementsInterface($interfaceName, $message = null, $propertyPath = null) |
2217 | 2217 | { |
2218 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2218 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2219 | 2219 | { |
2220 | 2220 | return $this; |
2221 | 2221 | } |
2222 | 2222 | $reflection = new \ReflectionClass($this->value); |
2223 | - if ( !$reflection->implementsInterface($interfaceName) ) |
|
2223 | + if ( ! $reflection->implementsInterface($interfaceName)) |
|
2224 | 2224 | { |
2225 | 2225 | $message = $message ?: $this->overrideError; |
2226 | 2226 | $message = sprintf( |
@@ -2228,7 +2228,7 @@ discard block |
||
2228 | 2228 | $this->stringify($this->value), |
2229 | 2229 | $this->stringify($interfaceName) |
2230 | 2230 | ); |
2231 | - throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $propertyPath, ['interface' => $interfaceName]); |
|
2231 | + throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $propertyPath, [ 'interface' => $interfaceName ]); |
|
2232 | 2232 | } |
2233 | 2233 | return $this; |
2234 | 2234 | } |
@@ -2249,11 +2249,11 @@ discard block |
||
2249 | 2249 | */ |
2250 | 2250 | public function isJsonString($message = null, $propertyPath = null) |
2251 | 2251 | { |
2252 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2252 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2253 | 2253 | { |
2254 | 2254 | return $this; |
2255 | 2255 | } |
2256 | - if ( null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error() ) |
|
2256 | + if (null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error()) |
|
2257 | 2257 | { |
2258 | 2258 | $message = $message ?: $this->overrideError; |
2259 | 2259 | $message = sprintf( |
@@ -2277,16 +2277,16 @@ discard block |
||
2277 | 2277 | */ |
2278 | 2278 | public function uuid($message = null, $propertyPath = null) |
2279 | 2279 | { |
2280 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2280 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2281 | 2281 | { |
2282 | 2282 | return $this; |
2283 | 2283 | } |
2284 | - $this->value = str_replace(['urn:', 'uuid:', '{', '}'], '', $this->value); |
|
2285 | - if ( $this->value === '00000000-0000-0000-0000-000000000000' ) |
|
2284 | + $this->value = str_replace([ 'urn:', 'uuid:', '{', '}' ], '', $this->value); |
|
2285 | + if ($this->value === '00000000-0000-0000-0000-000000000000') |
|
2286 | 2286 | { |
2287 | 2287 | return $this; |
2288 | 2288 | } |
2289 | - if ( !preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $this->value) ) |
|
2289 | + if ( ! preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $this->value)) |
|
2290 | 2290 | { |
2291 | 2291 | $message = $message ?: $this->overrideError; |
2292 | 2292 | $message = sprintf( |
@@ -2309,11 +2309,11 @@ discard block |
||
2309 | 2309 | */ |
2310 | 2310 | public function count($count, $message = null, $propertyPath = null) |
2311 | 2311 | { |
2312 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2312 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2313 | 2313 | { |
2314 | 2314 | return $this; |
2315 | 2315 | } |
2316 | - if ( $count !== count($this->value) ) |
|
2316 | + if ($count !== count($this->value)) |
|
2317 | 2317 | { |
2318 | 2318 | $message = $message ?: $this->overrideError; |
2319 | 2319 | $message = sprintf( |
@@ -2321,7 +2321,7 @@ discard block |
||
2321 | 2321 | $this->stringify($this->value), |
2322 | 2322 | $this->stringify($count) |
2323 | 2323 | ); |
2324 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $propertyPath, ['count' => $count]); |
|
2324 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $propertyPath, [ 'count' => $count ]); |
|
2325 | 2325 | } |
2326 | 2326 | return $this; |
2327 | 2327 | } |
@@ -2334,24 +2334,24 @@ discard block |
||
2334 | 2334 | */ |
2335 | 2335 | protected function doAllOrNullOr($func, $args) |
2336 | 2336 | { |
2337 | - if ( $this->nullOr && is_null($this->value) ) |
|
2337 | + if ($this->nullOr && is_null($this->value)) |
|
2338 | 2338 | { |
2339 | 2339 | return true; |
2340 | 2340 | } |
2341 | - if ( $this->emptyOr && empty($this->value) ) |
|
2341 | + if ($this->emptyOr && empty($this->value)) |
|
2342 | 2342 | { |
2343 | 2343 | return true; |
2344 | 2344 | } |
2345 | - if ( $this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable() ) |
|
2345 | + if ($this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable()) |
|
2346 | 2346 | { |
2347 | - foreach ( $this->value as $idx => $value ) |
|
2347 | + foreach ($this->value as $idx => $value) |
|
2348 | 2348 | { |
2349 | 2349 | $object = (new Assert($value))->setExceptionClass($this->exceptionClass); |
2350 | - call_user_func_array([$object, $func], $args); |
|
2350 | + call_user_func_array([ $object, $func ], $args); |
|
2351 | 2351 | } |
2352 | 2352 | return true; |
2353 | 2353 | } |
2354 | - return ( $this->nullOr && is_null($this->value) ) || ( $this->emptyOr && empty($this->value) ) ? true : false; |
|
2354 | + return ($this->nullOr && is_null($this->value)) || ($this->emptyOr && empty($this->value)) ? true : false; |
|
2355 | 2355 | } |
2356 | 2356 | |
2357 | 2357 | /** |
@@ -2364,12 +2364,12 @@ discard block |
||
2364 | 2364 | */ |
2365 | 2365 | public function choicesNotEmpty(array $choices, $message = null, $propertyPath = null) |
2366 | 2366 | { |
2367 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2367 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2368 | 2368 | { |
2369 | 2369 | return $this; |
2370 | 2370 | } |
2371 | 2371 | $this->notEmpty($message, $propertyPath); |
2372 | - foreach ( $choices as $choice ) |
|
2372 | + foreach ($choices as $choice) |
|
2373 | 2373 | { |
2374 | 2374 | $this->notEmptyKey($choice, $message, $propertyPath); |
2375 | 2375 | } |
@@ -2387,12 +2387,12 @@ discard block |
||
2387 | 2387 | */ |
2388 | 2388 | public function methodExists($object, $message = null, $propertyPath = null) |
2389 | 2389 | { |
2390 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2390 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2391 | 2391 | { |
2392 | 2392 | return $this; |
2393 | 2393 | } |
2394 | 2394 | (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $propertyPath); |
2395 | - if ( !method_exists($object, $this->value) ) |
|
2395 | + if ( ! method_exists($object, $this->value)) |
|
2396 | 2396 | { |
2397 | 2397 | $message = $message ?: $this->overrideError; |
2398 | 2398 | $message = sprintf( |
@@ -2414,11 +2414,11 @@ discard block |
||
2414 | 2414 | */ |
2415 | 2415 | public function isObject($message = null, $propertyPath = null) |
2416 | 2416 | { |
2417 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2417 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
2418 | 2418 | { |
2419 | 2419 | return $this; |
2420 | 2420 | } |
2421 | - if ( !is_object($this->value) ) |
|
2421 | + if ( ! is_object($this->value)) |
|
2422 | 2422 | { |
2423 | 2423 | $message = $message ?: $this->overrideError; |
2424 | 2424 | $message = sprintf( |
@@ -2438,32 +2438,32 @@ discard block |
||
2438 | 2438 | */ |
2439 | 2439 | private function stringify($value) |
2440 | 2440 | { |
2441 | - if ( is_bool($value) ) |
|
2441 | + if (is_bool($value)) |
|
2442 | 2442 | { |
2443 | 2443 | return $value ? '<TRUE>' : '<FALSE>'; |
2444 | 2444 | } |
2445 | - if ( is_scalar($value) ) |
|
2445 | + if (is_scalar($value)) |
|
2446 | 2446 | { |
2447 | 2447 | $val = (string)$value; |
2448 | - if ( strlen($val) > 100 ) |
|
2448 | + if (strlen($val) > 100) |
|
2449 | 2449 | { |
2450 | - $val = substr($val, 0, 97) . '...'; |
|
2450 | + $val = substr($val, 0, 97).'...'; |
|
2451 | 2451 | } |
2452 | 2452 | return $val; |
2453 | 2453 | } |
2454 | - if ( is_array($value) ) |
|
2454 | + if (is_array($value)) |
|
2455 | 2455 | { |
2456 | 2456 | return '<ARRAY>'; |
2457 | 2457 | } |
2458 | - if ( is_object($value) ) |
|
2458 | + if (is_object($value)) |
|
2459 | 2459 | { |
2460 | 2460 | return get_class($value); |
2461 | 2461 | } |
2462 | - if ( is_resource($value) ) |
|
2462 | + if (is_resource($value)) |
|
2463 | 2463 | { |
2464 | 2464 | return '<RESOURCE>'; |
2465 | 2465 | } |
2466 | - if ( $value === null ) |
|
2466 | + if ($value === null) |
|
2467 | 2467 | { |
2468 | 2468 | return '<NULL>'; |
2469 | 2469 | } |