@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | namespace Terah\Assert; |
| 4 | 4 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @var string |
| 133 | 133 | */ |
| 134 | - protected $exceptionClass = 'Terah\Assert\AssertionFailedException'; |
|
| 134 | + protected $exceptionClass = 'Terah\Assert\AssertionFailedException'; |
|
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | 137 | * @param mixed $value |
@@ -149,22 +149,22 @@ discard block |
||
| 149 | 149 | * @param string $level |
| 150 | 150 | * @return Assert |
| 151 | 151 | */ |
| 152 | - public static function that($value, $name='', $code=0, $error='', $level=Assert::WARNING) |
|
| 152 | + public static function that($value, $name = '', $code = 0, $error = '', $level = Assert::WARNING) |
|
| 153 | 153 | { |
| 154 | 154 | $assert = new static($value); |
| 155 | - if ( $name ) |
|
| 155 | + if ($name) |
|
| 156 | 156 | { |
| 157 | 157 | $assert->name($name); |
| 158 | 158 | } |
| 159 | - if ( $code ) |
|
| 159 | + if ($code) |
|
| 160 | 160 | { |
| 161 | 161 | $assert->code($code); |
| 162 | 162 | } |
| 163 | - if ( $error ) |
|
| 163 | + if ($error) |
|
| 164 | 164 | { |
| 165 | 165 | $assert->error($error); |
| 166 | 166 | } |
| 167 | - if ( $level ) |
|
| 167 | + if ($level) |
|
| 168 | 168 | { |
| 169 | 169 | $assert->level($level); |
| 170 | 170 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @param string $level |
| 234 | 234 | * @return AssertionFailedException |
| 235 | 235 | */ |
| 236 | - protected function createException($message, $code, $propertyPath, array $constraints = [], $level=null) |
|
| 236 | + protected function createException($message, $code, $propertyPath, array $constraints = [ ], $level = null) |
|
| 237 | 237 | { |
| 238 | 238 | $exceptionClass = $this->exceptionClass; |
| 239 | 239 | $propertyPath = is_null($propertyPath) ? $this->propertyPath : $propertyPath; |
@@ -303,11 +303,11 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function eq($value2, $message = null, $propertyPath = null) |
| 305 | 305 | { |
| 306 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 306 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 307 | 307 | { |
| 308 | 308 | return $this; |
| 309 | 309 | } |
| 310 | - if ( $this->value != $value2 ) |
|
| 310 | + if ($this->value != $value2) |
|
| 311 | 311 | { |
| 312 | 312 | $message = $message ?: $this->overrideError; |
| 313 | 313 | $message = sprintf( |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | $this->stringify($this->value), |
| 316 | 316 | $this->stringify($value2) |
| 317 | 317 | ); |
| 318 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
| 318 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
| 319 | 319 | } |
| 320 | 320 | return $this; |
| 321 | 321 | } |
@@ -330,11 +330,11 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | public function greaterThan($value2, $message = null, $propertyPath = null) |
| 332 | 332 | { |
| 333 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 333 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 334 | 334 | { |
| 335 | 335 | return $this; |
| 336 | 336 | } |
| 337 | - if ( ! ( $this->value > $value2 ) ) |
|
| 337 | + if ( ! ($this->value > $value2)) |
|
| 338 | 338 | { |
| 339 | 339 | $message = $message ?: $this->overrideError; |
| 340 | 340 | $message = sprintf( |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | $this->stringify($this->value), |
| 343 | 343 | $this->stringify($value2) |
| 344 | 344 | ); |
| 345 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
| 345 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
| 346 | 346 | } |
| 347 | 347 | return $this; |
| 348 | 348 | } |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | public function greaterThanOrEq($value2, $message = null, $propertyPath = null) |
| 359 | 359 | { |
| 360 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 360 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 361 | 361 | { |
| 362 | 362 | return $this; |
| 363 | 363 | } |
| 364 | - if ( ! ( $this->value >= $value2 ) ) |
|
| 364 | + if ( ! ($this->value >= $value2)) |
|
| 365 | 365 | { |
| 366 | 366 | $message = $message ?: $this->overrideError; |
| 367 | 367 | $message = sprintf( |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | $this->stringify($this->value), |
| 370 | 370 | $this->stringify($value2) |
| 371 | 371 | ); |
| 372 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
| 372 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
| 373 | 373 | } |
| 374 | 374 | return $this; |
| 375 | 375 | } |
@@ -384,11 +384,11 @@ discard block |
||
| 384 | 384 | */ |
| 385 | 385 | public function lessThan($value2, $message = null, $propertyPath = null) |
| 386 | 386 | { |
| 387 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 387 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 388 | 388 | { |
| 389 | 389 | return $this; |
| 390 | 390 | } |
| 391 | - if ( ! ( $this->value < $value2 ) ) |
|
| 391 | + if ( ! ($this->value < $value2)) |
|
| 392 | 392 | { |
| 393 | 393 | $message = $message ?: $this->overrideError; |
| 394 | 394 | $message = sprintf( |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | $this->stringify($this->value), |
| 397 | 397 | $this->stringify($value2) |
| 398 | 398 | ); |
| 399 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $propertyPath, ['expected' => $value2]); |
|
| 399 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $propertyPath, [ 'expected' => $value2 ]); |
|
| 400 | 400 | } |
| 401 | 401 | return $this; |
| 402 | 402 | } |
@@ -411,11 +411,11 @@ discard block |
||
| 411 | 411 | */ |
| 412 | 412 | public function lessThanOrEq($value2, $message = null, $propertyPath = null) |
| 413 | 413 | { |
| 414 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 414 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 415 | 415 | { |
| 416 | 416 | return $this; |
| 417 | 417 | } |
| 418 | - if ( ! ( $this->value <= $value2 ) ) |
|
| 418 | + if ( ! ($this->value <= $value2)) |
|
| 419 | 419 | { |
| 420 | 420 | $message = $message ?: $this->overrideError; |
| 421 | 421 | $message = sprintf( |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | $this->stringify($this->value), |
| 424 | 424 | $this->stringify($value2) |
| 425 | 425 | ); |
| 426 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $propertyPath, ['expected' => $value2]); |
|
| 426 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
| 427 | 427 | } |
| 428 | 428 | return $this; |
| 429 | 429 | } |
@@ -439,11 +439,11 @@ discard block |
||
| 439 | 439 | */ |
| 440 | 440 | public function same($value2, $message = null, $propertyPath = null) |
| 441 | 441 | { |
| 442 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 442 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 443 | 443 | { |
| 444 | 444 | return $this; |
| 445 | 445 | } |
| 446 | - if ( $this->value !== $value2 ) |
|
| 446 | + if ($this->value !== $value2) |
|
| 447 | 447 | { |
| 448 | 448 | $message = $message ?: $this->overrideError; |
| 449 | 449 | $message = sprintf( |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | $this->stringify($this->value), |
| 452 | 452 | $this->stringify($value2) |
| 453 | 453 | ); |
| 454 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $propertyPath, ['expected' => $value2]); |
|
| 454 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $propertyPath, [ 'expected' => $value2 ]); |
|
| 455 | 455 | } |
| 456 | 456 | return $this; |
| 457 | 457 | } |
@@ -467,11 +467,11 @@ discard block |
||
| 467 | 467 | */ |
| 468 | 468 | public function notEq($value2, $message = null, $propertyPath = null) |
| 469 | 469 | { |
| 470 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 470 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 471 | 471 | { |
| 472 | 472 | return $this; |
| 473 | 473 | } |
| 474 | - if ( $this->value == $value2 ) |
|
| 474 | + if ($this->value == $value2) |
|
| 475 | 475 | { |
| 476 | 476 | $message = $message ?: $this->overrideError; |
| 477 | 477 | $message = sprintf( |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | $this->stringify($this->value), |
| 480 | 480 | $this->stringify($value2) |
| 481 | 481 | ); |
| 482 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $propertyPath, ['expected' => $value2]); |
|
| 482 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $propertyPath, [ 'expected' => $value2 ]); |
|
| 483 | 483 | } |
| 484 | 484 | return $this; |
| 485 | 485 | } |
@@ -493,11 +493,11 @@ discard block |
||
| 493 | 493 | */ |
| 494 | 494 | public function isCallable($message = null, $propertyPath = null) |
| 495 | 495 | { |
| 496 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 496 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 497 | 497 | { |
| 498 | 498 | return $this; |
| 499 | 499 | } |
| 500 | - if ( !is_callable($this->value) ) |
|
| 500 | + if ( ! is_callable($this->value)) |
|
| 501 | 501 | { |
| 502 | 502 | $message = $message ?: $this->overrideError; |
| 503 | 503 | $message = sprintf( |
@@ -520,11 +520,11 @@ discard block |
||
| 520 | 520 | */ |
| 521 | 521 | public function notSame($value2, $message = null, $propertyPath = null) |
| 522 | 522 | { |
| 523 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 523 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 524 | 524 | { |
| 525 | 525 | return $this; |
| 526 | 526 | } |
| 527 | - if ( $this->value === $value2 ) |
|
| 527 | + if ($this->value === $value2) |
|
| 528 | 528 | { |
| 529 | 529 | $message = $message ?: $this->overrideError; |
| 530 | 530 | $message = sprintf( |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | $this->stringify($this->value), |
| 533 | 533 | $this->stringify($value2) |
| 534 | 534 | ); |
| 535 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $propertyPath, ['expected' => $value2]); |
|
| 535 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $propertyPath, [ 'expected' => $value2 ]); |
|
| 536 | 536 | } |
| 537 | 537 | return $this; |
| 538 | 538 | } |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | * @return Assert |
| 557 | 557 | * @throws AssertionFailedException |
| 558 | 558 | */ |
| 559 | - public function unsignedInt($message=null, $propertyPath=null) |
|
| 559 | + public function unsignedInt($message = null, $propertyPath = null) |
|
| 560 | 560 | { |
| 561 | 561 | $message = $message ?: $this->overrideError; |
| 562 | 562 | $message = $message ?: 'Value "%s" is not an integer id.'; |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | { |
| 588 | 588 | $message = $message ?: $this->overrideError; |
| 589 | 589 | $message = $message ?: 'Value "%s" is not a valid status.'; |
| 590 | - return $this->integer($message, $propertyPath)->inArray([-1, 0, 1]); |
|
| 590 | + return $this->integer($message, $propertyPath)->inArray([-1, 0, 1 ]); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -631,11 +631,11 @@ discard block |
||
| 631 | 631 | */ |
| 632 | 632 | public function integer($message = null, $propertyPath = null) |
| 633 | 633 | { |
| 634 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 634 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 635 | 635 | { |
| 636 | 636 | return $this; |
| 637 | 637 | } |
| 638 | - if ( !is_int($this->value) ) |
|
| 638 | + if ( ! is_int($this->value)) |
|
| 639 | 639 | { |
| 640 | 640 | $message = $message ?: $this->overrideError; |
| 641 | 641 | $message = sprintf( |
@@ -657,11 +657,11 @@ discard block |
||
| 657 | 657 | */ |
| 658 | 658 | public function float($message = null, $propertyPath = null) |
| 659 | 659 | { |
| 660 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 660 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 661 | 661 | { |
| 662 | 662 | return $this; |
| 663 | 663 | } |
| 664 | - if ( ! is_float($this->value) ) |
|
| 664 | + if ( ! is_float($this->value)) |
|
| 665 | 665 | { |
| 666 | 666 | $message = $message ?: $this->overrideError; |
| 667 | 667 | $message = sprintf( |
@@ -683,11 +683,11 @@ discard block |
||
| 683 | 683 | */ |
| 684 | 684 | public function digit($message = null, $propertyPath = null) |
| 685 | 685 | { |
| 686 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 686 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 687 | 687 | { |
| 688 | 688 | return $this; |
| 689 | 689 | } |
| 690 | - if ( ! ctype_digit((string)$this->value) ) |
|
| 690 | + if ( ! ctype_digit((string)$this->value)) |
|
| 691 | 691 | { |
| 692 | 692 | $message = $message ?: $this->overrideError; |
| 693 | 693 | $message = sprintf( |
@@ -709,12 +709,12 @@ discard block |
||
| 709 | 709 | */ |
| 710 | 710 | public function date($message = null, $propertyPath = null) |
| 711 | 711 | { |
| 712 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 712 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 713 | 713 | { |
| 714 | 714 | return $this; |
| 715 | 715 | } |
| 716 | 716 | $this->notEmpty($message, $propertyPath); |
| 717 | - if ( strtotime($this->value) === false ) |
|
| 717 | + if (strtotime($this->value) === false) |
|
| 718 | 718 | { |
| 719 | 719 | $message = $message ?: $this->overrideError; |
| 720 | 720 | $message = sprintf( |
@@ -736,11 +736,11 @@ discard block |
||
| 736 | 736 | */ |
| 737 | 737 | public function integerish($message = null, $propertyPath = null) |
| 738 | 738 | { |
| 739 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 739 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 740 | 740 | { |
| 741 | 741 | return $this; |
| 742 | 742 | } |
| 743 | - if ( is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value) ) |
|
| 743 | + if (is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value)) |
|
| 744 | 744 | { |
| 745 | 745 | $message = $message ?: $this->overrideError; |
| 746 | 746 | $message = sprintf( |
@@ -762,11 +762,11 @@ discard block |
||
| 762 | 762 | */ |
| 763 | 763 | public function boolean($message = null, $propertyPath = null) |
| 764 | 764 | { |
| 765 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 765 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 766 | 766 | { |
| 767 | 767 | return $this; |
| 768 | 768 | } |
| 769 | - if ( ! is_bool($this->value) ) |
|
| 769 | + if ( ! is_bool($this->value)) |
|
| 770 | 770 | { |
| 771 | 771 | $message = $message ?: $this->overrideError; |
| 772 | 772 | $message = sprintf( |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | */ |
| 789 | 789 | public function scalar($message = null, $propertyPath = null) |
| 790 | 790 | { |
| 791 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 791 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 792 | 792 | { |
| 793 | 793 | return $this; |
| 794 | 794 | } |
| 795 | - if ( ! is_scalar($this->value) ) |
|
| 795 | + if ( ! is_scalar($this->value)) |
|
| 796 | 796 | { |
| 797 | 797 | $message = $message ?: $this->overrideError; |
| 798 | 798 | $message = sprintf( |
@@ -814,11 +814,11 @@ discard block |
||
| 814 | 814 | */ |
| 815 | 815 | public function notEmpty($message = null, $propertyPath = null) |
| 816 | 816 | { |
| 817 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 817 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 818 | 818 | { |
| 819 | 819 | return $this; |
| 820 | 820 | } |
| 821 | - if ( ( is_object($this->value) && empty((array)$this->value) ) || empty($this->value) ) |
|
| 821 | + if ((is_object($this->value) && empty((array)$this->value)) || empty($this->value)) |
|
| 822 | 822 | { |
| 823 | 823 | $message = $message ?: $this->overrideError; |
| 824 | 824 | $message = sprintf( |
@@ -840,11 +840,11 @@ discard block |
||
| 840 | 840 | */ |
| 841 | 841 | public function noContent($message = null, $propertyPath = null) |
| 842 | 842 | { |
| 843 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 843 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 844 | 844 | { |
| 845 | 845 | return $this; |
| 846 | 846 | } |
| 847 | - if ( !empty( $this->value ) ) |
|
| 847 | + if ( ! empty($this->value)) |
|
| 848 | 848 | { |
| 849 | 849 | $message = $message ?: $this->overrideError; |
| 850 | 850 | $message = sprintf( |
@@ -866,11 +866,11 @@ discard block |
||
| 866 | 866 | */ |
| 867 | 867 | public function notNull($message = null, $propertyPath = null) |
| 868 | 868 | { |
| 869 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 869 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 870 | 870 | { |
| 871 | 871 | return $this; |
| 872 | 872 | } |
| 873 | - if ( $this->value === null ) |
|
| 873 | + if ($this->value === null) |
|
| 874 | 874 | { |
| 875 | 875 | $message = $message ?: $this->overrideError; |
| 876 | 876 | $message = sprintf( |
@@ -892,11 +892,11 @@ discard block |
||
| 892 | 892 | */ |
| 893 | 893 | public function string($message = null, $propertyPath = null) |
| 894 | 894 | { |
| 895 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 895 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 896 | 896 | { |
| 897 | 897 | return $this; |
| 898 | 898 | } |
| 899 | - if ( !is_string($this->value) ) |
|
| 899 | + if ( ! is_string($this->value)) |
|
| 900 | 900 | { |
| 901 | 901 | $message = $message ?: $this->overrideError; |
| 902 | 902 | $message = sprintf( |
@@ -918,21 +918,21 @@ discard block |
||
| 918 | 918 | * @return Assert |
| 919 | 919 | * @throws AssertionFailedException |
| 920 | 920 | */ |
| 921 | - public function regex($pattern, $message=null, $propertyPath=null) |
|
| 921 | + public function regex($pattern, $message = null, $propertyPath = null) |
|
| 922 | 922 | { |
| 923 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 923 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 924 | 924 | { |
| 925 | 925 | return $this; |
| 926 | 926 | } |
| 927 | 927 | $this->string($message, $propertyPath); |
| 928 | - if ( ! preg_match($pattern, $this->value) ) |
|
| 928 | + if ( ! preg_match($pattern, $this->value)) |
|
| 929 | 929 | { |
| 930 | 930 | $message = $message ?: $this->overrideError; |
| 931 | 931 | $message = sprintf( |
| 932 | 932 | $message ?: 'Value "%s" does not match expression.', |
| 933 | 933 | $this->stringify($this->value) |
| 934 | 934 | ); |
| 935 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, ['pattern' => $pattern]); |
|
| 935 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, [ 'pattern' => $pattern ]); |
|
| 936 | 936 | } |
| 937 | 937 | return $this; |
| 938 | 938 | } |
@@ -945,13 +945,13 @@ discard block |
||
| 945 | 945 | */ |
| 946 | 946 | public function ipAddress($message = null, $propertyPath = null) |
| 947 | 947 | { |
| 948 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 948 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 949 | 949 | { |
| 950 | 950 | return $this; |
| 951 | 951 | } |
| 952 | 952 | $this->string($message, $propertyPath); |
| 953 | - $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])$/'; |
|
| 954 | - if ( ! preg_match($pattern, $this->value) ) |
|
| 953 | + $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])$/'; |
|
| 954 | + if ( ! preg_match($pattern, $this->value)) |
|
| 955 | 955 | { |
| 956 | 956 | $message = $message ?: $this->overrideError; |
| 957 | 957 | $message = sprintf( |
@@ -972,19 +972,19 @@ discard block |
||
| 972 | 972 | */ |
| 973 | 973 | public function notRegex($pattern, $message = null, $propertyPath = null) |
| 974 | 974 | { |
| 975 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 975 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 976 | 976 | { |
| 977 | 977 | return $this; |
| 978 | 978 | } |
| 979 | 979 | $this->string($message, $propertyPath); |
| 980 | - if ( preg_match($pattern, $this->value) ) |
|
| 980 | + if (preg_match($pattern, $this->value)) |
|
| 981 | 981 | { |
| 982 | 982 | $message = $message ?: $this->overrideError; |
| 983 | 983 | $message = sprintf( |
| 984 | 984 | $message ?: 'Value "%s" does not match expression.', |
| 985 | 985 | $this->stringify($this->value) |
| 986 | 986 | ); |
| 987 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, ['pattern' => $pattern]); |
|
| 987 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $propertyPath, [ 'pattern' => $pattern ]); |
|
| 988 | 988 | } |
| 989 | 989 | return $this; |
| 990 | 990 | } |
@@ -1001,12 +1001,12 @@ discard block |
||
| 1001 | 1001 | */ |
| 1002 | 1002 | public function length($length, $message = null, $propertyPath = null, $encoding = 'utf8') |
| 1003 | 1003 | { |
| 1004 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1004 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1005 | 1005 | { |
| 1006 | 1006 | return $this; |
| 1007 | 1007 | } |
| 1008 | 1008 | $this->string($message, $propertyPath); |
| 1009 | - if ( mb_strlen($this->value, $encoding) !== $length ) |
|
| 1009 | + if (mb_strlen($this->value, $encoding) !== $length) |
|
| 1010 | 1010 | { |
| 1011 | 1011 | $message = $message ?: $this->overrideError; |
| 1012 | 1012 | $message = sprintf( |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | $length, |
| 1016 | 1016 | mb_strlen($this->value, $encoding) |
| 1017 | 1017 | ); |
| 1018 | - $constraints = ['length' => $length, 'encoding' => $encoding]; |
|
| 1018 | + $constraints = [ 'length' => $length, 'encoding' => $encoding ]; |
|
| 1019 | 1019 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_LENGTH, $propertyPath, $constraints); |
| 1020 | 1020 | } |
| 1021 | 1021 | return $this; |
@@ -1033,22 +1033,22 @@ discard block |
||
| 1033 | 1033 | */ |
| 1034 | 1034 | public function minLength($minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
| 1035 | 1035 | { |
| 1036 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1036 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1037 | 1037 | { |
| 1038 | 1038 | return $this; |
| 1039 | 1039 | } |
| 1040 | 1040 | $this->string($message, $propertyPath); |
| 1041 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
| 1041 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
| 1042 | 1042 | { |
| 1043 | 1043 | $message = $message ?: $this->overrideError; |
| 1044 | - $message = sprintf( |
|
| 1044 | + $message = sprintf( |
|
| 1045 | 1045 | $message |
| 1046 | 1046 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
| 1047 | 1047 | $this->stringify($this->value), |
| 1048 | 1048 | $minLength, |
| 1049 | 1049 | mb_strlen($this->value, $encoding) |
| 1050 | 1050 | ); |
| 1051 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
| 1051 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
| 1052 | 1052 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $propertyPath, $constraints); |
| 1053 | 1053 | } |
| 1054 | 1054 | return $this; |
@@ -1066,21 +1066,21 @@ discard block |
||
| 1066 | 1066 | */ |
| 1067 | 1067 | public function maxLength($maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
| 1068 | 1068 | { |
| 1069 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1069 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1070 | 1070 | { |
| 1071 | 1071 | return $this; |
| 1072 | 1072 | } |
| 1073 | 1073 | $this->string($message, $propertyPath); |
| 1074 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
| 1074 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
| 1075 | 1075 | { |
| 1076 | 1076 | $message = $message ?: $this->overrideError; |
| 1077 | - $message = sprintf( |
|
| 1077 | + $message = sprintf( |
|
| 1078 | 1078 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
| 1079 | 1079 | $this->stringify($this->value), |
| 1080 | 1080 | $maxLength, |
| 1081 | 1081 | mb_strlen($this->value, $encoding) |
| 1082 | 1082 | ); |
| 1083 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
| 1083 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
| 1084 | 1084 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $propertyPath, $constraints); |
| 1085 | 1085 | } |
| 1086 | 1086 | return $this; |
@@ -1099,34 +1099,34 @@ discard block |
||
| 1099 | 1099 | */ |
| 1100 | 1100 | public function betweenLength($minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
| 1101 | 1101 | { |
| 1102 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1102 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1103 | 1103 | { |
| 1104 | 1104 | return $this; |
| 1105 | 1105 | } |
| 1106 | 1106 | $this->string($message, $propertyPath); |
| 1107 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
| 1107 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
| 1108 | 1108 | { |
| 1109 | 1109 | $message = $message ?: $this->overrideError; |
| 1110 | - $message = sprintf( |
|
| 1110 | + $message = sprintf( |
|
| 1111 | 1111 | $message |
| 1112 | 1112 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
| 1113 | 1113 | $this->stringify($this->value), |
| 1114 | 1114 | $minLength, |
| 1115 | 1115 | mb_strlen($this->value, $encoding) |
| 1116 | 1116 | ); |
| 1117 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
| 1117 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
| 1118 | 1118 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $propertyPath, $constraints); |
| 1119 | 1119 | } |
| 1120 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
| 1120 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
| 1121 | 1121 | { |
| 1122 | 1122 | $message = $message ?: $this->overrideError; |
| 1123 | - $message = sprintf( |
|
| 1123 | + $message = sprintf( |
|
| 1124 | 1124 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
| 1125 | 1125 | $this->stringify($this->value), |
| 1126 | 1126 | $maxLength, |
| 1127 | 1127 | mb_strlen($this->value, $encoding) |
| 1128 | 1128 | ); |
| 1129 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
| 1129 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
| 1130 | 1130 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $propertyPath, $constraints); |
| 1131 | 1131 | } |
| 1132 | 1132 | return $this; |
@@ -1144,20 +1144,20 @@ discard block |
||
| 1144 | 1144 | */ |
| 1145 | 1145 | public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
| 1146 | 1146 | { |
| 1147 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1147 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1148 | 1148 | { |
| 1149 | 1149 | return $this; |
| 1150 | 1150 | } |
| 1151 | 1151 | $this->string($message, $propertyPath); |
| 1152 | - if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 ) |
|
| 1152 | + if (mb_strpos($this->value, $needle, null, $encoding) !== 0) |
|
| 1153 | 1153 | { |
| 1154 | 1154 | $message = $message ?: $this->overrideError; |
| 1155 | - $message = sprintf( |
|
| 1155 | + $message = sprintf( |
|
| 1156 | 1156 | $message ?: 'Value "%s" does not start with "%s".', |
| 1157 | 1157 | $this->stringify($this->value), |
| 1158 | 1158 | $this->stringify($needle) |
| 1159 | 1159 | ); |
| 1160 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
| 1160 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
| 1161 | 1161 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints); |
| 1162 | 1162 | } |
| 1163 | 1163 | return $this; |
@@ -1175,21 +1175,21 @@ discard block |
||
| 1175 | 1175 | */ |
| 1176 | 1176 | public function endsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
| 1177 | 1177 | { |
| 1178 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1178 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1179 | 1179 | { |
| 1180 | 1180 | return $this; |
| 1181 | 1181 | } |
| 1182 | 1182 | $this->string($message, $propertyPath); |
| 1183 | 1183 | $stringPosition = mb_strlen($this->value, $encoding) - mb_strlen($needle, $encoding); |
| 1184 | - if ( mb_strripos($this->value, $needle, null, $encoding) !== $stringPosition ) |
|
| 1184 | + if (mb_strripos($this->value, $needle, null, $encoding) !== $stringPosition) |
|
| 1185 | 1185 | { |
| 1186 | 1186 | $message = $message ?: $this->overrideError; |
| 1187 | - $message = sprintf( |
|
| 1187 | + $message = sprintf( |
|
| 1188 | 1188 | $message ?: 'Value "%s" does not end with "%s".', |
| 1189 | 1189 | $this->stringify($this->value), |
| 1190 | 1190 | $this->stringify($needle) |
| 1191 | 1191 | ); |
| 1192 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
| 1192 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
| 1193 | 1193 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_END, $propertyPath, $constraints); |
| 1194 | 1194 | } |
| 1195 | 1195 | return $this; |
@@ -1207,20 +1207,20 @@ discard block |
||
| 1207 | 1207 | */ |
| 1208 | 1208 | public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
| 1209 | 1209 | { |
| 1210 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1210 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1211 | 1211 | { |
| 1212 | 1212 | return $this; |
| 1213 | 1213 | } |
| 1214 | 1214 | $this->string($message, $propertyPath); |
| 1215 | - if ( mb_strpos($this->value, $needle, null, $encoding) === false ) |
|
| 1215 | + if (mb_strpos($this->value, $needle, null, $encoding) === false) |
|
| 1216 | 1216 | { |
| 1217 | 1217 | $message = $message ?: $this->overrideError; |
| 1218 | - $message = sprintf( |
|
| 1218 | + $message = sprintf( |
|
| 1219 | 1219 | $message ?: 'Value "%s" does not contain "%s".', |
| 1220 | 1220 | $this->stringify($this->value), |
| 1221 | 1221 | $this->stringify($needle) |
| 1222 | 1222 | ); |
| 1223 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
| 1223 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
| 1224 | 1224 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints); |
| 1225 | 1225 | } |
| 1226 | 1226 | return $this; |
@@ -1237,11 +1237,11 @@ discard block |
||
| 1237 | 1237 | */ |
| 1238 | 1238 | public function choice(array $choices, $message = null, $propertyPath = null) |
| 1239 | 1239 | { |
| 1240 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1240 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1241 | 1241 | { |
| 1242 | 1242 | return $this; |
| 1243 | 1243 | } |
| 1244 | - if ( !in_array($this->value, $choices, true) ) |
|
| 1244 | + if ( ! in_array($this->value, $choices, true)) |
|
| 1245 | 1245 | { |
| 1246 | 1246 | $message = $message ?: $this->overrideError; |
| 1247 | 1247 | $message = sprintf( |
@@ -1249,7 +1249,7 @@ discard block |
||
| 1249 | 1249 | $this->stringify($this->value), |
| 1250 | 1250 | implode(", ", array_map('Terah\Assert\Assert::stringify', $choices)) |
| 1251 | 1251 | ); |
| 1252 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $propertyPath, ['choices' => $choices]); |
|
| 1252 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $propertyPath, [ 'choices' => $choices ]); |
|
| 1253 | 1253 | } |
| 1254 | 1254 | return $this; |
| 1255 | 1255 | } |
@@ -1266,7 +1266,7 @@ discard block |
||
| 1266 | 1266 | */ |
| 1267 | 1267 | public function inArray(array $choices, $message = null, $propertyPath = null) |
| 1268 | 1268 | { |
| 1269 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1269 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1270 | 1270 | { |
| 1271 | 1271 | return $this; |
| 1272 | 1272 | } |
@@ -1284,11 +1284,11 @@ discard block |
||
| 1284 | 1284 | */ |
| 1285 | 1285 | public function numeric($message = null, $propertyPath = null) |
| 1286 | 1286 | { |
| 1287 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1287 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1288 | 1288 | { |
| 1289 | 1289 | return $this; |
| 1290 | 1290 | } |
| 1291 | - if ( ! is_numeric($this->value) ) |
|
| 1291 | + if ( ! is_numeric($this->value)) |
|
| 1292 | 1292 | { |
| 1293 | 1293 | $message = $message ?: $this->overrideError; |
| 1294 | 1294 | $message = sprintf( |
@@ -1346,11 +1346,11 @@ discard block |
||
| 1346 | 1346 | */ |
| 1347 | 1347 | public function isArray($message = null, $propertyPath = null) |
| 1348 | 1348 | { |
| 1349 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1349 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1350 | 1350 | { |
| 1351 | 1351 | return $this; |
| 1352 | 1352 | } |
| 1353 | - if ( !is_array($this->value) ) |
|
| 1353 | + if ( ! is_array($this->value)) |
|
| 1354 | 1354 | { |
| 1355 | 1355 | $message = $message ?: $this->overrideError; |
| 1356 | 1356 | $message = sprintf( |
@@ -1372,11 +1372,11 @@ discard block |
||
| 1372 | 1372 | */ |
| 1373 | 1373 | public function isTraversable($message = null, $propertyPath = null) |
| 1374 | 1374 | { |
| 1375 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1375 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1376 | 1376 | { |
| 1377 | 1377 | return $this; |
| 1378 | 1378 | } |
| 1379 | - if ( !is_array($this->value) && !$this->value instanceof \Traversable ) |
|
| 1379 | + if ( ! is_array($this->value) && ! $this->value instanceof \Traversable) |
|
| 1380 | 1380 | { |
| 1381 | 1381 | $message = $message ?: $this->overrideError; |
| 1382 | 1382 | $message = sprintf( |
@@ -1398,11 +1398,11 @@ discard block |
||
| 1398 | 1398 | */ |
| 1399 | 1399 | public function isArrayAccessible($message = null, $propertyPath = null) |
| 1400 | 1400 | { |
| 1401 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1401 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1402 | 1402 | { |
| 1403 | 1403 | return $this; |
| 1404 | 1404 | } |
| 1405 | - if ( !is_array($this->value) && !$this->value instanceof \ArrayAccess ) |
|
| 1405 | + if ( ! is_array($this->value) && ! $this->value instanceof \ArrayAccess) |
|
| 1406 | 1406 | { |
| 1407 | 1407 | $message = $message ?: $this->overrideError; |
| 1408 | 1408 | $message = sprintf( |
@@ -1425,19 +1425,19 @@ discard block |
||
| 1425 | 1425 | */ |
| 1426 | 1426 | public function keyExists($key, $message = null, $propertyPath = null) |
| 1427 | 1427 | { |
| 1428 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1428 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1429 | 1429 | { |
| 1430 | 1430 | return $this; |
| 1431 | 1431 | } |
| 1432 | 1432 | $this->isArray($message, $propertyPath); |
| 1433 | - if ( !array_key_exists($key, $this->value) ) |
|
| 1433 | + if ( ! array_key_exists($key, $this->value)) |
|
| 1434 | 1434 | { |
| 1435 | 1435 | $message = $message ?: $this->overrideError; |
| 1436 | 1436 | $message = sprintf( |
| 1437 | 1437 | $message ?: 'Array does not contain an element with key "%s"', |
| 1438 | 1438 | $this->stringify($key) |
| 1439 | 1439 | ); |
| 1440 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $propertyPath, ['key' => $key]); |
|
| 1440 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $propertyPath, [ 'key' => $key ]); |
|
| 1441 | 1441 | } |
| 1442 | 1442 | return $this; |
| 1443 | 1443 | } |
@@ -1453,21 +1453,21 @@ discard block |
||
| 1453 | 1453 | */ |
| 1454 | 1454 | public function keysExist($keys, $message = null, $propertyPath = null) |
| 1455 | 1455 | { |
| 1456 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1456 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1457 | 1457 | { |
| 1458 | 1458 | return $this; |
| 1459 | 1459 | } |
| 1460 | 1460 | $this->isArray($message, $propertyPath); |
| 1461 | - foreach ( $keys as $key ) |
|
| 1461 | + foreach ($keys as $key) |
|
| 1462 | 1462 | { |
| 1463 | - if ( !array_key_exists($key, $this->value) ) |
|
| 1463 | + if ( ! array_key_exists($key, $this->value)) |
|
| 1464 | 1464 | { |
| 1465 | 1465 | $message = $message |
| 1466 | 1466 | ?: sprintf( |
| 1467 | 1467 | 'Array does not contain an element with key "%s"', |
| 1468 | 1468 | $this->stringify($key) |
| 1469 | 1469 | ); |
| 1470 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $propertyPath, ['key' => $key]); |
|
| 1470 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $propertyPath, [ 'key' => $key ]); |
|
| 1471 | 1471 | } |
| 1472 | 1472 | } |
| 1473 | 1473 | return $this; |
@@ -1484,19 +1484,19 @@ discard block |
||
| 1484 | 1484 | */ |
| 1485 | 1485 | public function propertyExists($key, $message = null, $propertyPath = null) |
| 1486 | 1486 | { |
| 1487 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1487 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1488 | 1488 | { |
| 1489 | 1489 | return $this; |
| 1490 | 1490 | } |
| 1491 | 1491 | $this->isObject($message, $propertyPath); |
| 1492 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
| 1492 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
| 1493 | 1493 | { |
| 1494 | 1494 | $message = $message |
| 1495 | 1495 | ?: sprintf( |
| 1496 | 1496 | 'Object does not contain a property with key "%s"', |
| 1497 | 1497 | $this->stringify($key) |
| 1498 | 1498 | ); |
| 1499 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $propertyPath, ['key' => $key]); |
|
| 1499 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $propertyPath, [ 'key' => $key ]); |
|
| 1500 | 1500 | } |
| 1501 | 1501 | return $this; |
| 1502 | 1502 | } |
@@ -1512,22 +1512,22 @@ discard block |
||
| 1512 | 1512 | */ |
| 1513 | 1513 | public function propertiesExist(array $keys, $message = null, $propertyPath = null) |
| 1514 | 1514 | { |
| 1515 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1515 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1516 | 1516 | { |
| 1517 | 1517 | return $this; |
| 1518 | 1518 | } |
| 1519 | 1519 | $this->isObject($message, $propertyPath); |
| 1520 | - foreach ( $keys as $key ) |
|
| 1520 | + foreach ($keys as $key) |
|
| 1521 | 1521 | { |
| 1522 | 1522 | // Using isset to allow resolution of magically defined properties |
| 1523 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
| 1523 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
| 1524 | 1524 | { |
| 1525 | 1525 | $message = $message |
| 1526 | 1526 | ?: sprintf( |
| 1527 | 1527 | 'Object does not contain a property with key "%s"', |
| 1528 | 1528 | $this->stringify($key) |
| 1529 | 1529 | ); |
| 1530 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $propertyPath, ['key' => $key]); |
|
| 1530 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $propertyPath, [ 'key' => $key ]); |
|
| 1531 | 1531 | } |
| 1532 | 1532 | } |
| 1533 | 1533 | return $this; |
@@ -1543,12 +1543,12 @@ discard block |
||
| 1543 | 1543 | */ |
| 1544 | 1544 | public function utf8($message = null, $propertyPath = null) |
| 1545 | 1545 | { |
| 1546 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1546 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1547 | 1547 | { |
| 1548 | 1548 | return $this; |
| 1549 | 1549 | } |
| 1550 | 1550 | $this->string($message, $propertyPath); |
| 1551 | - if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1551 | + if (mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8') |
|
| 1552 | 1552 | { |
| 1553 | 1553 | $message = $message |
| 1554 | 1554 | ?: sprintf( |
@@ -1571,12 +1571,12 @@ discard block |
||
| 1571 | 1571 | */ |
| 1572 | 1572 | public function ascii($message = null, $propertyPath = null) |
| 1573 | 1573 | { |
| 1574 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1574 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1575 | 1575 | { |
| 1576 | 1576 | return $this; |
| 1577 | 1577 | } |
| 1578 | 1578 | $this->string($message, $propertyPath); |
| 1579 | - if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1579 | + if ( ! preg_match('/^[ -~]+$/', $this->value)) |
|
| 1580 | 1580 | { |
| 1581 | 1581 | $message = $message |
| 1582 | 1582 | ?: sprintf( |
@@ -1599,19 +1599,19 @@ discard block |
||
| 1599 | 1599 | */ |
| 1600 | 1600 | public function keyIsset($key, $message = null, $propertyPath = null) |
| 1601 | 1601 | { |
| 1602 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1602 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1603 | 1603 | { |
| 1604 | 1604 | return $this; |
| 1605 | 1605 | } |
| 1606 | 1606 | $this->isArrayAccessible($message, $propertyPath); |
| 1607 | - if ( !isset( $this->value[$key] ) ) |
|
| 1607 | + if ( ! isset($this->value[ $key ])) |
|
| 1608 | 1608 | { |
| 1609 | 1609 | $message = $message ?: $this->overrideError; |
| 1610 | 1610 | $message = sprintf( |
| 1611 | 1611 | $message ?: 'The element with key "%s" was not found', |
| 1612 | 1612 | $this->stringify($key) |
| 1613 | 1613 | ); |
| 1614 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $propertyPath, ['key' => $key]); |
|
| 1614 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $propertyPath, [ 'key' => $key ]); |
|
| 1615 | 1615 | } |
| 1616 | 1616 | return $this; |
| 1617 | 1617 | } |
@@ -1627,12 +1627,12 @@ discard block |
||
| 1627 | 1627 | */ |
| 1628 | 1628 | public function notEmptyKey($key, $message = null, $propertyPath = null) |
| 1629 | 1629 | { |
| 1630 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1630 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1631 | 1631 | { |
| 1632 | 1632 | return $this; |
| 1633 | 1633 | } |
| 1634 | 1634 | $this->keyIsset($key, $message, $propertyPath); |
| 1635 | - (new Assert($this->value[$key]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $propertyPath); |
|
| 1635 | + (new Assert($this->value[ $key ]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $propertyPath); |
|
| 1636 | 1636 | return $this; |
| 1637 | 1637 | } |
| 1638 | 1638 | |
@@ -1646,11 +1646,11 @@ discard block |
||
| 1646 | 1646 | */ |
| 1647 | 1647 | public function notBlank($message = null, $propertyPath = null) |
| 1648 | 1648 | { |
| 1649 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1649 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1650 | 1650 | { |
| 1651 | 1651 | return $this; |
| 1652 | 1652 | } |
| 1653 | - if ( false === $this->value || ( empty( $this->value ) && '0' != $this->value ) ) |
|
| 1653 | + if (false === $this->value || (empty($this->value) && '0' != $this->value)) |
|
| 1654 | 1654 | { |
| 1655 | 1655 | $message = $message ?: $this->overrideError; |
| 1656 | 1656 | $message = sprintf( |
@@ -1673,11 +1673,11 @@ discard block |
||
| 1673 | 1673 | */ |
| 1674 | 1674 | public function isInstanceOf($className, $message = null, $propertyPath = null) |
| 1675 | 1675 | { |
| 1676 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1676 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1677 | 1677 | { |
| 1678 | 1678 | return $this; |
| 1679 | 1679 | } |
| 1680 | - if ( !( $this->value instanceof $className ) ) |
|
| 1680 | + if ( ! ($this->value instanceof $className)) |
|
| 1681 | 1681 | { |
| 1682 | 1682 | $message = $message ?: $this->overrideError; |
| 1683 | 1683 | $message = sprintf( |
@@ -1685,7 +1685,7 @@ discard block |
||
| 1685 | 1685 | $this->stringify($this->value), |
| 1686 | 1686 | $className |
| 1687 | 1687 | ); |
| 1688 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $propertyPath, ['class' => $className]); |
|
| 1688 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $propertyPath, [ 'class' => $className ]); |
|
| 1689 | 1689 | } |
| 1690 | 1690 | return $this; |
| 1691 | 1691 | } |
@@ -1701,11 +1701,11 @@ discard block |
||
| 1701 | 1701 | */ |
| 1702 | 1702 | public function notIsInstanceOf($className, $message = null, $propertyPath = null) |
| 1703 | 1703 | { |
| 1704 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1704 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1705 | 1705 | { |
| 1706 | 1706 | return $this; |
| 1707 | 1707 | } |
| 1708 | - if ( $this->value instanceof $className ) |
|
| 1708 | + if ($this->value instanceof $className) |
|
| 1709 | 1709 | { |
| 1710 | 1710 | $message = $message ?: $this->overrideError; |
| 1711 | 1711 | $message = sprintf( |
@@ -1713,7 +1713,7 @@ discard block |
||
| 1713 | 1713 | $this->stringify($this->value), |
| 1714 | 1714 | $className |
| 1715 | 1715 | ); |
| 1716 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $propertyPath, ['class' => $className]); |
|
| 1716 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $propertyPath, [ 'class' => $className ]); |
|
| 1717 | 1717 | } |
| 1718 | 1718 | return $this; |
| 1719 | 1719 | } |
@@ -1729,11 +1729,11 @@ discard block |
||
| 1729 | 1729 | */ |
| 1730 | 1730 | public function subclassOf($className, $message = null, $propertyPath = null) |
| 1731 | 1731 | { |
| 1732 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1732 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1733 | 1733 | { |
| 1734 | 1734 | return $this; |
| 1735 | 1735 | } |
| 1736 | - if ( !is_subclass_of($this->value, $className) ) |
|
| 1736 | + if ( ! is_subclass_of($this->value, $className)) |
|
| 1737 | 1737 | { |
| 1738 | 1738 | $message = $message ?: $this->overrideError; |
| 1739 | 1739 | $message = sprintf( |
@@ -1741,7 +1741,7 @@ discard block |
||
| 1741 | 1741 | $this->stringify($this->value), |
| 1742 | 1742 | $className |
| 1743 | 1743 | ); |
| 1744 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $propertyPath, ['class' => $className]); |
|
| 1744 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $propertyPath, [ 'class' => $className ]); |
|
| 1745 | 1745 | } |
| 1746 | 1746 | return $this; |
| 1747 | 1747 | } |
@@ -1758,12 +1758,12 @@ discard block |
||
| 1758 | 1758 | */ |
| 1759 | 1759 | public function range($minValue, $maxValue, $message = null, $propertyPath = null) |
| 1760 | 1760 | { |
| 1761 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1761 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1762 | 1762 | { |
| 1763 | 1763 | return $this; |
| 1764 | 1764 | } |
| 1765 | 1765 | $this->numeric($message, $propertyPath); |
| 1766 | - if ( $this->value < $minValue || $this->value > $maxValue ) |
|
| 1766 | + if ($this->value < $minValue || $this->value > $maxValue) |
|
| 1767 | 1767 | { |
| 1768 | 1768 | $message = $message ?: $this->overrideError; |
| 1769 | 1769 | $message = sprintf( |
@@ -1791,12 +1791,12 @@ discard block |
||
| 1791 | 1791 | */ |
| 1792 | 1792 | public function min($minValue, $message = null, $propertyPath = null) |
| 1793 | 1793 | { |
| 1794 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1794 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1795 | 1795 | { |
| 1796 | 1796 | return $this; |
| 1797 | 1797 | } |
| 1798 | 1798 | $this->numeric($message, $propertyPath); |
| 1799 | - if ( $this->value < $minValue ) |
|
| 1799 | + if ($this->value < $minValue) |
|
| 1800 | 1800 | { |
| 1801 | 1801 | $message = $message ?: $this->overrideError; |
| 1802 | 1802 | $message = sprintf( |
@@ -1804,7 +1804,7 @@ discard block |
||
| 1804 | 1804 | $this->stringify($this->value), |
| 1805 | 1805 | $this->stringify($minValue) |
| 1806 | 1806 | ); |
| 1807 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $propertyPath, ['min' => $minValue]); |
|
| 1807 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $propertyPath, [ 'min' => $minValue ]); |
|
| 1808 | 1808 | } |
| 1809 | 1809 | return $this; |
| 1810 | 1810 | } |
@@ -1820,12 +1820,12 @@ discard block |
||
| 1820 | 1820 | */ |
| 1821 | 1821 | public function max($maxValue, $message = null, $propertyPath = null) |
| 1822 | 1822 | { |
| 1823 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1823 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1824 | 1824 | { |
| 1825 | 1825 | return $this; |
| 1826 | 1826 | } |
| 1827 | 1827 | $this->numeric($message, $propertyPath); |
| 1828 | - if ( $this->value > $maxValue ) |
|
| 1828 | + if ($this->value > $maxValue) |
|
| 1829 | 1829 | { |
| 1830 | 1830 | $message = $message ?: $this->overrideError; |
| 1831 | 1831 | $message = sprintf( |
@@ -1833,7 +1833,7 @@ discard block |
||
| 1833 | 1833 | $this->stringify($this->value), |
| 1834 | 1834 | $this->stringify($maxValue) |
| 1835 | 1835 | ); |
| 1836 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $propertyPath, ['max' => $maxValue]); |
|
| 1836 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $propertyPath, [ 'max' => $maxValue ]); |
|
| 1837 | 1837 | } |
| 1838 | 1838 | return $this; |
| 1839 | 1839 | } |
@@ -1848,13 +1848,13 @@ discard block |
||
| 1848 | 1848 | */ |
| 1849 | 1849 | public function file($message = null, $propertyPath = null) |
| 1850 | 1850 | { |
| 1851 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1851 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1852 | 1852 | { |
| 1853 | 1853 | return $this; |
| 1854 | 1854 | } |
| 1855 | 1855 | $this->string($message, $propertyPath); |
| 1856 | 1856 | $this->notEmpty($message, $propertyPath); |
| 1857 | - if ( !is_file($this->value) ) |
|
| 1857 | + if ( ! is_file($this->value)) |
|
| 1858 | 1858 | { |
| 1859 | 1859 | $message = $message ?: $this->overrideError; |
| 1860 | 1860 | $message = sprintf( |
@@ -1874,13 +1874,13 @@ discard block |
||
| 1874 | 1874 | */ |
| 1875 | 1875 | public function fileExists($message = null, $propertyPath = null) |
| 1876 | 1876 | { |
| 1877 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1877 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1878 | 1878 | { |
| 1879 | 1879 | return $this; |
| 1880 | 1880 | } |
| 1881 | 1881 | $this->string($message, $propertyPath); |
| 1882 | 1882 | $this->notEmpty($message, $propertyPath); |
| 1883 | - if ( ! file_exists($this->value) ) |
|
| 1883 | + if ( ! file_exists($this->value)) |
|
| 1884 | 1884 | { |
| 1885 | 1885 | $message = $message ?: $this->overrideError; |
| 1886 | 1886 | $message = sprintf( |
@@ -1902,12 +1902,12 @@ discard block |
||
| 1902 | 1902 | */ |
| 1903 | 1903 | public function directory($message = null, $propertyPath = null) |
| 1904 | 1904 | { |
| 1905 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1905 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1906 | 1906 | { |
| 1907 | 1907 | return $this; |
| 1908 | 1908 | } |
| 1909 | 1909 | $this->string($message, $propertyPath); |
| 1910 | - if ( !is_dir($this->value) ) |
|
| 1910 | + if ( ! is_dir($this->value)) |
|
| 1911 | 1911 | { |
| 1912 | 1912 | $message = $message ?: $this->overrideError; |
| 1913 | 1913 | $message = sprintf( |
@@ -1929,12 +1929,12 @@ discard block |
||
| 1929 | 1929 | */ |
| 1930 | 1930 | public function readable($message = null, $propertyPath = null) |
| 1931 | 1931 | { |
| 1932 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1932 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1933 | 1933 | { |
| 1934 | 1934 | return $this; |
| 1935 | 1935 | } |
| 1936 | 1936 | $this->string($message, $propertyPath); |
| 1937 | - if ( !is_readable($this->value) ) |
|
| 1937 | + if ( ! is_readable($this->value)) |
|
| 1938 | 1938 | { |
| 1939 | 1939 | $message = $message ?: $this->overrideError; |
| 1940 | 1940 | $message = sprintf( |
@@ -1956,12 +1956,12 @@ discard block |
||
| 1956 | 1956 | */ |
| 1957 | 1957 | public function writeable($message = null, $propertyPath = null) |
| 1958 | 1958 | { |
| 1959 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1959 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1960 | 1960 | { |
| 1961 | 1961 | return $this; |
| 1962 | 1962 | } |
| 1963 | 1963 | $this->string($message, $propertyPath); |
| 1964 | - if ( !is_writeable($this->value) ) |
|
| 1964 | + if ( ! is_writeable($this->value)) |
|
| 1965 | 1965 | { |
| 1966 | 1966 | $message = $message ?: $this->overrideError; |
| 1967 | 1967 | $message = sprintf( |
@@ -1984,12 +1984,12 @@ discard block |
||
| 1984 | 1984 | */ |
| 1985 | 1985 | public function email($message = null, $propertyPath = null) |
| 1986 | 1986 | { |
| 1987 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1987 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1988 | 1988 | { |
| 1989 | 1989 | return $this; |
| 1990 | 1990 | } |
| 1991 | 1991 | $this->string($message, $propertyPath); |
| 1992 | - if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL) ) |
|
| 1992 | + if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL)) |
|
| 1993 | 1993 | { |
| 1994 | 1994 | $message = $message ?: $this->overrideError; |
| 1995 | 1995 | $message = sprintf( |
@@ -2002,7 +2002,7 @@ discard block |
||
| 2002 | 2002 | { |
| 2003 | 2003 | $host = substr($this->value, strpos($this->value, '@') + 1); |
| 2004 | 2004 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
| 2005 | - if ( version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false ) |
|
| 2005 | + if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) |
|
| 2006 | 2006 | { |
| 2007 | 2007 | $message = $message ?: $this->overrideError; |
| 2008 | 2008 | $message = sprintf( |
@@ -2023,7 +2023,7 @@ discard block |
||
| 2023 | 2023 | */ |
| 2024 | 2024 | public function emailPrefix($message = null, $propertyPath = null) |
| 2025 | 2025 | { |
| 2026 | - $this->value($this->value . '@example.com'); |
|
| 2026 | + $this->value($this->value.'@example.com'); |
|
| 2027 | 2027 | return $this->email($message, $propertyPath); |
| 2028 | 2028 | } |
| 2029 | 2029 | |
@@ -2043,12 +2043,12 @@ discard block |
||
| 2043 | 2043 | */ |
| 2044 | 2044 | public function url($message = null, $propertyPath = null) |
| 2045 | 2045 | { |
| 2046 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2046 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2047 | 2047 | { |
| 2048 | 2048 | return $this; |
| 2049 | 2049 | } |
| 2050 | 2050 | $this->string($message, $propertyPath); |
| 2051 | - $protocols = ['http', 'https']; |
|
| 2051 | + $protocols = [ 'http', 'https' ]; |
|
| 2052 | 2052 | $pattern = '~^ |
| 2053 | 2053 | (%s):// # protocol |
| 2054 | 2054 | ( |
@@ -2063,8 +2063,8 @@ discard block |
||
| 2063 | 2063 | (:[0-9]+)? # a port (optional) |
| 2064 | 2064 | (/?|/\S+) # a /, nothing or a / with something |
| 2065 | 2065 | $~ixu'; |
| 2066 | - $pattern = sprintf($pattern, implode('|', $protocols)); |
|
| 2067 | - if ( !preg_match($pattern, $this->value) ) |
|
| 2066 | + $pattern = sprintf($pattern, implode('|', $protocols)); |
|
| 2067 | + if ( ! preg_match($pattern, $this->value)) |
|
| 2068 | 2068 | { |
| 2069 | 2069 | $message = $message ?: $this->overrideError; |
| 2070 | 2070 | $message = sprintf( |
@@ -2089,13 +2089,13 @@ discard block |
||
| 2089 | 2089 | */ |
| 2090 | 2090 | public function domainName($message = null, $propertyPath = null) |
| 2091 | 2091 | { |
| 2092 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2092 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2093 | 2093 | { |
| 2094 | 2094 | return $this; |
| 2095 | 2095 | } |
| 2096 | 2096 | $this->string($message, $propertyPath); |
| 2097 | - $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
| 2098 | - if ( ! preg_match($pattern, $this->value) ) |
|
| 2097 | + $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
| 2098 | + if ( ! preg_match($pattern, $this->value)) |
|
| 2099 | 2099 | { |
| 2100 | 2100 | $message = $message ?: $this->overrideError; |
| 2101 | 2101 | $message = sprintf( |
@@ -2117,7 +2117,7 @@ discard block |
||
| 2117 | 2117 | */ |
| 2118 | 2118 | public function ausMobile($message = null, $propertyPath = null) |
| 2119 | 2119 | { |
| 2120 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2120 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2121 | 2121 | { |
| 2122 | 2122 | return $this; |
| 2123 | 2123 | } |
@@ -2125,7 +2125,7 @@ discard block |
||
| 2125 | 2125 | { |
| 2126 | 2126 | $this->regex('/^04[0-9]{8})$/', $message, $propertyPath); |
| 2127 | 2127 | } |
| 2128 | - catch ( AssertionFailedException $e ) |
|
| 2128 | + catch (AssertionFailedException $e) |
|
| 2129 | 2129 | { |
| 2130 | 2130 | $message = $message ?: $this->overrideError; |
| 2131 | 2131 | $message = sprintf( |
@@ -2148,7 +2148,7 @@ discard block |
||
| 2148 | 2148 | */ |
| 2149 | 2149 | public function alnum($message = null, $propertyPath = null) |
| 2150 | 2150 | { |
| 2151 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2151 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2152 | 2152 | { |
| 2153 | 2153 | return $this; |
| 2154 | 2154 | } |
@@ -2179,11 +2179,11 @@ discard block |
||
| 2179 | 2179 | */ |
| 2180 | 2180 | public function true($message = null, $propertyPath = null) |
| 2181 | 2181 | { |
| 2182 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2182 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2183 | 2183 | { |
| 2184 | 2184 | return $this; |
| 2185 | 2185 | } |
| 2186 | - if ( $this->value !== true ) |
|
| 2186 | + if ($this->value !== true) |
|
| 2187 | 2187 | { |
| 2188 | 2188 | $message = $message ?: $this->overrideError; |
| 2189 | 2189 | $message = sprintf( |
@@ -2206,11 +2206,11 @@ discard block |
||
| 2206 | 2206 | */ |
| 2207 | 2207 | public function truthy($message = null, $propertyPath = null) |
| 2208 | 2208 | { |
| 2209 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2209 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2210 | 2210 | { |
| 2211 | 2211 | return $this; |
| 2212 | 2212 | } |
| 2213 | - if ( ! $this->value ) |
|
| 2213 | + if ( ! $this->value) |
|
| 2214 | 2214 | { |
| 2215 | 2215 | $message = $message ?: $this->overrideError; |
| 2216 | 2216 | $message = sprintf( |
@@ -2232,11 +2232,11 @@ discard block |
||
| 2232 | 2232 | */ |
| 2233 | 2233 | public function false($message = null, $propertyPath = null) |
| 2234 | 2234 | { |
| 2235 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2235 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2236 | 2236 | { |
| 2237 | 2237 | return $this; |
| 2238 | 2238 | } |
| 2239 | - if ( $this->value !== false ) |
|
| 2239 | + if ($this->value !== false) |
|
| 2240 | 2240 | { |
| 2241 | 2241 | $message = $message ?: $this->overrideError; |
| 2242 | 2242 | $message = sprintf( |
@@ -2258,11 +2258,11 @@ discard block |
||
| 2258 | 2258 | */ |
| 2259 | 2259 | public function notFalse($message = null, $propertyPath = null) |
| 2260 | 2260 | { |
| 2261 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2261 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2262 | 2262 | { |
| 2263 | 2263 | return $this; |
| 2264 | 2264 | } |
| 2265 | - if ( $this->value === false ) |
|
| 2265 | + if ($this->value === false) |
|
| 2266 | 2266 | { |
| 2267 | 2267 | $message = $message ?: $this->overrideError; |
| 2268 | 2268 | $message = sprintf( |
@@ -2284,11 +2284,11 @@ discard block |
||
| 2284 | 2284 | */ |
| 2285 | 2285 | public function classExists($message = null, $propertyPath = null) |
| 2286 | 2286 | { |
| 2287 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2287 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2288 | 2288 | { |
| 2289 | 2289 | return $this; |
| 2290 | 2290 | } |
| 2291 | - if ( !class_exists($this->value) ) |
|
| 2291 | + if ( ! class_exists($this->value)) |
|
| 2292 | 2292 | { |
| 2293 | 2293 | $message = $message ?: $this->overrideError; |
| 2294 | 2294 | $message = sprintf( |
@@ -2311,12 +2311,12 @@ discard block |
||
| 2311 | 2311 | */ |
| 2312 | 2312 | public function implementsInterface($interfaceName, $message = null, $propertyPath = null) |
| 2313 | 2313 | { |
| 2314 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2314 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2315 | 2315 | { |
| 2316 | 2316 | return $this; |
| 2317 | 2317 | } |
| 2318 | 2318 | $reflection = new \ReflectionClass($this->value); |
| 2319 | - if ( !$reflection->implementsInterface($interfaceName) ) |
|
| 2319 | + if ( ! $reflection->implementsInterface($interfaceName)) |
|
| 2320 | 2320 | { |
| 2321 | 2321 | $message = $message ?: $this->overrideError; |
| 2322 | 2322 | $message = sprintf( |
@@ -2324,7 +2324,7 @@ discard block |
||
| 2324 | 2324 | $this->stringify($this->value), |
| 2325 | 2325 | $this->stringify($interfaceName) |
| 2326 | 2326 | ); |
| 2327 | - throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $propertyPath, ['interface' => $interfaceName]); |
|
| 2327 | + throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $propertyPath, [ 'interface' => $interfaceName ]); |
|
| 2328 | 2328 | } |
| 2329 | 2329 | return $this; |
| 2330 | 2330 | } |
@@ -2345,11 +2345,11 @@ discard block |
||
| 2345 | 2345 | */ |
| 2346 | 2346 | public function isJsonString($message = null, $propertyPath = null) |
| 2347 | 2347 | { |
| 2348 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2348 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2349 | 2349 | { |
| 2350 | 2350 | return $this; |
| 2351 | 2351 | } |
| 2352 | - if ( null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error() ) |
|
| 2352 | + if (null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error()) |
|
| 2353 | 2353 | { |
| 2354 | 2354 | $message = $message ?: $this->overrideError; |
| 2355 | 2355 | $message = sprintf( |
@@ -2373,16 +2373,16 @@ discard block |
||
| 2373 | 2373 | */ |
| 2374 | 2374 | public function uuid($message = null, $propertyPath = null) |
| 2375 | 2375 | { |
| 2376 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2376 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2377 | 2377 | { |
| 2378 | 2378 | return $this; |
| 2379 | 2379 | } |
| 2380 | - $this->value = str_replace(['urn:', 'uuid:', '{', '}'], '', $this->value); |
|
| 2381 | - if ( $this->value === '00000000-0000-0000-0000-000000000000' ) |
|
| 2380 | + $this->value = str_replace([ 'urn:', 'uuid:', '{', '}' ], '', $this->value); |
|
| 2381 | + if ($this->value === '00000000-0000-0000-0000-000000000000') |
|
| 2382 | 2382 | { |
| 2383 | 2383 | return $this; |
| 2384 | 2384 | } |
| 2385 | - 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) ) |
|
| 2385 | + 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)) |
|
| 2386 | 2386 | { |
| 2387 | 2387 | $message = $message ?: $this->overrideError; |
| 2388 | 2388 | $message = sprintf( |
@@ -2408,11 +2408,11 @@ discard block |
||
| 2408 | 2408 | */ |
| 2409 | 2409 | public function samAccountName($message = null, $propertyPath = null) |
| 2410 | 2410 | { |
| 2411 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2411 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2412 | 2412 | { |
| 2413 | 2413 | return $this; |
| 2414 | 2414 | } |
| 2415 | - if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
| 2415 | + if ( ! preg_match('/^([a-z0-9]{4,20})$/', $this->value)) |
|
| 2416 | 2416 | { |
| 2417 | 2417 | $message = $message ?: $this->overrideError; |
| 2418 | 2418 | $message = sprintf( |
@@ -2434,7 +2434,7 @@ discard block |
||
| 2434 | 2434 | */ |
| 2435 | 2435 | public function userPrincipalName($message = null, $propertyPath = null) |
| 2436 | 2436 | { |
| 2437 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2437 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2438 | 2438 | { |
| 2439 | 2439 | return $this; |
| 2440 | 2440 | } |
@@ -2463,11 +2463,11 @@ discard block |
||
| 2463 | 2463 | */ |
| 2464 | 2464 | public function count($count, $message = null, $propertyPath = null) |
| 2465 | 2465 | { |
| 2466 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2466 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2467 | 2467 | { |
| 2468 | 2468 | return $this; |
| 2469 | 2469 | } |
| 2470 | - if ( $count !== count($this->value) ) |
|
| 2470 | + if ($count !== count($this->value)) |
|
| 2471 | 2471 | { |
| 2472 | 2472 | $message = $message ?: $this->overrideError; |
| 2473 | 2473 | $message = sprintf( |
@@ -2475,7 +2475,7 @@ discard block |
||
| 2475 | 2475 | $this->stringify($this->value), |
| 2476 | 2476 | $this->stringify($count) |
| 2477 | 2477 | ); |
| 2478 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $propertyPath, ['count' => $count]); |
|
| 2478 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $propertyPath, [ 'count' => $count ]); |
|
| 2479 | 2479 | } |
| 2480 | 2480 | return $this; |
| 2481 | 2481 | } |
@@ -2488,24 +2488,24 @@ discard block |
||
| 2488 | 2488 | */ |
| 2489 | 2489 | protected function doAllOrNullOr($func, $args) |
| 2490 | 2490 | { |
| 2491 | - if ( $this->nullOr && is_null($this->value) ) |
|
| 2491 | + if ($this->nullOr && is_null($this->value)) |
|
| 2492 | 2492 | { |
| 2493 | 2493 | return true; |
| 2494 | 2494 | } |
| 2495 | - if ( $this->emptyOr && empty($this->value) ) |
|
| 2495 | + if ($this->emptyOr && empty($this->value)) |
|
| 2496 | 2496 | { |
| 2497 | 2497 | return true; |
| 2498 | 2498 | } |
| 2499 | - if ( $this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable() ) |
|
| 2499 | + if ($this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable()) |
|
| 2500 | 2500 | { |
| 2501 | - foreach ( $this->value as $idx => $value ) |
|
| 2501 | + foreach ($this->value as $idx => $value) |
|
| 2502 | 2502 | { |
| 2503 | 2503 | $object = (new Assert($value))->setExceptionClass($this->exceptionClass); |
| 2504 | - call_user_func_array([$object, $func], $args); |
|
| 2504 | + call_user_func_array([ $object, $func ], $args); |
|
| 2505 | 2505 | } |
| 2506 | 2506 | return true; |
| 2507 | 2507 | } |
| 2508 | - return ( $this->nullOr && is_null($this->value) ) || ( $this->emptyOr && empty($this->value) ) ? true : false; |
|
| 2508 | + return ($this->nullOr && is_null($this->value)) || ($this->emptyOr && empty($this->value)) ? true : false; |
|
| 2509 | 2509 | } |
| 2510 | 2510 | |
| 2511 | 2511 | /** |
@@ -2518,12 +2518,12 @@ discard block |
||
| 2518 | 2518 | */ |
| 2519 | 2519 | public function choicesNotEmpty(array $choices, $message = null, $propertyPath = null) |
| 2520 | 2520 | { |
| 2521 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2521 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2522 | 2522 | { |
| 2523 | 2523 | return $this; |
| 2524 | 2524 | } |
| 2525 | 2525 | $this->notEmpty($message, $propertyPath); |
| 2526 | - foreach ( $choices as $choice ) |
|
| 2526 | + foreach ($choices as $choice) |
|
| 2527 | 2527 | { |
| 2528 | 2528 | $this->notEmptyKey($choice, $message, $propertyPath); |
| 2529 | 2529 | } |
@@ -2541,12 +2541,12 @@ discard block |
||
| 2541 | 2541 | */ |
| 2542 | 2542 | public function methodExists($object, $message = null, $propertyPath = null) |
| 2543 | 2543 | { |
| 2544 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2544 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2545 | 2545 | { |
| 2546 | 2546 | return $this; |
| 2547 | 2547 | } |
| 2548 | 2548 | (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $propertyPath); |
| 2549 | - if ( !method_exists($object, $this->value) ) |
|
| 2549 | + if ( ! method_exists($object, $this->value)) |
|
| 2550 | 2550 | { |
| 2551 | 2551 | $message = $message ?: $this->overrideError; |
| 2552 | 2552 | $message = sprintf( |
@@ -2568,11 +2568,11 @@ discard block |
||
| 2568 | 2568 | */ |
| 2569 | 2569 | public function isObject($message = null, $propertyPath = null) |
| 2570 | 2570 | { |
| 2571 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2571 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2572 | 2572 | { |
| 2573 | 2573 | return $this; |
| 2574 | 2574 | } |
| 2575 | - if ( !is_object($this->value) ) |
|
| 2575 | + if ( ! is_object($this->value)) |
|
| 2576 | 2576 | { |
| 2577 | 2577 | $message = $message ?: $this->overrideError; |
| 2578 | 2578 | $message = sprintf( |
@@ -2592,32 +2592,32 @@ discard block |
||
| 2592 | 2592 | */ |
| 2593 | 2593 | private function stringify($value) |
| 2594 | 2594 | { |
| 2595 | - if ( is_bool($value) ) |
|
| 2595 | + if (is_bool($value)) |
|
| 2596 | 2596 | { |
| 2597 | 2597 | return $value ? '<TRUE>' : '<FALSE>'; |
| 2598 | 2598 | } |
| 2599 | - if ( is_scalar($value) ) |
|
| 2599 | + if (is_scalar($value)) |
|
| 2600 | 2600 | { |
| 2601 | 2601 | $val = (string)$value; |
| 2602 | - if ( strlen($val) > 100 ) |
|
| 2602 | + if (strlen($val) > 100) |
|
| 2603 | 2603 | { |
| 2604 | - $val = substr($val, 0, 97) . '...'; |
|
| 2604 | + $val = substr($val, 0, 97).'...'; |
|
| 2605 | 2605 | } |
| 2606 | 2606 | return $val; |
| 2607 | 2607 | } |
| 2608 | - if ( is_array($value) ) |
|
| 2608 | + if (is_array($value)) |
|
| 2609 | 2609 | { |
| 2610 | 2610 | return '<ARRAY>'; |
| 2611 | 2611 | } |
| 2612 | - if ( is_object($value) ) |
|
| 2612 | + if (is_object($value)) |
|
| 2613 | 2613 | { |
| 2614 | 2614 | return get_class($value); |
| 2615 | 2615 | } |
| 2616 | - if ( is_resource($value) ) |
|
| 2616 | + if (is_resource($value)) |
|
| 2617 | 2617 | { |
| 2618 | 2618 | return '<RESOURCE>'; |
| 2619 | 2619 | } |
| 2620 | - if ( $value === null ) |
|
| 2620 | + if ($value === null) |
|
| 2621 | 2621 | { |
| 2622 | 2622 | return '<NULL>'; |
| 2623 | 2623 | } |