@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | /** |
| 547 | 547 | * Assert that value is not equal to a provided value (using == ). |
| 548 | 548 | * |
| 549 | - * @param mixed $value2 |
|
| 549 | + * @param string $value2 |
|
| 550 | 550 | * @param string $message |
| 551 | 551 | * @param string $fieldName |
| 552 | 552 | * @return Assert |
@@ -1448,7 +1448,7 @@ discard block |
||
| 1448 | 1448 | /** |
| 1449 | 1449 | * Alias of {@see choice()} |
| 1450 | 1450 | * |
| 1451 | - * @param array $choices |
|
| 1451 | + * @param integer[] $choices |
|
| 1452 | 1452 | * @param string $message |
| 1453 | 1453 | * @param string $fieldName |
| 1454 | 1454 | * @return Assert |
@@ -1625,7 +1625,7 @@ discard block |
||
| 1625 | 1625 | /** |
| 1626 | 1626 | * Assert that key exists in the values array. |
| 1627 | 1627 | * |
| 1628 | - * @param string|integer $key |
|
| 1628 | + * @param string $key |
|
| 1629 | 1629 | * @param string $message |
| 1630 | 1630 | * @param string $fieldName |
| 1631 | 1631 | * @return Assert |
@@ -2743,7 +2743,6 @@ discard block |
||
| 2743 | 2743 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
| 2744 | 2744 | * |
| 2745 | 2745 | * @param string|null $message |
| 2746 | - * @param string|null $propertyPath |
|
| 2747 | 2746 | * @return Assert |
| 2748 | 2747 | * @throws AssertionFailedException |
| 2749 | 2748 | */ |
@@ -2798,7 +2797,7 @@ discard block |
||
| 2798 | 2797 | } |
| 2799 | 2798 | |
| 2800 | 2799 | /** |
| 2801 | - * @param $func |
|
| 2800 | + * @param string $func |
|
| 2802 | 2801 | * @param $args |
| 2803 | 2802 | * @return bool |
| 2804 | 2803 | * @throws AssertionFailedException |
@@ -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 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * |
| 137 | 137 | * @var string |
| 138 | 138 | */ |
| 139 | - protected $exceptionClass = AssertionFailedException::class; |
|
| 139 | + protected $exceptionClass = AssertionFailedException::class; |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * @param mixed $value |
@@ -152,16 +152,16 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public static function runValidators(array $validators) : array |
| 154 | 154 | { |
| 155 | - $errors = []; |
|
| 156 | - foreach ( $validators as $fieldName => $validator ) |
|
| 155 | + $errors = [ ]; |
|
| 156 | + foreach ($validators as $fieldName => $validator) |
|
| 157 | 157 | { |
| 158 | 158 | try |
| 159 | 159 | { |
| 160 | 160 | $validator->__invoke(); |
| 161 | 161 | } |
| 162 | - catch ( AssertionFailedException $e ) |
|
| 162 | + catch (AssertionFailedException $e) |
|
| 163 | 163 | { |
| 164 | - $errors[$fieldName] = $e->getMessage(); |
|
| 164 | + $errors[ $fieldName ] = $e->getMessage(); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
@@ -176,22 +176,22 @@ discard block |
||
| 176 | 176 | * @param string $level |
| 177 | 177 | * @return Assert |
| 178 | 178 | */ |
| 179 | - public static function that($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) : Assert |
|
| 179 | + public static function that($value, string $fieldName = '', int $code = 0, string $error = '', string $level = Assert::WARNING) : Assert |
|
| 180 | 180 | { |
| 181 | 181 | $assert = new static($value); |
| 182 | - if ( $fieldName ) |
|
| 182 | + if ($fieldName) |
|
| 183 | 183 | { |
| 184 | 184 | $assert->fieldName($fieldName); |
| 185 | 185 | } |
| 186 | - if ( $code ) |
|
| 186 | + if ($code) |
|
| 187 | 187 | { |
| 188 | 188 | $assert->code($code); |
| 189 | 189 | } |
| 190 | - if ( $error ) |
|
| 190 | + if ($error) |
|
| 191 | 191 | { |
| 192 | 192 | $assert->error($error); |
| 193 | 193 | } |
| 194 | - if ( $level ) |
|
| 194 | + if ($level) |
|
| 195 | 195 | { |
| 196 | 196 | $assert->level($level); |
| 197 | 197 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @param string $level |
| 271 | 271 | * @return AssertionFailedException |
| 272 | 272 | */ |
| 273 | - protected function createException(string $message, int $code, string $fieldName, array $constraints=[], string $level='') : AssertionFailedException |
|
| 273 | + protected function createException(string $message, int $code, string $fieldName, array $constraints = [ ], string $level = '') : AssertionFailedException |
|
| 274 | 274 | { |
| 275 | 275 | $exceptionClass = $this->exceptionClass; |
| 276 | 276 | $fieldName = empty($fieldName) ? $this->fieldName : $fieldName; |
@@ -372,13 +372,13 @@ discard block |
||
| 372 | 372 | * @return Assert |
| 373 | 373 | * @throws AssertionFailedException |
| 374 | 374 | */ |
| 375 | - public function eq($value2, string $message='', string $fieldName='') : Assert |
|
| 375 | + public function eq($value2, string $message = '', string $fieldName = '') : Assert |
|
| 376 | 376 | { |
| 377 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 377 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 378 | 378 | { |
| 379 | 379 | return $this; |
| 380 | 380 | } |
| 381 | - if ( $this->value != $value2 ) |
|
| 381 | + if ($this->value != $value2) |
|
| 382 | 382 | { |
| 383 | 383 | $message = $message ?: $this->overrideError; |
| 384 | 384 | $message = sprintf( |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | $this->stringify($value2) |
| 388 | 388 | ); |
| 389 | 389 | |
| 390 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
| 390 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | return $this; |
@@ -402,13 +402,13 @@ discard block |
||
| 402 | 402 | * @return Assert |
| 403 | 403 | * @throws AssertionFailedException |
| 404 | 404 | */ |
| 405 | - public function greaterThan($value2, string $message='', string $fieldName='') : Assert |
|
| 405 | + public function greaterThan($value2, string $message = '', string $fieldName = '') : Assert |
|
| 406 | 406 | { |
| 407 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 407 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 408 | 408 | { |
| 409 | 409 | return $this; |
| 410 | 410 | } |
| 411 | - if ( ! ( $this->value > $value2 ) ) |
|
| 411 | + if ( ! ($this->value > $value2)) |
|
| 412 | 412 | { |
| 413 | 413 | $message = $message ?: $this->overrideError; |
| 414 | 414 | $message = sprintf( |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $this->stringify($value2) |
| 418 | 418 | ); |
| 419 | 419 | |
| 420 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
| 420 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | return $this; |
@@ -432,13 +432,13 @@ discard block |
||
| 432 | 432 | * @return Assert |
| 433 | 433 | * @throws AssertionFailedException |
| 434 | 434 | */ |
| 435 | - public function greaterThanOrEq($value2, string $message='', string $fieldName='') : Assert |
|
| 435 | + public function greaterThanOrEq($value2, string $message = '', string $fieldName = '') : Assert |
|
| 436 | 436 | { |
| 437 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 437 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 438 | 438 | { |
| 439 | 439 | return $this; |
| 440 | 440 | } |
| 441 | - if ( ! ( $this->value >= $value2 ) ) |
|
| 441 | + if ( ! ($this->value >= $value2)) |
|
| 442 | 442 | { |
| 443 | 443 | $message = $message ?: $this->overrideError; |
| 444 | 444 | $message = sprintf( |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | $this->stringify($value2) |
| 448 | 448 | ); |
| 449 | 449 | |
| 450 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, ['expected' => $value2]); |
|
| 450 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | return $this; |
@@ -462,13 +462,13 @@ discard block |
||
| 462 | 462 | * @return Assert |
| 463 | 463 | * @throws AssertionFailedException |
| 464 | 464 | */ |
| 465 | - public function lessThan($value2, string $message='', string $fieldName='') : Assert |
|
| 465 | + public function lessThan($value2, string $message = '', string $fieldName = '') : Assert |
|
| 466 | 466 | { |
| 467 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 467 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 468 | 468 | { |
| 469 | 469 | return $this; |
| 470 | 470 | } |
| 471 | - if ( ! ( $this->value < $value2 ) ) |
|
| 471 | + if ( ! ($this->value < $value2)) |
|
| 472 | 472 | { |
| 473 | 473 | $message = $message ?: $this->overrideError; |
| 474 | 474 | $message = sprintf( |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | $this->stringify($value2) |
| 478 | 478 | ); |
| 479 | 479 | |
| 480 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $fieldName, ['expected' => $value2]); |
|
| 480 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN, $fieldName, [ 'expected' => $value2 ]); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | return $this; |
@@ -492,13 +492,13 @@ discard block |
||
| 492 | 492 | * @return Assert |
| 493 | 493 | * @throws AssertionFailedException |
| 494 | 494 | */ |
| 495 | - public function lessThanOrEq($value2, string $message='', string $fieldName='') : Assert |
|
| 495 | + public function lessThanOrEq($value2, string $message = '', string $fieldName = '') : Assert |
|
| 496 | 496 | { |
| 497 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 497 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 498 | 498 | { |
| 499 | 499 | return $this; |
| 500 | 500 | } |
| 501 | - if ( ! ( $this->value <= $value2 ) ) |
|
| 501 | + if ( ! ($this->value <= $value2)) |
|
| 502 | 502 | { |
| 503 | 503 | $message = $message ?: $this->overrideError; |
| 504 | 504 | $message = sprintf( |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | $this->stringify($value2) |
| 508 | 508 | ); |
| 509 | 509 | |
| 510 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $fieldName, ['expected' => $value2]); |
|
| 510 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_LESS_THAN_OR_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | return $this; |
@@ -522,13 +522,13 @@ discard block |
||
| 522 | 522 | * @return Assert |
| 523 | 523 | * @throws AssertionFailedException |
| 524 | 524 | */ |
| 525 | - public function same($value2, string $message='', string $fieldName='') : Assert |
|
| 525 | + public function same($value2, string $message = '', string $fieldName = '') : Assert |
|
| 526 | 526 | { |
| 527 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 527 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 528 | 528 | { |
| 529 | 529 | return $this; |
| 530 | 530 | } |
| 531 | - if ( $this->value !== $value2 ) |
|
| 531 | + if ($this->value !== $value2) |
|
| 532 | 532 | { |
| 533 | 533 | $message = $message ?: $this->overrideError; |
| 534 | 534 | $message = sprintf( |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | $this->stringify($value2) |
| 538 | 538 | ); |
| 539 | 539 | |
| 540 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $fieldName, ['expected' => $value2]); |
|
| 540 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SAME, $fieldName, [ 'expected' => $value2 ]); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | return $this; |
@@ -552,13 +552,13 @@ discard block |
||
| 552 | 552 | * @return Assert |
| 553 | 553 | * @throws AssertionFailedException |
| 554 | 554 | */ |
| 555 | - public function notEq($value2, string $message='', string $fieldName='') : Assert |
|
| 555 | + public function notEq($value2, string $message = '', string $fieldName = '') : Assert |
|
| 556 | 556 | { |
| 557 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 557 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 558 | 558 | { |
| 559 | 559 | return $this; |
| 560 | 560 | } |
| 561 | - if ( $this->value == $value2 ) |
|
| 561 | + if ($this->value == $value2) |
|
| 562 | 562 | { |
| 563 | 563 | $message = $message ?: $this->overrideError; |
| 564 | 564 | $message = sprintf( |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | $this->stringify($value2) |
| 568 | 568 | ); |
| 569 | 569 | |
| 570 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $fieldName, ['expected' => $value2]); |
|
| 570 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_EQ, $fieldName, [ 'expected' => $value2 ]); |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | return $this; |
@@ -581,13 +581,13 @@ discard block |
||
| 581 | 581 | * @return Assert |
| 582 | 582 | * @throws AssertionFailedException |
| 583 | 583 | */ |
| 584 | - public function isCallable(string $message='', string $fieldName='') : Assert |
|
| 584 | + public function isCallable(string $message = '', string $fieldName = '') : Assert |
|
| 585 | 585 | { |
| 586 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 586 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 587 | 587 | { |
| 588 | 588 | return $this; |
| 589 | 589 | } |
| 590 | - if ( !is_callable($this->value) ) |
|
| 590 | + if ( ! is_callable($this->value)) |
|
| 591 | 591 | { |
| 592 | 592 | $message = $message ?: $this->overrideError; |
| 593 | 593 | $message = sprintf( |
@@ -610,13 +610,13 @@ discard block |
||
| 610 | 610 | * @return Assert |
| 611 | 611 | * @throws AssertionFailedException |
| 612 | 612 | */ |
| 613 | - public function notSame($value2, string $message='', string $fieldName='') : Assert |
|
| 613 | + public function notSame($value2, string $message = '', string $fieldName = '') : Assert |
|
| 614 | 614 | { |
| 615 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 615 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 616 | 616 | { |
| 617 | 617 | return $this; |
| 618 | 618 | } |
| 619 | - if ( $this->value === $value2 ) |
|
| 619 | + if ($this->value === $value2) |
|
| 620 | 620 | { |
| 621 | 621 | $message = $message ?: $this->overrideError; |
| 622 | 622 | $message = sprintf( |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | $this->stringify($value2) |
| 626 | 626 | ); |
| 627 | 627 | |
| 628 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $fieldName, ['expected' => $value2]); |
|
| 628 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_SAME, $fieldName, [ 'expected' => $value2 ]); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | return $this; |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | * @return Assert |
| 640 | 640 | * @throws AssertionFailedException |
| 641 | 641 | */ |
| 642 | - public function id(string $message='', string $fieldName='') : Assert |
|
| 642 | + public function id(string $message = '', string $fieldName = '') : Assert |
|
| 643 | 643 | { |
| 644 | 644 | $message = $message ?: $this->overrideError; |
| 645 | 645 | $message = $message ?: 'Value "%s" is not an integer id.'; |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * @return Assert |
| 655 | 655 | * @throws AssertionFailedException |
| 656 | 656 | */ |
| 657 | - public function unsignedInt(string $message='', string $fieldName='') : Assert |
|
| 657 | + public function unsignedInt(string $message = '', string $fieldName = '') : Assert |
|
| 658 | 658 | { |
| 659 | 659 | $message = $message ?: $this->overrideError; |
| 660 | 660 | $message = $message ?: 'Value "%s" is not an integer id.'; |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | * @return Assert |
| 671 | 671 | * @throws AssertionFailedException |
| 672 | 672 | */ |
| 673 | - public function flag(string $message='', string $fieldName='') : Assert |
|
| 673 | + public function flag(string $message = '', string $fieldName = '') : Assert |
|
| 674 | 674 | { |
| 675 | 675 | $message = $message ?: $this->overrideError; |
| 676 | 676 | $message = $message ?: 'Value "%s" is not a 0 or 1.'; |
@@ -686,12 +686,12 @@ discard block |
||
| 686 | 686 | * @return Assert |
| 687 | 687 | * @throws AssertionFailedException |
| 688 | 688 | */ |
| 689 | - public function status(string $message='', string $fieldName='') : Assert |
|
| 689 | + public function status(string $message = '', string $fieldName = '') : Assert |
|
| 690 | 690 | { |
| 691 | 691 | $message = $message ?: $this->overrideError; |
| 692 | 692 | $message = $message ?: 'Value "%s" is not a valid status.'; |
| 693 | 693 | |
| 694 | - return $this->integer($message, $fieldName)->inArray([-1, 0, 1]); |
|
| 694 | + return $this->integer($message, $fieldName)->inArray([-1, 0, 1 ]); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | * @return Assert |
| 703 | 703 | * @throws AssertionFailedException |
| 704 | 704 | */ |
| 705 | - public function nullOrId(string $message='', string $fieldName='') : Assert |
|
| 705 | + public function nullOrId(string $message = '', string $fieldName = '') : Assert |
|
| 706 | 706 | { |
| 707 | 707 | return $this->nullOr()->id($message, $fieldName); |
| 708 | 708 | } |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | * @return Assert |
| 716 | 716 | * @throws AssertionFailedException |
| 717 | 717 | */ |
| 718 | - public function allIds(string $message='', string $fieldName='') : Assert |
|
| 718 | + public function allIds(string $message = '', string $fieldName = '') : Assert |
|
| 719 | 719 | { |
| 720 | 720 | return $this->all()->id($message, $fieldName); |
| 721 | 721 | } |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * @return Assert |
| 729 | 729 | * @throws AssertionFailedException |
| 730 | 730 | */ |
| 731 | - public function int(string $message='', string $fieldName='') : Assert |
|
| 731 | + public function int(string $message = '', string $fieldName = '') : Assert |
|
| 732 | 732 | { |
| 733 | 733 | return $this->integer($message, $fieldName); |
| 734 | 734 | } |
@@ -741,13 +741,13 @@ discard block |
||
| 741 | 741 | * @return Assert |
| 742 | 742 | * @throws AssertionFailedException |
| 743 | 743 | */ |
| 744 | - public function integer(string $message='', string $fieldName='') : Assert |
|
| 744 | + public function integer(string $message = '', string $fieldName = '') : Assert |
|
| 745 | 745 | { |
| 746 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 746 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 747 | 747 | { |
| 748 | 748 | return $this; |
| 749 | 749 | } |
| 750 | - if ( !is_int($this->value) ) |
|
| 750 | + if ( ! is_int($this->value)) |
|
| 751 | 751 | { |
| 752 | 752 | $message = $message ?: $this->overrideError; |
| 753 | 753 | $message = sprintf( |
@@ -769,13 +769,13 @@ discard block |
||
| 769 | 769 | * @return Assert |
| 770 | 770 | * @throws AssertionFailedException |
| 771 | 771 | */ |
| 772 | - public function float(string $message='', string $fieldName='') : Assert |
|
| 772 | + public function float(string $message = '', string $fieldName = '') : Assert |
|
| 773 | 773 | { |
| 774 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 774 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 775 | 775 | { |
| 776 | 776 | return $this; |
| 777 | 777 | } |
| 778 | - if ( ! is_float($this->value) ) |
|
| 778 | + if ( ! is_float($this->value)) |
|
| 779 | 779 | { |
| 780 | 780 | $message = $message ?: $this->overrideError; |
| 781 | 781 | $message = sprintf( |
@@ -797,13 +797,13 @@ discard block |
||
| 797 | 797 | * @return Assert |
| 798 | 798 | * @throws AssertionFailedException |
| 799 | 799 | */ |
| 800 | - public function digit(string $message='', string $fieldName='') : Assert |
|
| 800 | + public function digit(string $message = '', string $fieldName = '') : Assert |
|
| 801 | 801 | { |
| 802 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 802 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 803 | 803 | { |
| 804 | 804 | return $this; |
| 805 | 805 | } |
| 806 | - if ( ! ctype_digit((string)$this->value) ) |
|
| 806 | + if ( ! ctype_digit((string)$this->value)) |
|
| 807 | 807 | { |
| 808 | 808 | $message = $message ?: $this->overrideError; |
| 809 | 809 | $message = sprintf( |
@@ -825,14 +825,14 @@ discard block |
||
| 825 | 825 | * @return Assert |
| 826 | 826 | * @throws AssertionFailedException |
| 827 | 827 | */ |
| 828 | - public function date(string $message='', string $fieldName='') : Assert |
|
| 828 | + public function date(string $message = '', string $fieldName = '') : Assert |
|
| 829 | 829 | { |
| 830 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 830 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 831 | 831 | { |
| 832 | 832 | return $this; |
| 833 | 833 | } |
| 834 | 834 | $this->notEmpty($message, $fieldName); |
| 835 | - if ( strtotime($this->value) === false ) |
|
| 835 | + if (strtotime($this->value) === false) |
|
| 836 | 836 | { |
| 837 | 837 | $message = $message ?: $this->overrideError; |
| 838 | 838 | $message = sprintf( |
@@ -853,14 +853,14 @@ discard block |
||
| 853 | 853 | * @return $this |
| 854 | 854 | * @throws AssertionFailedException |
| 855 | 855 | */ |
| 856 | - public function after($afterDate, string $message='', string $fieldName='') |
|
| 856 | + public function after($afterDate, string $message = '', string $fieldName = '') |
|
| 857 | 857 | { |
| 858 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 858 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 859 | 859 | { |
| 860 | 860 | return $this; |
| 861 | 861 | } |
| 862 | 862 | $this->notEmpty($message, $fieldName); |
| 863 | - if ( strtotime($this->value) === false && strtotime($afterDate) === false && strtotime($this->value) < strtotime($afterDate) ) |
|
| 863 | + if (strtotime($this->value) === false && strtotime($afterDate) === false && strtotime($this->value) < strtotime($afterDate)) |
|
| 864 | 864 | { |
| 865 | 865 | $message = $message ?: $this->overrideError; |
| 866 | 866 | $message = sprintf( |
@@ -882,13 +882,13 @@ discard block |
||
| 882 | 882 | * @return Assert |
| 883 | 883 | * @throws AssertionFailedException |
| 884 | 884 | */ |
| 885 | - public function integerish(string $message='', string $fieldName='') : Assert |
|
| 885 | + public function integerish(string $message = '', string $fieldName = '') : Assert |
|
| 886 | 886 | { |
| 887 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 887 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 888 | 888 | { |
| 889 | 889 | return $this; |
| 890 | 890 | } |
| 891 | - if ( is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value) ) |
|
| 891 | + if (is_object($this->value) || strval(intval($this->value)) != $this->value || is_bool($this->value) || is_null($this->value)) |
|
| 892 | 892 | { |
| 893 | 893 | $message = $message ?: $this->overrideError; |
| 894 | 894 | $message = sprintf( |
@@ -910,13 +910,13 @@ discard block |
||
| 910 | 910 | * @return Assert |
| 911 | 911 | * @throws AssertionFailedException |
| 912 | 912 | */ |
| 913 | - public function boolean(string $message='', string $fieldName='') : Assert |
|
| 913 | + public function boolean(string $message = '', string $fieldName = '') : Assert |
|
| 914 | 914 | { |
| 915 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 915 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 916 | 916 | { |
| 917 | 917 | return $this; |
| 918 | 918 | } |
| 919 | - if ( ! is_bool($this->value) ) |
|
| 919 | + if ( ! is_bool($this->value)) |
|
| 920 | 920 | { |
| 921 | 921 | $message = $message ?: $this->overrideError; |
| 922 | 922 | $message = sprintf( |
@@ -938,13 +938,13 @@ discard block |
||
| 938 | 938 | * @return Assert |
| 939 | 939 | * @throws AssertionFailedException |
| 940 | 940 | */ |
| 941 | - public function scalar(string $message='', string $fieldName='') : Assert |
|
| 941 | + public function scalar(string $message = '', string $fieldName = '') : Assert |
|
| 942 | 942 | { |
| 943 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 943 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 944 | 944 | { |
| 945 | 945 | return $this; |
| 946 | 946 | } |
| 947 | - if ( ! is_scalar($this->value) ) |
|
| 947 | + if ( ! is_scalar($this->value)) |
|
| 948 | 948 | { |
| 949 | 949 | $message = $message ?: $this->overrideError; |
| 950 | 950 | $message = sprintf( |
@@ -966,13 +966,13 @@ discard block |
||
| 966 | 966 | * @return Assert |
| 967 | 967 | * @throws AssertionFailedException |
| 968 | 968 | */ |
| 969 | - public function notEmpty(string $message='', string $fieldName='') : Assert |
|
| 969 | + public function notEmpty(string $message = '', string $fieldName = '') : Assert |
|
| 970 | 970 | { |
| 971 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 971 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 972 | 972 | { |
| 973 | 973 | return $this; |
| 974 | 974 | } |
| 975 | - if ( ( is_object($this->value) && empty((array)$this->value) ) || empty($this->value) ) |
|
| 975 | + if ((is_object($this->value) && empty((array)$this->value)) || empty($this->value)) |
|
| 976 | 976 | { |
| 977 | 977 | $message = $message ?: $this->overrideError; |
| 978 | 978 | $message = sprintf( |
@@ -994,13 +994,13 @@ discard block |
||
| 994 | 994 | * @return Assert |
| 995 | 995 | * @throws AssertionFailedException |
| 996 | 996 | */ |
| 997 | - public function noContent(string $message='', string $fieldName='') : Assert |
|
| 997 | + public function noContent(string $message = '', string $fieldName = '') : Assert |
|
| 998 | 998 | { |
| 999 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 999 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1000 | 1000 | { |
| 1001 | 1001 | return $this; |
| 1002 | 1002 | } |
| 1003 | - if ( !empty( $this->value ) ) |
|
| 1003 | + if ( ! empty($this->value)) |
|
| 1004 | 1004 | { |
| 1005 | 1005 | $message = $message ?: $this->overrideError; |
| 1006 | 1006 | $message = sprintf( |
@@ -1022,13 +1022,13 @@ discard block |
||
| 1022 | 1022 | * @return Assert |
| 1023 | 1023 | * @throws AssertionFailedException |
| 1024 | 1024 | */ |
| 1025 | - public function notNull(string $message='', string $fieldName='') : Assert |
|
| 1025 | + public function notNull(string $message = '', string $fieldName = '') : Assert |
|
| 1026 | 1026 | { |
| 1027 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1027 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1028 | 1028 | { |
| 1029 | 1029 | return $this; |
| 1030 | 1030 | } |
| 1031 | - if ( $this->value === null ) |
|
| 1031 | + if ($this->value === null) |
|
| 1032 | 1032 | { |
| 1033 | 1033 | $message = $message ?: $this->overrideError; |
| 1034 | 1034 | $message = sprintf( |
@@ -1050,13 +1050,13 @@ discard block |
||
| 1050 | 1050 | * @return Assert |
| 1051 | 1051 | * @throws AssertionFailedException |
| 1052 | 1052 | */ |
| 1053 | - public function string(string $message='', string $fieldName='') : Assert |
|
| 1053 | + public function string(string $message = '', string $fieldName = '') : Assert |
|
| 1054 | 1054 | { |
| 1055 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1055 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1056 | 1056 | { |
| 1057 | 1057 | return $this; |
| 1058 | 1058 | } |
| 1059 | - if ( !is_string($this->value) ) |
|
| 1059 | + if ( ! is_string($this->value)) |
|
| 1060 | 1060 | { |
| 1061 | 1061 | $message = $message ?: $this->overrideError; |
| 1062 | 1062 | $message = sprintf( |
@@ -1080,14 +1080,14 @@ discard block |
||
| 1080 | 1080 | * @return Assert |
| 1081 | 1081 | * @throws AssertionFailedException |
| 1082 | 1082 | */ |
| 1083 | - public function regex(string $pattern, string $message='', string $fieldName='') : Assert |
|
| 1083 | + public function regex(string $pattern, string $message = '', string $fieldName = '') : Assert |
|
| 1084 | 1084 | { |
| 1085 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1085 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1086 | 1086 | { |
| 1087 | 1087 | return $this; |
| 1088 | 1088 | } |
| 1089 | 1089 | $this->string($message, $fieldName); |
| 1090 | - if ( ! preg_match($pattern, $this->value) ) |
|
| 1090 | + if ( ! preg_match($pattern, $this->value)) |
|
| 1091 | 1091 | { |
| 1092 | 1092 | $message = $message ?: $this->overrideError; |
| 1093 | 1093 | $message = sprintf( |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | $this->stringify($this->value) |
| 1096 | 1096 | ); |
| 1097 | 1097 | |
| 1098 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, ['pattern' => $pattern]); |
|
| 1098 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, [ 'pattern' => $pattern ]); |
|
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | return $this; |
@@ -1109,15 +1109,15 @@ discard block |
||
| 1109 | 1109 | * @return Assert |
| 1110 | 1110 | * @throws AssertionFailedException |
| 1111 | 1111 | */ |
| 1112 | - public function ipAddress(string $message='', string $fieldName='') : Assert |
|
| 1112 | + public function ipAddress(string $message = '', string $fieldName = '') : Assert |
|
| 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, $fieldName); |
| 1119 | - $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])$/'; |
|
| 1120 | - if ( ! preg_match($pattern, $this->value) ) |
|
| 1119 | + $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])$/'; |
|
| 1120 | + if ( ! preg_match($pattern, $this->value)) |
|
| 1121 | 1121 | { |
| 1122 | 1122 | $message = $message ?: $this->overrideError; |
| 1123 | 1123 | $message = sprintf( |
@@ -1140,14 +1140,14 @@ discard block |
||
| 1140 | 1140 | * @return Assert |
| 1141 | 1141 | * @throws AssertionFailedException |
| 1142 | 1142 | */ |
| 1143 | - public function notRegex(string $pattern, string $message='', string $fieldName='') : Assert |
|
| 1143 | + public function notRegex(string $pattern, string $message = '', string $fieldName = '') : Assert |
|
| 1144 | 1144 | { |
| 1145 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1145 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1146 | 1146 | { |
| 1147 | 1147 | return $this; |
| 1148 | 1148 | } |
| 1149 | 1149 | $this->string($message, $fieldName); |
| 1150 | - if ( preg_match($pattern, $this->value) ) |
|
| 1150 | + if (preg_match($pattern, $this->value)) |
|
| 1151 | 1151 | { |
| 1152 | 1152 | $message = $message ?: $this->overrideError; |
| 1153 | 1153 | $message = sprintf( |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | $this->stringify($this->value) |
| 1156 | 1156 | ); |
| 1157 | 1157 | |
| 1158 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, ['pattern' => $pattern]); |
|
| 1158 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_REGEX, $fieldName, [ 'pattern' => $pattern ]); |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | return $this; |
@@ -1171,14 +1171,14 @@ discard block |
||
| 1171 | 1171 | * @return Assert |
| 1172 | 1172 | * @throws AssertionFailedException |
| 1173 | 1173 | */ |
| 1174 | - public function length(int $length, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1174 | + public function length(int $length, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 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 | 1180 | $this->string($message, $fieldName); |
| 1181 | - if ( mb_strlen($this->value, $encoding) !== $length ) |
|
| 1181 | + if (mb_strlen($this->value, $encoding) !== $length) |
|
| 1182 | 1182 | { |
| 1183 | 1183 | $message = $message ?: $this->overrideError; |
| 1184 | 1184 | $message = sprintf( |
@@ -1187,7 +1187,7 @@ discard block |
||
| 1187 | 1187 | $length, |
| 1188 | 1188 | mb_strlen($this->value, $encoding) |
| 1189 | 1189 | ); |
| 1190 | - $constraints = ['length' => $length, 'encoding' => $encoding]; |
|
| 1190 | + $constraints = [ 'length' => $length, 'encoding' => $encoding ]; |
|
| 1191 | 1191 | |
| 1192 | 1192 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_LENGTH, $fieldName, $constraints); |
| 1193 | 1193 | } |
@@ -1206,24 +1206,24 @@ discard block |
||
| 1206 | 1206 | * @return Assert |
| 1207 | 1207 | * @throws AssertionFailedException |
| 1208 | 1208 | */ |
| 1209 | - public function minLength(int $minLength, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1209 | + public function minLength(int $minLength, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1210 | 1210 | { |
| 1211 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1211 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1212 | 1212 | { |
| 1213 | 1213 | return $this; |
| 1214 | 1214 | } |
| 1215 | 1215 | $this->string($message, $fieldName); |
| 1216 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
| 1216 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
| 1217 | 1217 | { |
| 1218 | 1218 | $message = $message ?: $this->overrideError; |
| 1219 | - $message = sprintf( |
|
| 1219 | + $message = sprintf( |
|
| 1220 | 1220 | $message |
| 1221 | 1221 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
| 1222 | 1222 | $this->stringify($this->value), |
| 1223 | 1223 | $minLength, |
| 1224 | 1224 | mb_strlen($this->value, $encoding) |
| 1225 | 1225 | ); |
| 1226 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
| 1226 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
| 1227 | 1227 | |
| 1228 | 1228 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $fieldName, $constraints); |
| 1229 | 1229 | } |
@@ -1242,23 +1242,23 @@ discard block |
||
| 1242 | 1242 | * @return Assert |
| 1243 | 1243 | * @throws AssertionFailedException |
| 1244 | 1244 | */ |
| 1245 | - public function maxLength(int $maxLength, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1245 | + public function maxLength(int $maxLength, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1246 | 1246 | { |
| 1247 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1247 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1248 | 1248 | { |
| 1249 | 1249 | return $this; |
| 1250 | 1250 | } |
| 1251 | 1251 | $this->string($message, $fieldName); |
| 1252 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
| 1252 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
| 1253 | 1253 | { |
| 1254 | 1254 | $message = $message ?: $this->overrideError; |
| 1255 | - $message = sprintf( |
|
| 1255 | + $message = sprintf( |
|
| 1256 | 1256 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
| 1257 | 1257 | $this->stringify($this->value), |
| 1258 | 1258 | $maxLength, |
| 1259 | 1259 | mb_strlen($this->value, $encoding) |
| 1260 | 1260 | ); |
| 1261 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
| 1261 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
| 1262 | 1262 | |
| 1263 | 1263 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $fieldName, $constraints); |
| 1264 | 1264 | } |
@@ -1277,37 +1277,37 @@ discard block |
||
| 1277 | 1277 | * @return Assert |
| 1278 | 1278 | * @throws AssertionFailedException |
| 1279 | 1279 | */ |
| 1280 | - public function betweenLength(int $minLength, int $maxLength, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1280 | + public function betweenLength(int $minLength, int $maxLength, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1281 | 1281 | { |
| 1282 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1282 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1283 | 1283 | { |
| 1284 | 1284 | return $this; |
| 1285 | 1285 | } |
| 1286 | 1286 | $this->string($message, $fieldName); |
| 1287 | - if ( mb_strlen($this->value, $encoding) < $minLength ) |
|
| 1287 | + if (mb_strlen($this->value, $encoding) < $minLength) |
|
| 1288 | 1288 | { |
| 1289 | 1289 | $message = $message ?: $this->overrideError; |
| 1290 | - $message = sprintf( |
|
| 1290 | + $message = sprintf( |
|
| 1291 | 1291 | $message |
| 1292 | 1292 | ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', |
| 1293 | 1293 | $this->stringify($this->value), |
| 1294 | 1294 | $minLength, |
| 1295 | 1295 | mb_strlen($this->value, $encoding) |
| 1296 | 1296 | ); |
| 1297 | - $constraints = ['min_length' => $minLength, 'encoding' => $encoding]; |
|
| 1297 | + $constraints = [ 'min_length' => $minLength, 'encoding' => $encoding ]; |
|
| 1298 | 1298 | |
| 1299 | 1299 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN_LENGTH, $fieldName, $constraints); |
| 1300 | 1300 | } |
| 1301 | - if ( mb_strlen($this->value, $encoding) > $maxLength ) |
|
| 1301 | + if (mb_strlen($this->value, $encoding) > $maxLength) |
|
| 1302 | 1302 | { |
| 1303 | 1303 | $message = $message ?: $this->overrideError; |
| 1304 | - $message = sprintf( |
|
| 1304 | + $message = sprintf( |
|
| 1305 | 1305 | $message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', |
| 1306 | 1306 | $this->stringify($this->value), |
| 1307 | 1307 | $maxLength, |
| 1308 | 1308 | mb_strlen($this->value, $encoding) |
| 1309 | 1309 | ); |
| 1310 | - $constraints = ['max_length' => $maxLength, 'encoding' => $encoding]; |
|
| 1310 | + $constraints = [ 'max_length' => $maxLength, 'encoding' => $encoding ]; |
|
| 1311 | 1311 | |
| 1312 | 1312 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX_LENGTH, $fieldName, $constraints); |
| 1313 | 1313 | } |
@@ -1325,22 +1325,22 @@ discard block |
||
| 1325 | 1325 | * @return Assert |
| 1326 | 1326 | * @throws AssertionFailedException |
| 1327 | 1327 | */ |
| 1328 | - public function startsWith(string $needle, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1328 | + public function startsWith(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1329 | 1329 | { |
| 1330 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1330 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1331 | 1331 | { |
| 1332 | 1332 | return $this; |
| 1333 | 1333 | } |
| 1334 | 1334 | $this->string($message, $fieldName); |
| 1335 | - if ( mb_strpos($this->value, $needle, 0, $encoding) !== 0 ) |
|
| 1335 | + if (mb_strpos($this->value, $needle, 0, $encoding) !== 0) |
|
| 1336 | 1336 | { |
| 1337 | 1337 | $message = $message ?: $this->overrideError; |
| 1338 | - $message = sprintf( |
|
| 1338 | + $message = sprintf( |
|
| 1339 | 1339 | $message ?: 'Value "%s" does not start with "%s".', |
| 1340 | 1340 | $this->stringify($this->value), |
| 1341 | 1341 | $this->stringify($needle) |
| 1342 | 1342 | ); |
| 1343 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
| 1343 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
| 1344 | 1344 | |
| 1345 | 1345 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $fieldName, $constraints); |
| 1346 | 1346 | } |
@@ -1358,23 +1358,23 @@ discard block |
||
| 1358 | 1358 | * @return Assert |
| 1359 | 1359 | * @throws AssertionFailedException |
| 1360 | 1360 | */ |
| 1361 | - public function endsWith(string $needle, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1361 | + public function endsWith(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1362 | 1362 | { |
| 1363 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1363 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1364 | 1364 | { |
| 1365 | 1365 | return $this; |
| 1366 | 1366 | } |
| 1367 | 1367 | $this->string($message, $fieldName); |
| 1368 | 1368 | $stringPosition = mb_strlen($this->value, $encoding) - mb_strlen($needle, $encoding); |
| 1369 | - if ( mb_strripos($this->value, $needle, 0 , $encoding) !== $stringPosition ) |
|
| 1369 | + if (mb_strripos($this->value, $needle, 0, $encoding) !== $stringPosition) |
|
| 1370 | 1370 | { |
| 1371 | 1371 | $message = $message ?: $this->overrideError; |
| 1372 | - $message = sprintf( |
|
| 1372 | + $message = sprintf( |
|
| 1373 | 1373 | $message ?: 'Value "%s" does not end with "%s".', |
| 1374 | 1374 | $this->stringify($this->value), |
| 1375 | 1375 | $this->stringify($needle) |
| 1376 | 1376 | ); |
| 1377 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
| 1377 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
| 1378 | 1378 | |
| 1379 | 1379 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_END, $fieldName, $constraints); |
| 1380 | 1380 | } |
@@ -1392,22 +1392,22 @@ discard block |
||
| 1392 | 1392 | * @return Assert |
| 1393 | 1393 | * @throws AssertionFailedException |
| 1394 | 1394 | */ |
| 1395 | - public function contains(string $needle, string $message='', string $fieldName='', string $encoding='utf8') : Assert |
|
| 1395 | + public function contains(string $needle, string $message = '', string $fieldName = '', string $encoding = 'utf8') : Assert |
|
| 1396 | 1396 | { |
| 1397 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1397 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1398 | 1398 | { |
| 1399 | 1399 | return $this; |
| 1400 | 1400 | } |
| 1401 | 1401 | $this->string($message, $fieldName); |
| 1402 | - if ( mb_strpos($this->value, $needle, 0, $encoding) === false ) |
|
| 1402 | + if (mb_strpos($this->value, $needle, 0, $encoding) === false) |
|
| 1403 | 1403 | { |
| 1404 | 1404 | $message = $message ?: $this->overrideError; |
| 1405 | - $message = sprintf( |
|
| 1405 | + $message = sprintf( |
|
| 1406 | 1406 | $message ?: 'Value "%s" does not contain "%s".', |
| 1407 | 1407 | $this->stringify($this->value), |
| 1408 | 1408 | $this->stringify($needle) |
| 1409 | 1409 | ); |
| 1410 | - $constraints = ['needle' => $needle, 'encoding' => $encoding]; |
|
| 1410 | + $constraints = [ 'needle' => $needle, 'encoding' => $encoding ]; |
|
| 1411 | 1411 | |
| 1412 | 1412 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $fieldName, $constraints); |
| 1413 | 1413 | } |
@@ -1424,13 +1424,13 @@ discard block |
||
| 1424 | 1424 | * @return Assert |
| 1425 | 1425 | * @throws AssertionFailedException |
| 1426 | 1426 | */ |
| 1427 | - public function choice(array $choices, string $message='', string $fieldName='') : Assert |
|
| 1427 | + public function choice(array $choices, string $message = '', string $fieldName = '') : Assert |
|
| 1428 | 1428 | { |
| 1429 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1429 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1430 | 1430 | { |
| 1431 | 1431 | return $this; |
| 1432 | 1432 | } |
| 1433 | - if ( !in_array($this->value, $choices, true) ) |
|
| 1433 | + if ( ! in_array($this->value, $choices, true)) |
|
| 1434 | 1434 | { |
| 1435 | 1435 | $message = $message ?: $this->overrideError; |
| 1436 | 1436 | $message = sprintf( |
@@ -1439,7 +1439,7 @@ discard block |
||
| 1439 | 1439 | implode(", ", array_map('Terah\Assert\Assert::stringify', $choices)) |
| 1440 | 1440 | ); |
| 1441 | 1441 | |
| 1442 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $fieldName, ['choices' => $choices]); |
|
| 1442 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_CHOICE, $fieldName, [ 'choices' => $choices ]); |
|
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | return $this; |
@@ -1454,9 +1454,9 @@ discard block |
||
| 1454 | 1454 | * @return Assert |
| 1455 | 1455 | * @throws AssertionFailedException |
| 1456 | 1456 | */ |
| 1457 | - public function inArray(array $choices, string $message='', string $fieldName='') : Assert |
|
| 1457 | + public function inArray(array $choices, string $message = '', string $fieldName = '') : Assert |
|
| 1458 | 1458 | { |
| 1459 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1459 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1460 | 1460 | { |
| 1461 | 1461 | return $this; |
| 1462 | 1462 | } |
@@ -1473,13 +1473,13 @@ discard block |
||
| 1473 | 1473 | * @return Assert |
| 1474 | 1474 | * @throws AssertionFailedException |
| 1475 | 1475 | */ |
| 1476 | - public function numeric(string $message='', string $fieldName='') : Assert |
|
| 1476 | + public function numeric(string $message = '', string $fieldName = '') : Assert |
|
| 1477 | 1477 | { |
| 1478 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1478 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1479 | 1479 | { |
| 1480 | 1480 | return $this; |
| 1481 | 1481 | } |
| 1482 | - if ( ! is_numeric($this->value) ) |
|
| 1482 | + if ( ! is_numeric($this->value)) |
|
| 1483 | 1483 | { |
| 1484 | 1484 | $message = $message ?: $this->overrideError; |
| 1485 | 1485 | $message = sprintf( |
@@ -1501,7 +1501,7 @@ discard block |
||
| 1501 | 1501 | * @return Assert |
| 1502 | 1502 | * @throws AssertionFailedException |
| 1503 | 1503 | */ |
| 1504 | - public function nonEmptyArray(string $message='', string $fieldName='') : Assert |
|
| 1504 | + public function nonEmptyArray(string $message = '', string $fieldName = '') : Assert |
|
| 1505 | 1505 | { |
| 1506 | 1506 | $message = $message ?: 'Value "%s" is not a non-empty array.'; |
| 1507 | 1507 | |
@@ -1516,7 +1516,7 @@ discard block |
||
| 1516 | 1516 | * @return Assert |
| 1517 | 1517 | * @throws AssertionFailedException |
| 1518 | 1518 | */ |
| 1519 | - public function nonEmptyInt(string $message='', string $fieldName='') : Assert |
|
| 1519 | + public function nonEmptyInt(string $message = '', string $fieldName = '') : Assert |
|
| 1520 | 1520 | { |
| 1521 | 1521 | $message = $message ?: 'Value "%s" is not a non-empty integer.'; |
| 1522 | 1522 | |
@@ -1531,7 +1531,7 @@ discard block |
||
| 1531 | 1531 | * @return Assert |
| 1532 | 1532 | * @throws AssertionFailedException |
| 1533 | 1533 | */ |
| 1534 | - public function nonEmptyString(string $message='', string $fieldName='') : Assert |
|
| 1534 | + public function nonEmptyString(string $message = '', string $fieldName = '') : Assert |
|
| 1535 | 1535 | { |
| 1536 | 1536 | $message = $message ?: 'Value "%s" is not a non-empty string.'; |
| 1537 | 1537 | |
@@ -1546,13 +1546,13 @@ discard block |
||
| 1546 | 1546 | * @return Assert |
| 1547 | 1547 | * @throws AssertionFailedException |
| 1548 | 1548 | */ |
| 1549 | - public function isArray(string $message='', string $fieldName='') : Assert |
|
| 1549 | + public function isArray(string $message = '', string $fieldName = '') : Assert |
|
| 1550 | 1550 | { |
| 1551 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1551 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1552 | 1552 | { |
| 1553 | 1553 | return $this; |
| 1554 | 1554 | } |
| 1555 | - if ( !is_array($this->value) ) |
|
| 1555 | + if ( ! is_array($this->value)) |
|
| 1556 | 1556 | { |
| 1557 | 1557 | $message = $message ?: $this->overrideError; |
| 1558 | 1558 | $message = sprintf( |
@@ -1574,13 +1574,13 @@ discard block |
||
| 1574 | 1574 | * @return Assert |
| 1575 | 1575 | * @throws AssertionFailedException |
| 1576 | 1576 | */ |
| 1577 | - public function isTraversable(string $message='', string $fieldName='') : Assert |
|
| 1577 | + public function isTraversable(string $message = '', string $fieldName = '') : Assert |
|
| 1578 | 1578 | { |
| 1579 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1579 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1580 | 1580 | { |
| 1581 | 1581 | return $this; |
| 1582 | 1582 | } |
| 1583 | - if ( !is_array($this->value) && !$this->value instanceof \Traversable ) |
|
| 1583 | + if ( ! is_array($this->value) && ! $this->value instanceof \Traversable) |
|
| 1584 | 1584 | { |
| 1585 | 1585 | $message = $message ?: $this->overrideError; |
| 1586 | 1586 | $message = sprintf( |
@@ -1602,13 +1602,13 @@ discard block |
||
| 1602 | 1602 | * @return Assert |
| 1603 | 1603 | * @throws AssertionFailedException |
| 1604 | 1604 | */ |
| 1605 | - public function isArrayAccessible(string $message='', string $fieldName='') : Assert |
|
| 1605 | + public function isArrayAccessible(string $message = '', string $fieldName = '') : Assert |
|
| 1606 | 1606 | { |
| 1607 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1607 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1608 | 1608 | { |
| 1609 | 1609 | return $this; |
| 1610 | 1610 | } |
| 1611 | - if ( !is_array($this->value) && !$this->value instanceof \ArrayAccess ) |
|
| 1611 | + if ( ! is_array($this->value) && ! $this->value instanceof \ArrayAccess) |
|
| 1612 | 1612 | { |
| 1613 | 1613 | $message = $message ?: $this->overrideError; |
| 1614 | 1614 | $message = sprintf( |
@@ -1631,14 +1631,14 @@ discard block |
||
| 1631 | 1631 | * @return Assert |
| 1632 | 1632 | * @throws AssertionFailedException |
| 1633 | 1633 | */ |
| 1634 | - public function keyExists($key, string $message='', string $fieldName='') : Assert |
|
| 1634 | + public function keyExists($key, string $message = '', string $fieldName = '') : Assert |
|
| 1635 | 1635 | { |
| 1636 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1636 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1637 | 1637 | { |
| 1638 | 1638 | return $this; |
| 1639 | 1639 | } |
| 1640 | 1640 | $this->isArray($message, $fieldName); |
| 1641 | - if ( !array_key_exists($key, $this->value) ) |
|
| 1641 | + if ( ! array_key_exists($key, $this->value)) |
|
| 1642 | 1642 | { |
| 1643 | 1643 | $message = $message ?: $this->overrideError; |
| 1644 | 1644 | $message = sprintf( |
@@ -1646,7 +1646,7 @@ discard block |
||
| 1646 | 1646 | $this->stringify($key) |
| 1647 | 1647 | ); |
| 1648 | 1648 | |
| 1649 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $fieldName, ['key' => $key]); |
|
| 1649 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_EXISTS, $fieldName, [ 'key' => $key ]); |
|
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | 1652 | return $this; |
@@ -1661,23 +1661,23 @@ discard block |
||
| 1661 | 1661 | * @return Assert |
| 1662 | 1662 | * @throws AssertionFailedException |
| 1663 | 1663 | */ |
| 1664 | - public function keysExist(array $keys, string $message='', string $fieldName='') : Assert |
|
| 1664 | + public function keysExist(array $keys, string $message = '', string $fieldName = '') : Assert |
|
| 1665 | 1665 | { |
| 1666 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1666 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1667 | 1667 | { |
| 1668 | 1668 | return $this; |
| 1669 | 1669 | } |
| 1670 | 1670 | $this->isArray($message, $fieldName); |
| 1671 | - foreach ( $keys as $key ) |
|
| 1671 | + foreach ($keys as $key) |
|
| 1672 | 1672 | { |
| 1673 | - if ( !array_key_exists($key, $this->value) ) |
|
| 1673 | + if ( ! array_key_exists($key, $this->value)) |
|
| 1674 | 1674 | { |
| 1675 | 1675 | $message = $message |
| 1676 | 1676 | ?: sprintf( |
| 1677 | 1677 | 'Array does not contain an element with key "%s"', |
| 1678 | 1678 | $this->stringify($key) |
| 1679 | 1679 | ); |
| 1680 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $fieldName, ['key' => $key]); |
|
| 1680 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEYS_EXIST, $fieldName, [ 'key' => $key ]); |
|
| 1681 | 1681 | } |
| 1682 | 1682 | } |
| 1683 | 1683 | |
@@ -1693,14 +1693,14 @@ discard block |
||
| 1693 | 1693 | * @return Assert |
| 1694 | 1694 | * @throws AssertionFailedException |
| 1695 | 1695 | */ |
| 1696 | - public function propertyExists($key, string $message='', string $fieldName='') : Assert |
|
| 1696 | + public function propertyExists($key, string $message = '', string $fieldName = '') : Assert |
|
| 1697 | 1697 | { |
| 1698 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1698 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1699 | 1699 | { |
| 1700 | 1700 | return $this; |
| 1701 | 1701 | } |
| 1702 | 1702 | $this->isObject($message, $fieldName); |
| 1703 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
| 1703 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
| 1704 | 1704 | { |
| 1705 | 1705 | $message = $message |
| 1706 | 1706 | ?: sprintf( |
@@ -1708,7 +1708,7 @@ discard block |
||
| 1708 | 1708 | $this->stringify($key) |
| 1709 | 1709 | ); |
| 1710 | 1710 | |
| 1711 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $fieldName, ['key' => $key]); |
|
| 1711 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTY_EXISTS, $fieldName, [ 'key' => $key ]); |
|
| 1712 | 1712 | } |
| 1713 | 1713 | |
| 1714 | 1714 | return $this; |
@@ -1723,24 +1723,24 @@ discard block |
||
| 1723 | 1723 | * @return Assert |
| 1724 | 1724 | * @throws AssertionFailedException |
| 1725 | 1725 | */ |
| 1726 | - public function propertiesExist(array $keys, string $message='', string $fieldName='') : Assert |
|
| 1726 | + public function propertiesExist(array $keys, string $message = '', string $fieldName = '') : Assert |
|
| 1727 | 1727 | { |
| 1728 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1728 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1729 | 1729 | { |
| 1730 | 1730 | return $this; |
| 1731 | 1731 | } |
| 1732 | 1732 | $this->isObject($message, $fieldName); |
| 1733 | - foreach ( $keys as $key ) |
|
| 1733 | + foreach ($keys as $key) |
|
| 1734 | 1734 | { |
| 1735 | 1735 | // Using isset to allow resolution of magically defined properties |
| 1736 | - if ( !property_exists($this->value, $key) && !isset( $this->value->{$key} ) ) |
|
| 1736 | + if ( ! property_exists($this->value, $key) && ! isset($this->value->{$key} )) |
|
| 1737 | 1737 | { |
| 1738 | 1738 | $message = $message |
| 1739 | 1739 | ?: sprintf( |
| 1740 | 1740 | 'Object does not contain a property with key "%s"', |
| 1741 | 1741 | $this->stringify($key) |
| 1742 | 1742 | ); |
| 1743 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $fieldName, ['key' => $key]); |
|
| 1743 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_PROPERTIES_EXIST, $fieldName, [ 'key' => $key ]); |
|
| 1744 | 1744 | } |
| 1745 | 1745 | } |
| 1746 | 1746 | |
@@ -1755,14 +1755,14 @@ discard block |
||
| 1755 | 1755 | * @return Assert |
| 1756 | 1756 | * @throws AssertionFailedException |
| 1757 | 1757 | */ |
| 1758 | - public function utf8(string $message='', string $fieldName='') : Assert |
|
| 1758 | + public function utf8(string $message = '', string $fieldName = '') : Assert |
|
| 1759 | 1759 | { |
| 1760 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1760 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1761 | 1761 | { |
| 1762 | 1762 | return $this; |
| 1763 | 1763 | } |
| 1764 | 1764 | $this->string($message, $fieldName); |
| 1765 | - if ( mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8' ) |
|
| 1765 | + if (mb_detect_encoding($this->value, 'UTF-8', true) !== 'UTF-8') |
|
| 1766 | 1766 | { |
| 1767 | 1767 | $message = $message |
| 1768 | 1768 | ?: sprintf( |
@@ -1785,14 +1785,14 @@ discard block |
||
| 1785 | 1785 | * @return Assert |
| 1786 | 1786 | * @throws AssertionFailedException |
| 1787 | 1787 | */ |
| 1788 | - public function ascii(string $message='', string $fieldName='') : Assert |
|
| 1788 | + public function ascii(string $message = '', string $fieldName = '') : Assert |
|
| 1789 | 1789 | { |
| 1790 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1790 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1791 | 1791 | { |
| 1792 | 1792 | return $this; |
| 1793 | 1793 | } |
| 1794 | 1794 | $this->string($message, $fieldName); |
| 1795 | - if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
| 1795 | + if ( ! preg_match('/^[ -~]+$/', $this->value)) |
|
| 1796 | 1796 | { |
| 1797 | 1797 | $message = $message |
| 1798 | 1798 | ?: sprintf( |
@@ -1816,14 +1816,14 @@ discard block |
||
| 1816 | 1816 | * @return Assert |
| 1817 | 1817 | * @throws AssertionFailedException |
| 1818 | 1818 | */ |
| 1819 | - public function keyIsset($key, string $message='', string $fieldName='') : Assert |
|
| 1819 | + public function keyIsset($key, string $message = '', string $fieldName = '') : Assert |
|
| 1820 | 1820 | { |
| 1821 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1821 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1822 | 1822 | { |
| 1823 | 1823 | return $this; |
| 1824 | 1824 | } |
| 1825 | 1825 | $this->isArrayAccessible($message, $fieldName); |
| 1826 | - if ( !isset( $this->value[$key] ) ) |
|
| 1826 | + if ( ! isset($this->value[ $key ])) |
|
| 1827 | 1827 | { |
| 1828 | 1828 | $message = $message ?: $this->overrideError; |
| 1829 | 1829 | $message = sprintf( |
@@ -1831,7 +1831,7 @@ discard block |
||
| 1831 | 1831 | $this->stringify($key) |
| 1832 | 1832 | ); |
| 1833 | 1833 | |
| 1834 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $fieldName, ['key' => $key]); |
|
| 1834 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_KEY_ISSET, $fieldName, [ 'key' => $key ]); |
|
| 1835 | 1835 | } |
| 1836 | 1836 | |
| 1837 | 1837 | return $this; |
@@ -1847,14 +1847,14 @@ discard block |
||
| 1847 | 1847 | * @return Assert |
| 1848 | 1848 | * @throws AssertionFailedException |
| 1849 | 1849 | */ |
| 1850 | - public function notEmptyKey($key, string $message='', string $fieldName='') : Assert |
|
| 1850 | + public function notEmptyKey($key, string $message = '', string $fieldName = '') : Assert |
|
| 1851 | 1851 | { |
| 1852 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1852 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1853 | 1853 | { |
| 1854 | 1854 | return $this; |
| 1855 | 1855 | } |
| 1856 | 1856 | $this->keyIsset($key, $message, $fieldName); |
| 1857 | - (new Assert($this->value[$key]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $fieldName); |
|
| 1857 | + (new Assert($this->value[ $key ]))->setExceptionClass($this->exceptionClass)->notEmpty($message, $fieldName); |
|
| 1858 | 1858 | |
| 1859 | 1859 | return $this; |
| 1860 | 1860 | } |
@@ -1867,13 +1867,13 @@ discard block |
||
| 1867 | 1867 | * @return Assert |
| 1868 | 1868 | * @throws AssertionFailedException |
| 1869 | 1869 | */ |
| 1870 | - public function notBlank(string $message='', string $fieldName='') : Assert |
|
| 1870 | + public function notBlank(string $message = '', string $fieldName = '') : Assert |
|
| 1871 | 1871 | { |
| 1872 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1872 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1873 | 1873 | { |
| 1874 | 1874 | return $this; |
| 1875 | 1875 | } |
| 1876 | - if ( false === $this->value || ( empty( $this->value ) && '0' != $this->value ) ) |
|
| 1876 | + if (false === $this->value || (empty($this->value) && '0' != $this->value)) |
|
| 1877 | 1877 | { |
| 1878 | 1878 | $message = $message ?: $this->overrideError; |
| 1879 | 1879 | $message = sprintf( |
@@ -1896,13 +1896,13 @@ discard block |
||
| 1896 | 1896 | * @return Assert |
| 1897 | 1897 | * @throws AssertionFailedException |
| 1898 | 1898 | */ |
| 1899 | - public function isInstanceOf(string $className, string $message='', string $fieldName='') : Assert |
|
| 1899 | + public function isInstanceOf(string $className, string $message = '', string $fieldName = '') : Assert |
|
| 1900 | 1900 | { |
| 1901 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1901 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1902 | 1902 | { |
| 1903 | 1903 | return $this; |
| 1904 | 1904 | } |
| 1905 | - if ( !( $this->value instanceof $className ) ) |
|
| 1905 | + if ( ! ($this->value instanceof $className)) |
|
| 1906 | 1906 | { |
| 1907 | 1907 | $message = $message ?: $this->overrideError; |
| 1908 | 1908 | $message = sprintf( |
@@ -1911,7 +1911,7 @@ discard block |
||
| 1911 | 1911 | $className |
| 1912 | 1912 | ); |
| 1913 | 1913 | |
| 1914 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $fieldName, ['class' => $className]); |
|
| 1914 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_INSTANCE_OF, $fieldName, [ 'class' => $className ]); |
|
| 1915 | 1915 | } |
| 1916 | 1916 | |
| 1917 | 1917 | return $this; |
@@ -1926,13 +1926,13 @@ discard block |
||
| 1926 | 1926 | * @return Assert |
| 1927 | 1927 | * @throws AssertionFailedException |
| 1928 | 1928 | */ |
| 1929 | - public function notIsInstanceOf(string $className, string $message='', string $fieldName='') : Assert |
|
| 1929 | + public function notIsInstanceOf(string $className, string $message = '', string $fieldName = '') : Assert |
|
| 1930 | 1930 | { |
| 1931 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1931 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1932 | 1932 | { |
| 1933 | 1933 | return $this; |
| 1934 | 1934 | } |
| 1935 | - if ( $this->value instanceof $className ) |
|
| 1935 | + if ($this->value instanceof $className) |
|
| 1936 | 1936 | { |
| 1937 | 1937 | $message = $message ?: $this->overrideError; |
| 1938 | 1938 | $message = sprintf( |
@@ -1941,7 +1941,7 @@ discard block |
||
| 1941 | 1941 | $className |
| 1942 | 1942 | ); |
| 1943 | 1943 | |
| 1944 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $fieldName, ['class' => $className]); |
|
| 1944 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_NOT_INSTANCE_OF, $fieldName, [ 'class' => $className ]); |
|
| 1945 | 1945 | } |
| 1946 | 1946 | |
| 1947 | 1947 | return $this; |
@@ -1956,13 +1956,13 @@ discard block |
||
| 1956 | 1956 | * @return Assert |
| 1957 | 1957 | * @throws AssertionFailedException |
| 1958 | 1958 | */ |
| 1959 | - public function subclassOf(string $className, string $message='', string $fieldName='') : Assert |
|
| 1959 | + public function subclassOf(string $className, string $message = '', string $fieldName = '') : Assert |
|
| 1960 | 1960 | { |
| 1961 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1961 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1962 | 1962 | { |
| 1963 | 1963 | return $this; |
| 1964 | 1964 | } |
| 1965 | - if ( !is_subclass_of($this->value, $className) ) |
|
| 1965 | + if ( ! is_subclass_of($this->value, $className)) |
|
| 1966 | 1966 | { |
| 1967 | 1967 | $message = $message ?: $this->overrideError; |
| 1968 | 1968 | $message = sprintf( |
@@ -1971,7 +1971,7 @@ discard block |
||
| 1971 | 1971 | $className |
| 1972 | 1972 | ); |
| 1973 | 1973 | |
| 1974 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $fieldName, ['class' => $className]); |
|
| 1974 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_SUBCLASS_OF, $fieldName, [ 'class' => $className ]); |
|
| 1975 | 1975 | } |
| 1976 | 1976 | |
| 1977 | 1977 | return $this; |
@@ -1987,14 +1987,14 @@ discard block |
||
| 1987 | 1987 | * @return Assert |
| 1988 | 1988 | * @throws AssertionFailedException |
| 1989 | 1989 | */ |
| 1990 | - public function range(float $minValue, float $maxValue, string $message='', string $fieldName='') : Assert |
|
| 1990 | + public function range(float $minValue, float $maxValue, string $message = '', string $fieldName = '') : Assert |
|
| 1991 | 1991 | { |
| 1992 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 1992 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 1993 | 1993 | { |
| 1994 | 1994 | return $this; |
| 1995 | 1995 | } |
| 1996 | 1996 | $this->numeric($message, $fieldName); |
| 1997 | - if ( $this->value < $minValue || $this->value > $maxValue ) |
|
| 1997 | + if ($this->value < $minValue || $this->value > $maxValue) |
|
| 1998 | 1998 | { |
| 1999 | 1999 | $message = $message ?: $this->overrideError; |
| 2000 | 2000 | $message = sprintf( |
@@ -2022,14 +2022,14 @@ discard block |
||
| 2022 | 2022 | * @return Assert |
| 2023 | 2023 | * @throws AssertionFailedException |
| 2024 | 2024 | */ |
| 2025 | - public function min(int $minValue, string $message='', string $fieldName='') : Assert |
|
| 2025 | + public function min(int $minValue, string $message = '', string $fieldName = '') : Assert |
|
| 2026 | 2026 | { |
| 2027 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2027 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2028 | 2028 | { |
| 2029 | 2029 | return $this; |
| 2030 | 2030 | } |
| 2031 | 2031 | $this->numeric($message, $fieldName); |
| 2032 | - if ( $this->value < $minValue ) |
|
| 2032 | + if ($this->value < $minValue) |
|
| 2033 | 2033 | { |
| 2034 | 2034 | $message = $message ?: $this->overrideError; |
| 2035 | 2035 | $message = sprintf( |
@@ -2038,7 +2038,7 @@ discard block |
||
| 2038 | 2038 | $this->stringify($minValue) |
| 2039 | 2039 | ); |
| 2040 | 2040 | |
| 2041 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $fieldName, ['min' => $minValue]); |
|
| 2041 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MIN, $fieldName, [ 'min' => $minValue ]); |
|
| 2042 | 2042 | } |
| 2043 | 2043 | |
| 2044 | 2044 | return $this; |
@@ -2053,14 +2053,14 @@ discard block |
||
| 2053 | 2053 | * @return Assert |
| 2054 | 2054 | * @throws AssertionFailedException |
| 2055 | 2055 | */ |
| 2056 | - public function max(int $maxValue, string $message='', string $fieldName='') : Assert |
|
| 2056 | + public function max(int $maxValue, string $message = '', string $fieldName = '') : Assert |
|
| 2057 | 2057 | { |
| 2058 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2058 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2059 | 2059 | { |
| 2060 | 2060 | return $this; |
| 2061 | 2061 | } |
| 2062 | 2062 | $this->numeric($message, $fieldName); |
| 2063 | - if ( $this->value > $maxValue ) |
|
| 2063 | + if ($this->value > $maxValue) |
|
| 2064 | 2064 | { |
| 2065 | 2065 | $message = $message ?: $this->overrideError; |
| 2066 | 2066 | $message = sprintf( |
@@ -2069,7 +2069,7 @@ discard block |
||
| 2069 | 2069 | $this->stringify($maxValue) |
| 2070 | 2070 | ); |
| 2071 | 2071 | |
| 2072 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $fieldName, ['max' => $maxValue]); |
|
| 2072 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_MAX, $fieldName, [ 'max' => $maxValue ]); |
|
| 2073 | 2073 | } |
| 2074 | 2074 | |
| 2075 | 2075 | return $this; |
@@ -2083,15 +2083,15 @@ discard block |
||
| 2083 | 2083 | * @return Assert |
| 2084 | 2084 | * @throws AssertionFailedException |
| 2085 | 2085 | */ |
| 2086 | - public function file(string $message='', string $fieldName='') : Assert |
|
| 2086 | + public function file(string $message = '', string $fieldName = '') : Assert |
|
| 2087 | 2087 | { |
| 2088 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2088 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2089 | 2089 | { |
| 2090 | 2090 | return $this; |
| 2091 | 2091 | } |
| 2092 | 2092 | $this->string($message, $fieldName); |
| 2093 | 2093 | $this->notEmpty($message, $fieldName); |
| 2094 | - if ( !is_file($this->value) ) |
|
| 2094 | + if ( ! is_file($this->value)) |
|
| 2095 | 2095 | { |
| 2096 | 2096 | $message = $message ?: $this->overrideError; |
| 2097 | 2097 | $message = sprintf( |
@@ -2113,15 +2113,15 @@ discard block |
||
| 2113 | 2113 | * @return Assert |
| 2114 | 2114 | * @throws AssertionFailedException |
| 2115 | 2115 | */ |
| 2116 | - public function fileOrDirectoryExists(string $message='', string $fieldName='') : Assert |
|
| 2116 | + public function fileOrDirectoryExists(string $message = '', string $fieldName = '') : Assert |
|
| 2117 | 2117 | { |
| 2118 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2118 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2119 | 2119 | { |
| 2120 | 2120 | return $this; |
| 2121 | 2121 | } |
| 2122 | 2122 | $this->string($message, $fieldName); |
| 2123 | 2123 | $this->notEmpty($message, $fieldName); |
| 2124 | - if ( ! file_exists($this->value) ) |
|
| 2124 | + if ( ! file_exists($this->value)) |
|
| 2125 | 2125 | { |
| 2126 | 2126 | $message = $message ?: $this->overrideError; |
| 2127 | 2127 | $message = sprintf( |
@@ -2143,14 +2143,14 @@ discard block |
||
| 2143 | 2143 | * @return Assert |
| 2144 | 2144 | * @throws AssertionFailedException |
| 2145 | 2145 | */ |
| 2146 | - public function directory(string $message='', string $fieldName='') : Assert |
|
| 2146 | + public function directory(string $message = '', string $fieldName = '') : Assert |
|
| 2147 | 2147 | { |
| 2148 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2148 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2149 | 2149 | { |
| 2150 | 2150 | return $this; |
| 2151 | 2151 | } |
| 2152 | 2152 | $this->string($message, $fieldName); |
| 2153 | - if ( !is_dir($this->value) ) |
|
| 2153 | + if ( ! is_dir($this->value)) |
|
| 2154 | 2154 | { |
| 2155 | 2155 | $message = $message ?: $this->overrideError; |
| 2156 | 2156 | $message = sprintf( |
@@ -2172,14 +2172,14 @@ discard block |
||
| 2172 | 2172 | * @return Assert |
| 2173 | 2173 | * @throws AssertionFailedException |
| 2174 | 2174 | */ |
| 2175 | - public function readable(string $message='', string $fieldName='') : Assert |
|
| 2175 | + public function readable(string $message = '', string $fieldName = '') : Assert |
|
| 2176 | 2176 | { |
| 2177 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2177 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2178 | 2178 | { |
| 2179 | 2179 | return $this; |
| 2180 | 2180 | } |
| 2181 | 2181 | $this->string($message, $fieldName); |
| 2182 | - if ( !is_readable($this->value) ) |
|
| 2182 | + if ( ! is_readable($this->value)) |
|
| 2183 | 2183 | { |
| 2184 | 2184 | $message = $message ?: $this->overrideError; |
| 2185 | 2185 | $message = sprintf( |
@@ -2201,14 +2201,14 @@ discard block |
||
| 2201 | 2201 | * @return Assert |
| 2202 | 2202 | * @throws AssertionFailedException |
| 2203 | 2203 | */ |
| 2204 | - public function writeable(string $message='', string $fieldName='') : Assert |
|
| 2204 | + public function writeable(string $message = '', string $fieldName = '') : Assert |
|
| 2205 | 2205 | { |
| 2206 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2206 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2207 | 2207 | { |
| 2208 | 2208 | return $this; |
| 2209 | 2209 | } |
| 2210 | 2210 | $this->string($message, $fieldName); |
| 2211 | - if ( !is_writeable($this->value) ) |
|
| 2211 | + if ( ! is_writeable($this->value)) |
|
| 2212 | 2212 | { |
| 2213 | 2213 | $message = $message ?: $this->overrideError; |
| 2214 | 2214 | $message = sprintf( |
@@ -2230,14 +2230,14 @@ discard block |
||
| 2230 | 2230 | * @return Assert |
| 2231 | 2231 | * @throws AssertionFailedException |
| 2232 | 2232 | */ |
| 2233 | - public function email(string $message='', string $fieldName='') : Assert |
|
| 2233 | + public function email(string $message = '', string $fieldName = '') : Assert |
|
| 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 | 2239 | $this->string($message, $fieldName); |
| 2240 | - if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL) ) |
|
| 2240 | + if ( ! filter_var($this->value, FILTER_VALIDATE_EMAIL)) |
|
| 2241 | 2241 | { |
| 2242 | 2242 | $message = $message ?: $this->overrideError; |
| 2243 | 2243 | $message = sprintf( |
@@ -2251,7 +2251,7 @@ discard block |
||
| 2251 | 2251 | { |
| 2252 | 2252 | $host = substr($this->value, strpos($this->value, '@') + 1); |
| 2253 | 2253 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
| 2254 | - if ( version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false ) |
|
| 2254 | + if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) |
|
| 2255 | 2255 | { |
| 2256 | 2256 | $message = $message ?: $this->overrideError; |
| 2257 | 2257 | $message = sprintf( |
@@ -2273,9 +2273,9 @@ discard block |
||
| 2273 | 2273 | * @return Assert |
| 2274 | 2274 | * @throws AssertionFailedException |
| 2275 | 2275 | */ |
| 2276 | - public function emailPrefix(string $message='', string $fieldName='') : Assert |
|
| 2276 | + public function emailPrefix(string $message = '', string $fieldName = '') : Assert |
|
| 2277 | 2277 | { |
| 2278 | - $this->value($this->value . '@example.com'); |
|
| 2278 | + $this->value($this->value.'@example.com'); |
|
| 2279 | 2279 | |
| 2280 | 2280 | return $this->email($message, $fieldName); |
| 2281 | 2281 | } |
@@ -2294,14 +2294,14 @@ discard block |
||
| 2294 | 2294 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
| 2295 | 2295 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
| 2296 | 2296 | */ |
| 2297 | - public function url(string $message='', string $fieldName='') : Assert |
|
| 2297 | + public function url(string $message = '', string $fieldName = '') : Assert |
|
| 2298 | 2298 | { |
| 2299 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2299 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2300 | 2300 | { |
| 2301 | 2301 | return $this; |
| 2302 | 2302 | } |
| 2303 | 2303 | $this->string($message, $fieldName); |
| 2304 | - $protocols = ['http', 'https']; |
|
| 2304 | + $protocols = [ 'http', 'https' ]; |
|
| 2305 | 2305 | $pattern = '~^ |
| 2306 | 2306 | (%s):// # protocol |
| 2307 | 2307 | ( |
@@ -2316,8 +2316,8 @@ discard block |
||
| 2316 | 2316 | (:[0-9]+)? # a port (optional) |
| 2317 | 2317 | (/?|/\S+) # a /, nothing or a / with something |
| 2318 | 2318 | $~ixu'; |
| 2319 | - $pattern = sprintf($pattern, implode('|', $protocols)); |
|
| 2320 | - if ( !preg_match($pattern, $this->value) ) |
|
| 2319 | + $pattern = sprintf($pattern, implode('|', $protocols)); |
|
| 2320 | + if ( ! preg_match($pattern, $this->value)) |
|
| 2321 | 2321 | { |
| 2322 | 2322 | $message = $message ?: $this->overrideError; |
| 2323 | 2323 | $message = sprintf( |
@@ -2342,15 +2342,15 @@ discard block |
||
| 2342 | 2342 | * @throws AssertionFailedException |
| 2343 | 2343 | * |
| 2344 | 2344 | */ |
| 2345 | - public function domainName(string $message='', string $fieldName='') : Assert |
|
| 2345 | + public function domainName(string $message = '', string $fieldName = '') : Assert |
|
| 2346 | 2346 | { |
| 2347 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2347 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2348 | 2348 | { |
| 2349 | 2349 | return $this; |
| 2350 | 2350 | } |
| 2351 | 2351 | $this->string($message, $fieldName); |
| 2352 | - $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
| 2353 | - if ( ! preg_match($pattern, $this->value) ) |
|
| 2352 | + $pattern = '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/'; |
|
| 2353 | + if ( ! preg_match($pattern, $this->value)) |
|
| 2354 | 2354 | { |
| 2355 | 2355 | $message = $message ?: $this->overrideError; |
| 2356 | 2356 | $message = sprintf( |
@@ -2372,9 +2372,9 @@ discard block |
||
| 2372 | 2372 | * @return Assert |
| 2373 | 2373 | * @throws AssertionFailedException |
| 2374 | 2374 | */ |
| 2375 | - public function ausMobile(string $message='', string $fieldName='') : Assert |
|
| 2375 | + public function ausMobile(string $message = '', string $fieldName = '') : Assert |
|
| 2376 | 2376 | { |
| 2377 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2377 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2378 | 2378 | { |
| 2379 | 2379 | return $this; |
| 2380 | 2380 | } |
@@ -2382,7 +2382,7 @@ discard block |
||
| 2382 | 2382 | { |
| 2383 | 2383 | $this->regex('/^04[0-9]{8})$/', $message, $fieldName); |
| 2384 | 2384 | } |
| 2385 | - catch ( AssertionFailedException $e ) |
|
| 2385 | + catch (AssertionFailedException $e) |
|
| 2386 | 2386 | { |
| 2387 | 2387 | $message = $message ?: $this->overrideError; |
| 2388 | 2388 | $message = sprintf( |
@@ -2405,9 +2405,9 @@ discard block |
||
| 2405 | 2405 | * @return Assert |
| 2406 | 2406 | * @throws AssertionFailedException |
| 2407 | 2407 | */ |
| 2408 | - public function alnum(string $message='', string $fieldName='') : Assert |
|
| 2408 | + public function alnum(string $message = '', string $fieldName = '') : Assert |
|
| 2409 | 2409 | { |
| 2410 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2410 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2411 | 2411 | { |
| 2412 | 2412 | return $this; |
| 2413 | 2413 | } |
@@ -2438,13 +2438,13 @@ discard block |
||
| 2438 | 2438 | * @return Assert |
| 2439 | 2439 | * @throws AssertionFailedException |
| 2440 | 2440 | */ |
| 2441 | - public function true(string $message='', string $fieldName='') : Assert |
|
| 2441 | + public function true(string $message = '', string $fieldName = '') : Assert |
|
| 2442 | 2442 | { |
| 2443 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2443 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2444 | 2444 | { |
| 2445 | 2445 | return $this; |
| 2446 | 2446 | } |
| 2447 | - if ( $this->value !== true ) |
|
| 2447 | + if ($this->value !== true) |
|
| 2448 | 2448 | { |
| 2449 | 2449 | $message = $message ?: $this->overrideError; |
| 2450 | 2450 | $message = sprintf( |
@@ -2466,13 +2466,13 @@ discard block |
||
| 2466 | 2466 | * @return Assert |
| 2467 | 2467 | * @throws AssertionFailedException |
| 2468 | 2468 | */ |
| 2469 | - public function truthy(string $message='', string $fieldName='') : Assert |
|
| 2469 | + public function truthy(string $message = '', string $fieldName = '') : Assert |
|
| 2470 | 2470 | { |
| 2471 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2471 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2472 | 2472 | { |
| 2473 | 2473 | return $this; |
| 2474 | 2474 | } |
| 2475 | - if ( ! $this->value ) |
|
| 2475 | + if ( ! $this->value) |
|
| 2476 | 2476 | { |
| 2477 | 2477 | $message = $message ?: $this->overrideError; |
| 2478 | 2478 | $message = sprintf( |
@@ -2494,13 +2494,13 @@ discard block |
||
| 2494 | 2494 | * @return Assert |
| 2495 | 2495 | * @throws AssertionFailedException |
| 2496 | 2496 | */ |
| 2497 | - public function false(string $message='', string $fieldName='') : Assert |
|
| 2497 | + public function false(string $message = '', string $fieldName = '') : Assert |
|
| 2498 | 2498 | { |
| 2499 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2499 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2500 | 2500 | { |
| 2501 | 2501 | return $this; |
| 2502 | 2502 | } |
| 2503 | - if ( $this->value !== false ) |
|
| 2503 | + if ($this->value !== false) |
|
| 2504 | 2504 | { |
| 2505 | 2505 | $message = $message ?: $this->overrideError; |
| 2506 | 2506 | $message = sprintf( |
@@ -2522,13 +2522,13 @@ discard block |
||
| 2522 | 2522 | * @return Assert |
| 2523 | 2523 | * @throws AssertionFailedException |
| 2524 | 2524 | */ |
| 2525 | - public function notFalse(string $message='', string $fieldName='') : Assert |
|
| 2525 | + public function notFalse(string $message = '', string $fieldName = '') : Assert |
|
| 2526 | 2526 | { |
| 2527 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2527 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2528 | 2528 | { |
| 2529 | 2529 | return $this; |
| 2530 | 2530 | } |
| 2531 | - if ( $this->value === false ) |
|
| 2531 | + if ($this->value === false) |
|
| 2532 | 2532 | { |
| 2533 | 2533 | $message = $message ?: $this->overrideError; |
| 2534 | 2534 | $message = sprintf( |
@@ -2550,13 +2550,13 @@ discard block |
||
| 2550 | 2550 | * @return Assert |
| 2551 | 2551 | * @throws AssertionFailedException |
| 2552 | 2552 | */ |
| 2553 | - public function classExists(string $message='', string $fieldName='') : Assert |
|
| 2553 | + public function classExists(string $message = '', string $fieldName = '') : Assert |
|
| 2554 | 2554 | { |
| 2555 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2555 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2556 | 2556 | { |
| 2557 | 2557 | return $this; |
| 2558 | 2558 | } |
| 2559 | - if ( !class_exists($this->value) ) |
|
| 2559 | + if ( ! class_exists($this->value)) |
|
| 2560 | 2560 | { |
| 2561 | 2561 | $message = $message ?: $this->overrideError; |
| 2562 | 2562 | $message = sprintf( |
@@ -2578,14 +2578,14 @@ discard block |
||
| 2578 | 2578 | * @throws AssertionFailedException |
| 2579 | 2579 | * @throws \ReflectionException |
| 2580 | 2580 | */ |
| 2581 | - public function implementsInterface(string $interfaceName, string $message='', string $fieldName='') : Assert |
|
| 2581 | + public function implementsInterface(string $interfaceName, string $message = '', string $fieldName = '') : Assert |
|
| 2582 | 2582 | { |
| 2583 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2583 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2584 | 2584 | { |
| 2585 | 2585 | return $this; |
| 2586 | 2586 | } |
| 2587 | 2587 | $reflection = new \ReflectionClass($this->value); |
| 2588 | - if ( !$reflection->implementsInterface($interfaceName) ) |
|
| 2588 | + if ( ! $reflection->implementsInterface($interfaceName)) |
|
| 2589 | 2589 | { |
| 2590 | 2590 | $message = $message ?: $this->overrideError; |
| 2591 | 2591 | $message = sprintf( |
@@ -2594,7 +2594,7 @@ discard block |
||
| 2594 | 2594 | $this->stringify($interfaceName) |
| 2595 | 2595 | ); |
| 2596 | 2596 | |
| 2597 | - throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $fieldName, ['interface' => $interfaceName]); |
|
| 2597 | + throw $this->createException($message, self::INTERFACE_NOT_IMPLEMENTED, $fieldName, [ 'interface' => $interfaceName ]); |
|
| 2598 | 2598 | } |
| 2599 | 2599 | |
| 2600 | 2600 | return $this; |
@@ -2614,13 +2614,13 @@ discard block |
||
| 2614 | 2614 | * @return Assert |
| 2615 | 2615 | * @throws AssertionFailedException |
| 2616 | 2616 | */ |
| 2617 | - public function isJsonString(string $message='', string $fieldName='') : Assert |
|
| 2617 | + public function isJsonString(string $message = '', string $fieldName = '') : Assert |
|
| 2618 | 2618 | { |
| 2619 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2619 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2620 | 2620 | { |
| 2621 | 2621 | return $this; |
| 2622 | 2622 | } |
| 2623 | - if ( null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error() ) |
|
| 2623 | + if (null === json_decode($this->value) && JSON_ERROR_NONE !== json_last_error()) |
|
| 2624 | 2624 | { |
| 2625 | 2625 | $message = $message ?: $this->overrideError; |
| 2626 | 2626 | $message = sprintf( |
@@ -2644,18 +2644,18 @@ discard block |
||
| 2644 | 2644 | * @return Assert |
| 2645 | 2645 | * @throws AssertionFailedException |
| 2646 | 2646 | */ |
| 2647 | - public function uuid(string $message='', string $fieldName='') : Assert |
|
| 2647 | + public function uuid(string $message = '', string $fieldName = '') : Assert |
|
| 2648 | 2648 | { |
| 2649 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2649 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2650 | 2650 | { |
| 2651 | 2651 | return $this; |
| 2652 | 2652 | } |
| 2653 | - $this->value = str_replace(['urn:', 'uuid:', '{', '}'], '', $this->value); |
|
| 2654 | - if ( $this->value === '00000000-0000-0000-0000-000000000000' ) |
|
| 2653 | + $this->value = str_replace([ 'urn:', 'uuid:', '{', '}' ], '', $this->value); |
|
| 2654 | + if ($this->value === '00000000-0000-0000-0000-000000000000') |
|
| 2655 | 2655 | { |
| 2656 | 2656 | return $this; |
| 2657 | 2657 | } |
| 2658 | - 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) ) |
|
| 2658 | + 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)) |
|
| 2659 | 2659 | { |
| 2660 | 2660 | $message = $message ?: $this->overrideError; |
| 2661 | 2661 | $message = sprintf( |
@@ -2684,13 +2684,13 @@ discard block |
||
| 2684 | 2684 | * @return Assert |
| 2685 | 2685 | * @throws AssertionFailedException |
| 2686 | 2686 | */ |
| 2687 | - public function samAccountName(string $message='', string $fieldName='') : Assert |
|
| 2687 | + public function samAccountName(string $message = '', string $fieldName = '') : Assert |
|
| 2688 | 2688 | { |
| 2689 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2689 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2690 | 2690 | { |
| 2691 | 2691 | return $this; |
| 2692 | 2692 | } |
| 2693 | - if ( !preg_match('/^([a-z0-9]{4,20})$/', $this->value) ) |
|
| 2693 | + if ( ! preg_match('/^([a-z0-9]{4,20})$/', $this->value)) |
|
| 2694 | 2694 | { |
| 2695 | 2695 | $message = $message ?: $this->overrideError; |
| 2696 | 2696 | $message = sprintf( |
@@ -2712,9 +2712,9 @@ discard block |
||
| 2712 | 2712 | * @return Assert |
| 2713 | 2713 | * @throws AssertionFailedException |
| 2714 | 2714 | */ |
| 2715 | - public function userPrincipalName(string $message='', string $fieldName='') : Assert |
|
| 2715 | + public function userPrincipalName(string $message = '', string $fieldName = '') : Assert |
|
| 2716 | 2716 | { |
| 2717 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2717 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2718 | 2718 | { |
| 2719 | 2719 | return $this; |
| 2720 | 2720 | } |
@@ -2747,13 +2747,13 @@ discard block |
||
| 2747 | 2747 | * @return Assert |
| 2748 | 2748 | * @throws AssertionFailedException |
| 2749 | 2749 | */ |
| 2750 | - public function isni(string $message='', string $fieldName='') |
|
| 2750 | + public function isni(string $message = '', string $fieldName = '') |
|
| 2751 | 2751 | { |
| 2752 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2752 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2753 | 2753 | { |
| 2754 | 2754 | return $this; |
| 2755 | 2755 | } |
| 2756 | - if ( !preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]{1}$/', $this->value) ) |
|
| 2756 | + if ( ! preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]{1}$/', $this->value)) |
|
| 2757 | 2757 | { |
| 2758 | 2758 | $message = $message ?: $this->overrideError; |
| 2759 | 2759 | $message = sprintf( |
@@ -2776,13 +2776,13 @@ discard block |
||
| 2776 | 2776 | * @return Assert |
| 2777 | 2777 | * @throws AssertionFailedException |
| 2778 | 2778 | */ |
| 2779 | - public function count(int $count, string $message='', string $fieldName='') : Assert |
|
| 2779 | + public function count(int $count, string $message = '', string $fieldName = '') : Assert |
|
| 2780 | 2780 | { |
| 2781 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2781 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2782 | 2782 | { |
| 2783 | 2783 | return $this; |
| 2784 | 2784 | } |
| 2785 | - if ( $count !== count($this->value) ) |
|
| 2785 | + if ($count !== count($this->value)) |
|
| 2786 | 2786 | { |
| 2787 | 2787 | $message = $message ?: $this->overrideError; |
| 2788 | 2788 | $message = sprintf( |
@@ -2791,7 +2791,7 @@ discard block |
||
| 2791 | 2791 | $this->stringify($count) |
| 2792 | 2792 | ); |
| 2793 | 2793 | |
| 2794 | - throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $fieldName, ['count' => $count]); |
|
| 2794 | + throw $this->createException($message, $this->overrideCode ?: self::INVALID_COUNT, $fieldName, [ 'count' => $count ]); |
|
| 2795 | 2795 | } |
| 2796 | 2796 | |
| 2797 | 2797 | return $this; |
@@ -2805,25 +2805,25 @@ discard block |
||
| 2805 | 2805 | */ |
| 2806 | 2806 | protected function doAllOrNullOr($func, $args) : bool |
| 2807 | 2807 | { |
| 2808 | - if ( $this->nullOr && is_null($this->value) ) |
|
| 2808 | + if ($this->nullOr && is_null($this->value)) |
|
| 2809 | 2809 | { |
| 2810 | 2810 | return true; |
| 2811 | 2811 | } |
| 2812 | - if ( $this->emptyOr && empty($this->value) ) |
|
| 2812 | + if ($this->emptyOr && empty($this->value)) |
|
| 2813 | 2813 | { |
| 2814 | 2814 | return true; |
| 2815 | 2815 | } |
| 2816 | - if ( $this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable() ) |
|
| 2816 | + if ($this->all && (new Assert($this->value))->setExceptionClass($this->exceptionClass)->isTraversable()) |
|
| 2817 | 2817 | { |
| 2818 | - foreach ( $this->value as $idx => $value ) |
|
| 2818 | + foreach ($this->value as $idx => $value) |
|
| 2819 | 2819 | { |
| 2820 | 2820 | $object = (new Assert($value))->setExceptionClass($this->exceptionClass); |
| 2821 | - call_user_func_array([$object, $func], $args); |
|
| 2821 | + call_user_func_array([ $object, $func ], $args); |
|
| 2822 | 2822 | } |
| 2823 | 2823 | return true; |
| 2824 | 2824 | } |
| 2825 | 2825 | |
| 2826 | - return ( $this->nullOr && is_null($this->value) ) || ( $this->emptyOr && empty($this->value) ) ? true : false; |
|
| 2826 | + return ($this->nullOr && is_null($this->value)) || ($this->emptyOr && empty($this->value)) ? true : false; |
|
| 2827 | 2827 | } |
| 2828 | 2828 | |
| 2829 | 2829 | /** |
@@ -2835,14 +2835,14 @@ discard block |
||
| 2835 | 2835 | * @return Assert |
| 2836 | 2836 | * @throws AssertionFailedException |
| 2837 | 2837 | */ |
| 2838 | - public function choicesNotEmpty(array $choices, string $message='', string $fieldName='') : Assert |
|
| 2838 | + public function choicesNotEmpty(array $choices, string $message = '', string $fieldName = '') : Assert |
|
| 2839 | 2839 | { |
| 2840 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2840 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2841 | 2841 | { |
| 2842 | 2842 | return $this; |
| 2843 | 2843 | } |
| 2844 | 2844 | $this->notEmpty($message, $fieldName); |
| 2845 | - foreach ( $choices as $choice ) |
|
| 2845 | + foreach ($choices as $choice) |
|
| 2846 | 2846 | { |
| 2847 | 2847 | $this->notEmptyKey($choice, $message, $fieldName); |
| 2848 | 2848 | } |
@@ -2859,14 +2859,14 @@ discard block |
||
| 2859 | 2859 | * @returns Assert |
| 2860 | 2860 | * @throws AssertionFailedException |
| 2861 | 2861 | */ |
| 2862 | - public function methodExists($object, string $message='', string $fieldName='') : Assert |
|
| 2862 | + public function methodExists($object, string $message = '', string $fieldName = '') : Assert |
|
| 2863 | 2863 | { |
| 2864 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2864 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2865 | 2865 | { |
| 2866 | 2866 | return $this; |
| 2867 | 2867 | } |
| 2868 | 2868 | (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $fieldName); |
| 2869 | - if ( !method_exists($object, $this->value) ) |
|
| 2869 | + if ( ! method_exists($object, $this->value)) |
|
| 2870 | 2870 | { |
| 2871 | 2871 | $message = $message ?: $this->overrideError; |
| 2872 | 2872 | $message = sprintf( |
@@ -2888,13 +2888,13 @@ discard block |
||
| 2888 | 2888 | * @return Assert |
| 2889 | 2889 | * @throws AssertionFailedException |
| 2890 | 2890 | */ |
| 2891 | - public function isObject(string $message='', string $fieldName='') : Assert |
|
| 2891 | + public function isObject(string $message = '', string $fieldName = '') : Assert |
|
| 2892 | 2892 | { |
| 2893 | - if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
| 2893 | + if ($this->doAllOrNullOr(__FUNCTION__, func_get_args())) |
|
| 2894 | 2894 | { |
| 2895 | 2895 | return $this; |
| 2896 | 2896 | } |
| 2897 | - if ( !is_object($this->value) ) |
|
| 2897 | + if ( ! is_object($this->value)) |
|
| 2898 | 2898 | { |
| 2899 | 2899 | $message = $message ?: $this->overrideError; |
| 2900 | 2900 | $message = sprintf( |
@@ -2916,33 +2916,33 @@ discard block |
||
| 2916 | 2916 | */ |
| 2917 | 2917 | private function stringify($value) : string |
| 2918 | 2918 | { |
| 2919 | - if ( is_bool($value) ) |
|
| 2919 | + if (is_bool($value)) |
|
| 2920 | 2920 | { |
| 2921 | 2921 | return $value ? '<TRUE>' : '<FALSE>'; |
| 2922 | 2922 | } |
| 2923 | - if ( is_scalar($value) ) |
|
| 2923 | + if (is_scalar($value)) |
|
| 2924 | 2924 | { |
| 2925 | 2925 | $val = (string)$value; |
| 2926 | - if ( strlen($val) > 100 ) |
|
| 2926 | + if (strlen($val) > 100) |
|
| 2927 | 2927 | { |
| 2928 | - $val = substr($val, 0, 97) . '...'; |
|
| 2928 | + $val = substr($val, 0, 97).'...'; |
|
| 2929 | 2929 | } |
| 2930 | 2930 | |
| 2931 | 2931 | return $val; |
| 2932 | 2932 | } |
| 2933 | - if ( is_array($value) ) |
|
| 2933 | + if (is_array($value)) |
|
| 2934 | 2934 | { |
| 2935 | 2935 | return '<ARRAY>'; |
| 2936 | 2936 | } |
| 2937 | - if ( is_object($value) ) |
|
| 2937 | + if (is_object($value)) |
|
| 2938 | 2938 | { |
| 2939 | 2939 | return get_class($value); |
| 2940 | 2940 | } |
| 2941 | - if ( is_resource($value) ) |
|
| 2941 | + if (is_resource($value)) |
|
| 2942 | 2942 | { |
| 2943 | 2943 | return '<RESOURCE>'; |
| 2944 | 2944 | } |
| 2945 | - if ( $value === null ) |
|
| 2945 | + if ($value === null) |
|
| 2946 | 2946 | { |
| 2947 | 2947 | return '<NULL>'; |
| 2948 | 2948 | } |
@@ -158,8 +158,7 @@ discard block |
||
| 158 | 158 | try |
| 159 | 159 | { |
| 160 | 160 | $validator->__invoke(); |
| 161 | - } |
|
| 162 | - catch ( AssertionFailedException $e ) |
|
| 161 | + } catch ( AssertionFailedException $e ) |
|
| 163 | 162 | { |
| 164 | 163 | $errors[$fieldName] = $e->getMessage(); |
| 165 | 164 | } |
@@ -2246,8 +2245,7 @@ discard block |
||
| 2246 | 2245 | ); |
| 2247 | 2246 | |
| 2248 | 2247 | throw $this->createException($message, $this->overrideCode ?: self::INVALID_EMAIL, $fieldName); |
| 2249 | - } |
|
| 2250 | - else |
|
| 2248 | + } else |
|
| 2251 | 2249 | { |
| 2252 | 2250 | $host = substr($this->value, strpos($this->value, '@') + 1); |
| 2253 | 2251 | // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3 |
@@ -2381,8 +2379,7 @@ discard block |
||
| 2381 | 2379 | try |
| 2382 | 2380 | { |
| 2383 | 2381 | $this->regex('/^04[0-9]{8})$/', $message, $fieldName); |
| 2384 | - } |
|
| 2385 | - catch ( AssertionFailedException $e ) |
|
| 2382 | + } catch ( AssertionFailedException $e ) |
|
| 2386 | 2383 | { |
| 2387 | 2384 | $message = $message ?: $this->overrideError; |
| 2388 | 2385 | $message = sprintf( |
@@ -2414,8 +2411,7 @@ discard block |
||
| 2414 | 2411 | try |
| 2415 | 2412 | { |
| 2416 | 2413 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $fieldName); |
| 2417 | - } |
|
| 2418 | - catch (AssertionFailedException $e) |
|
| 2414 | + } catch (AssertionFailedException $e) |
|
| 2419 | 2415 | { |
| 2420 | 2416 | $message = $message ?: $this->overrideError; |
| 2421 | 2417 | $message = sprintf( |
@@ -2721,8 +2717,7 @@ discard block |
||
| 2721 | 2717 | try |
| 2722 | 2718 | { |
| 2723 | 2719 | $this->email($message, $fieldName); |
| 2724 | - } |
|
| 2725 | - catch (AssertionFailedException $e) |
|
| 2720 | + } catch (AssertionFailedException $e) |
|
| 2726 | 2721 | { |
| 2727 | 2722 | $message = $message ?: $this->overrideError; |
| 2728 | 2723 | $message = sprintf( |