| @@ 223-231 (lines=9) @@ | ||
| 220 | } |
|
| 221 | } |
|
| 222 | ||
| 223 | public static function natural($value, $message = '') |
|
| 224 | { |
|
| 225 | if (!is_int($value) || $value < 0) { |
|
| 226 | static::reportInvalidArgument(sprintf( |
|
| 227 | $message ?: 'Expected a non-negative integer. Got %s', |
|
| 228 | static::valueToString($value) |
|
| 229 | )); |
|
| 230 | } |
|
| 231 | } |
|
| 232 | ||
| 233 | public static function boolean($value, $message = '') |
|
| 234 | { |
|
| @@ 391-399 (lines=9) @@ | ||
| 388 | } |
|
| 389 | } |
|
| 390 | ||
| 391 | public static function null($value, $message = '') |
|
| 392 | { |
|
| 393 | if (null !== $value) { |
|
| 394 | static::reportInvalidArgument(sprintf( |
|
| 395 | $message ?: 'Expected null. Got: %s', |
|
| 396 | static::valueToString($value) |
|
| 397 | )); |
|
| 398 | } |
|
| 399 | } |
|
| 400 | ||
| 401 | public static function notNull($value, $message = '') |
|
| 402 | { |
|
| @@ 410-418 (lines=9) @@ | ||
| 407 | } |
|
| 408 | } |
|
| 409 | ||
| 410 | public static function true($value, $message = '') |
|
| 411 | { |
|
| 412 | if (true !== $value) { |
|
| 413 | static::reportInvalidArgument(sprintf( |
|
| 414 | $message ?: 'Expected a value to be true. Got: %s', |
|
| 415 | static::valueToString($value) |
|
| 416 | )); |
|
| 417 | } |
|
| 418 | } |
|
| 419 | ||
| 420 | public static function false($value, $message = '') |
|
| 421 | { |
|
| @@ 420-428 (lines=9) @@ | ||
| 417 | } |
|
| 418 | } |
|
| 419 | ||
| 420 | public static function false($value, $message = '') |
|
| 421 | { |
|
| 422 | if (false !== $value) { |
|
| 423 | static::reportInvalidArgument(sprintf( |
|
| 424 | $message ?: 'Expected a value to be false. Got: %s', |
|
| 425 | static::valueToString($value) |
|
| 426 | )); |
|
| 427 | } |
|
| 428 | } |
|
| 429 | ||
| 430 | public static function eq($value, $value2, $message = '') |
|
| 431 | { |
|
| @@ 430-439 (lines=10) @@ | ||
| 427 | } |
|
| 428 | } |
|
| 429 | ||
| 430 | public static function eq($value, $value2, $message = '') |
|
| 431 | { |
|
| 432 | if ($value2 != $value) { |
|
| 433 | static::reportInvalidArgument(sprintf( |
|
| 434 | $message ?: 'Expected a value equal to %2$s. Got: %s', |
|
| 435 | static::valueToString($value), |
|
| 436 | static::valueToString($value2) |
|
| 437 | )); |
|
| 438 | } |
|
| 439 | } |
|
| 440 | ||
| 441 | public static function notEq($value, $value2, $message = '') |
|
| 442 | { |
|
| @@ 451-460 (lines=10) @@ | ||
| 448 | } |
|
| 449 | } |
|
| 450 | ||
| 451 | public static function same($value, $value2, $message = '') |
|
| 452 | { |
|
| 453 | if ($value2 !== $value) { |
|
| 454 | static::reportInvalidArgument(sprintf( |
|
| 455 | $message ?: 'Expected a value identical to %2$s. Got: %s', |
|
| 456 | static::valueToString($value), |
|
| 457 | static::valueToString($value2) |
|
| 458 | )); |
|
| 459 | } |
|
| 460 | } |
|
| 461 | ||
| 462 | public static function notSame($value, $value2, $message = '') |
|
| 463 | { |
|
| @@ 472-481 (lines=10) @@ | ||
| 469 | } |
|
| 470 | } |
|
| 471 | ||
| 472 | public static function greaterThan($value, $limit, $message = '') |
|
| 473 | { |
|
| 474 | if ($value <= $limit) { |
|
| 475 | static::reportInvalidArgument(sprintf( |
|
| 476 | $message ?: 'Expected a value greater than %2$s. Got: %s', |
|
| 477 | static::valueToString($value), |
|
| 478 | static::valueToString($limit) |
|
| 479 | )); |
|
| 480 | } |
|
| 481 | } |
|
| 482 | ||
| 483 | public static function greaterThanEq($value, $limit, $message = '') |
|
| 484 | { |
|
| @@ 483-492 (lines=10) @@ | ||
| 480 | } |
|
| 481 | } |
|
| 482 | ||
| 483 | public static function greaterThanEq($value, $limit, $message = '') |
|
| 484 | { |
|
| 485 | if ($value < $limit) { |
|
| 486 | static::reportInvalidArgument(sprintf( |
|
| 487 | $message ?: 'Expected a value greater than or equal to %2$s. Got: %s', |
|
| 488 | static::valueToString($value), |
|
| 489 | static::valueToString($limit) |
|
| 490 | )); |
|
| 491 | } |
|
| 492 | } |
|
| 493 | ||
| 494 | public static function lessThan($value, $limit, $message = '') |
|
| 495 | { |
|
| @@ 494-503 (lines=10) @@ | ||
| 491 | } |
|
| 492 | } |
|
| 493 | ||
| 494 | public static function lessThan($value, $limit, $message = '') |
|
| 495 | { |
|
| 496 | if ($value >= $limit) { |
|
| 497 | static::reportInvalidArgument(sprintf( |
|
| 498 | $message ?: 'Expected a value less than %2$s. Got: %s', |
|
| 499 | static::valueToString($value), |
|
| 500 | static::valueToString($limit) |
|
| 501 | )); |
|
| 502 | } |
|
| 503 | } |
|
| 504 | ||
| 505 | public static function lessThanEq($value, $limit, $message = '') |
|
| 506 | { |
|
| @@ 505-514 (lines=10) @@ | ||
| 502 | } |
|
| 503 | } |
|
| 504 | ||
| 505 | public static function lessThanEq($value, $limit, $message = '') |
|
| 506 | { |
|
| 507 | if ($value > $limit) { |
|
| 508 | static::reportInvalidArgument(sprintf( |
|
| 509 | $message ?: 'Expected a value less than or equal to %2$s. Got: %s', |
|
| 510 | static::valueToString($value), |
|
| 511 | static::valueToString($limit) |
|
| 512 | )); |
|
| 513 | } |
|
| 514 | } |
|
| 515 | ||
| 516 | public static function range($value, $min, $max, $message = '') |
|
| 517 | { |
|
| @@ 561-569 (lines=9) @@ | ||
| 558 | } |
|
| 559 | } |
|
| 560 | ||
| 561 | public static function notWhitespaceOnly($value, $message = '') |
|
| 562 | { |
|
| 563 | if (preg_match('/^\s*$/', $value)) { |
|
| 564 | static::reportInvalidArgument(sprintf( |
|
| 565 | $message ?: 'Expected a non-whitespace string. Got: %s', |
|
| 566 | static::valueToString($value) |
|
| 567 | )); |
|
| 568 | } |
|
| 569 | } |
|
| 570 | ||
| 571 | public static function startsWith($value, $prefix, $message = '') |
|
| 572 | { |
|
| @@ 612-620 (lines=9) @@ | ||
| 609 | } |
|
| 610 | } |
|
| 611 | ||
| 612 | public static function regex($value, $pattern, $message = '') |
|
| 613 | { |
|
| 614 | if (!preg_match($pattern, $value)) { |
|
| 615 | static::reportInvalidArgument(sprintf( |
|
| 616 | $message ?: 'The value %s does not match the expected pattern.', |
|
| 617 | static::valueToString($value) |
|
| 618 | )); |
|
| 619 | } |
|
| 620 | } |
|
| 621 | ||
| 622 | public static function alpha($value, $message = '') |
|
| 623 | { |
|
| @@ 708-717 (lines=10) @@ | ||
| 705 | } |
|
| 706 | } |
|
| 707 | ||
| 708 | public static function minLength($value, $min, $message = '') |
|
| 709 | { |
|
| 710 | if (static::strlen($value) < $min) { |
|
| 711 | static::reportInvalidArgument(sprintf( |
|
| 712 | $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', |
|
| 713 | static::valueToString($value), |
|
| 714 | $min |
|
| 715 | )); |
|
| 716 | } |
|
| 717 | } |
|
| 718 | ||
| 719 | public static function maxLength($value, $max, $message = '') |
|
| 720 | { |
|
| @@ 719-728 (lines=10) @@ | ||
| 716 | } |
|
| 717 | } |
|
| 718 | ||
| 719 | public static function maxLength($value, $max, $message = '') |
|
| 720 | { |
|
| 721 | if (static::strlen($value) > $max) { |
|
| 722 | static::reportInvalidArgument(sprintf( |
|
| 723 | $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', |
|
| 724 | static::valueToString($value), |
|
| 725 | $max |
|
| 726 | )); |
|
| 727 | } |
|
| 728 | } |
|
| 729 | ||
| 730 | public static function lengthBetween($value, $min, $max, $message = '') |
|
| 731 | { |
|
| @@ 780-788 (lines=9) @@ | ||
| 777 | } |
|
| 778 | } |
|
| 779 | ||
| 780 | public static function readable($value, $message = '') |
|
| 781 | { |
|
| 782 | if (!is_readable($value)) { |
|
| 783 | static::reportInvalidArgument(sprintf( |
|
| 784 | $message ?: 'The path %s is not readable.', |
|
| 785 | static::valueToString($value) |
|
| 786 | )); |
|
| 787 | } |
|
| 788 | } |
|
| 789 | ||
| 790 | public static function writable($value, $message = '') |
|
| 791 | { |
|
| @@ 790-798 (lines=9) @@ | ||
| 787 | } |
|
| 788 | } |
|
| 789 | ||
| 790 | public static function writable($value, $message = '') |
|
| 791 | { |
|
| 792 | if (!is_writable($value)) { |
|
| 793 | static::reportInvalidArgument(sprintf( |
|
| 794 | $message ?: 'The path %s is not writable.', |
|
| 795 | static::valueToString($value) |
|
| 796 | )); |
|
| 797 | } |
|
| 798 | } |
|
| 799 | ||
| 800 | public static function classExists($value, $message = '') |
|
| 801 | { |
|
| @@ 800-808 (lines=9) @@ | ||
| 797 | } |
|
| 798 | } |
|
| 799 | ||
| 800 | public static function classExists($value, $message = '') |
|
| 801 | { |
|
| 802 | if (!class_exists($value)) { |
|
| 803 | static::reportInvalidArgument(sprintf( |
|
| 804 | $message ?: 'Expected an existing class name. Got: %s', |
|
| 805 | static::valueToString($value) |
|
| 806 | )); |
|
| 807 | } |
|
| 808 | } |
|
| 809 | ||
| 810 | public static function subclassOf($value, $class, $message = '') |
|
| 811 | { |
|