| @@ 220-228 (lines=9) @@ | ||
| 217 | } | |
| 218 | } | |
| 219 | ||
| 220 | public static function natural($value, $message = '') | |
| 221 |     { | |
| 222 |         if (!is_int($value) || $value < 0) { | |
| 223 | static::reportInvalidArgument(sprintf( | |
| 224 | $message ?: 'Expected a non-negative integer. Got %s', | |
| 225 | static::valueToString($value) | |
| 226 | )); | |
| 227 | } | |
| 228 | } | |
| 229 | ||
| 230 | public static function boolean($value, $message = '') | |
| 231 |     { | |
| @@ 378-386 (lines=9) @@ | ||
| 375 | } | |
| 376 | } | |
| 377 | ||
| 378 | public static function null($value, $message = '') | |
| 379 |     { | |
| 380 |         if (null !== $value) { | |
| 381 | static::reportInvalidArgument(sprintf( | |
| 382 | $message ?: 'Expected null. Got: %s', | |
| 383 | static::valueToString($value) | |
| 384 | )); | |
| 385 | } | |
| 386 | } | |
| 387 | ||
| 388 | public static function notNull($value, $message = '') | |
| 389 |     { | |
| @@ 397-405 (lines=9) @@ | ||
| 394 | } | |
| 395 | } | |
| 396 | ||
| 397 | public static function true($value, $message = '') | |
| 398 |     { | |
| 399 |         if (true !== $value) { | |
| 400 | static::reportInvalidArgument(sprintf( | |
| 401 | $message ?: 'Expected a value to be true. Got: %s', | |
| 402 | static::valueToString($value) | |
| 403 | )); | |
| 404 | } | |
| 405 | } | |
| 406 | ||
| 407 | public static function false($value, $message = '') | |
| 408 |     { | |
| @@ 407-415 (lines=9) @@ | ||
| 404 | } | |
| 405 | } | |
| 406 | ||
| 407 | public static function false($value, $message = '') | |
| 408 |     { | |
| 409 |         if (false !== $value) { | |
| 410 | static::reportInvalidArgument(sprintf( | |
| 411 | $message ?: 'Expected a value to be false. Got: %s', | |
| 412 | static::valueToString($value) | |
| 413 | )); | |
| 414 | } | |
| 415 | } | |
| 416 | ||
| 417 | public static function eq($value, $value2, $message = '') | |
| 418 |     { | |
| @@ 417-426 (lines=10) @@ | ||
| 414 | } | |
| 415 | } | |
| 416 | ||
| 417 | public static function eq($value, $value2, $message = '') | |
| 418 |     { | |
| 419 |         if ($value2 != $value) { | |
| 420 | static::reportInvalidArgument(sprintf( | |
| 421 | $message ?: 'Expected a value equal to %2$s. Got: %s', | |
| 422 | static::valueToString($value), | |
| 423 | static::valueToString($value2) | |
| 424 | )); | |
| 425 | } | |
| 426 | } | |
| 427 | ||
| 428 | public static function notEq($value, $value2, $message = '') | |
| 429 |     { | |
| @@ 438-447 (lines=10) @@ | ||
| 435 | } | |
| 436 | } | |
| 437 | ||
| 438 | public static function same($value, $value2, $message = '') | |
| 439 |     { | |
| 440 |         if ($value2 !== $value) { | |
| 441 | static::reportInvalidArgument(sprintf( | |
| 442 | $message ?: 'Expected a value identical to %2$s. Got: %s', | |
| 443 | static::valueToString($value), | |
| 444 | static::valueToString($value2) | |
| 445 | )); | |
| 446 | } | |
| 447 | } | |
| 448 | ||
| 449 | public static function notSame($value, $value2, $message = '') | |
| 450 |     { | |
| @@ 459-468 (lines=10) @@ | ||
| 456 | } | |
| 457 | } | |
| 458 | ||
| 459 | public static function greaterThan($value, $limit, $message = '') | |
| 460 |     { | |
| 461 |         if ($value <= $limit) { | |
| 462 | static::reportInvalidArgument(sprintf( | |
| 463 | $message ?: 'Expected a value greater than %2$s. Got: %s', | |
| 464 | static::valueToString($value), | |
| 465 | static::valueToString($limit) | |
| 466 | )); | |
| 467 | } | |
| 468 | } | |
| 469 | ||
| 470 | public static function greaterThanEq($value, $limit, $message = '') | |
| 471 |     { | |
| @@ 470-479 (lines=10) @@ | ||
| 467 | } | |
| 468 | } | |
| 469 | ||
| 470 | public static function greaterThanEq($value, $limit, $message = '') | |
| 471 |     { | |
| 472 |         if ($value < $limit) { | |
| 473 | static::reportInvalidArgument(sprintf( | |
| 474 | $message ?: 'Expected a value greater than or equal to %2$s. Got: %s', | |
| 475 | static::valueToString($value), | |
| 476 | static::valueToString($limit) | |
| 477 | )); | |
| 478 | } | |
| 479 | } | |
| 480 | ||
| 481 | public static function lessThan($value, $limit, $message = '') | |
| 482 |     { | |
| @@ 481-490 (lines=10) @@ | ||
| 478 | } | |
| 479 | } | |
| 480 | ||
| 481 | public static function lessThan($value, $limit, $message = '') | |
| 482 |     { | |
| 483 |         if ($value >= $limit) { | |
| 484 | static::reportInvalidArgument(sprintf( | |
| 485 | $message ?: 'Expected a value less than %2$s. Got: %s', | |
| 486 | static::valueToString($value), | |
| 487 | static::valueToString($limit) | |
| 488 | )); | |
| 489 | } | |
| 490 | } | |
| 491 | ||
| 492 | public static function lessThanEq($value, $limit, $message = '') | |
| 493 |     { | |
| @@ 492-501 (lines=10) @@ | ||
| 489 | } | |
| 490 | } | |
| 491 | ||
| 492 | public static function lessThanEq($value, $limit, $message = '') | |
| 493 |     { | |
| 494 |         if ($value > $limit) { | |
| 495 | static::reportInvalidArgument(sprintf( | |
| 496 | $message ?: 'Expected a value less than or equal to %2$s. Got: %s', | |
| 497 | static::valueToString($value), | |
| 498 | static::valueToString($limit) | |
| 499 | )); | |
| 500 | } | |
| 501 | } | |
| 502 | ||
| 503 | public static function range($value, $min, $max, $message = '') | |
| 504 |     { | |
| @@ 548-556 (lines=9) @@ | ||
| 545 | } | |
| 546 | } | |
| 547 | ||
| 548 | public static function notWhitespaceOnly($value, $message = '') | |
| 549 |     { | |
| 550 |         if (preg_match('/^\s*$/', $value)) { | |
| 551 | static::reportInvalidArgument(sprintf( | |
| 552 | $message ?: 'Expected a non-whitespace string. Got: %s', | |
| 553 | static::valueToString($value) | |
| 554 | )); | |
| 555 | } | |
| 556 | } | |
| 557 | ||
| 558 | public static function startsWith($value, $prefix, $message = '') | |
| 559 |     { | |
| @@ 599-607 (lines=9) @@ | ||
| 596 | } | |
| 597 | } | |
| 598 | ||
| 599 | public static function regex($value, $pattern, $message = '') | |
| 600 |     { | |
| 601 |         if (!preg_match($pattern, $value)) { | |
| 602 | static::reportInvalidArgument(sprintf( | |
| 603 | $message ?: 'The value %s does not match the expected pattern.', | |
| 604 | static::valueToString($value) | |
| 605 | )); | |
| 606 | } | |
| 607 | } | |
| 608 | ||
| 609 | public static function alpha($value, $message = '') | |
| 610 |     { | |
| @@ 695-704 (lines=10) @@ | ||
| 692 | } | |
| 693 | } | |
| 694 | ||
| 695 | public static function minLength($value, $min, $message = '') | |
| 696 |     { | |
| 697 |         if (static::strlen($value) < $min) { | |
| 698 | static::reportInvalidArgument(sprintf( | |
| 699 | $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', | |
| 700 | static::valueToString($value), | |
| 701 | $min | |
| 702 | )); | |
| 703 | } | |
| 704 | } | |
| 705 | ||
| 706 | public static function maxLength($value, $max, $message = '') | |
| 707 |     { | |
| @@ 706-715 (lines=10) @@ | ||
| 703 | } | |
| 704 | } | |
| 705 | ||
| 706 | public static function maxLength($value, $max, $message = '') | |
| 707 |     { | |
| 708 |         if (static::strlen($value) > $max) { | |
| 709 | static::reportInvalidArgument(sprintf( | |
| 710 | $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', | |
| 711 | static::valueToString($value), | |
| 712 | $max | |
| 713 | )); | |
| 714 | } | |
| 715 | } | |
| 716 | ||
| 717 | public static function lengthBetween($value, $min, $max, $message = '') | |
| 718 |     { | |
| @@ 767-775 (lines=9) @@ | ||
| 764 | } | |
| 765 | } | |
| 766 | ||
| 767 | public static function readable($value, $message = '') | |
| 768 |     { | |
| 769 |         if (!is_readable($value)) { | |
| 770 | static::reportInvalidArgument(sprintf( | |
| 771 | $message ?: 'The path %s is not readable.', | |
| 772 | static::valueToString($value) | |
| 773 | )); | |
| 774 | } | |
| 775 | } | |
| 776 | ||
| 777 | public static function writable($value, $message = '') | |
| 778 |     { | |
| @@ 777-785 (lines=9) @@ | ||
| 774 | } | |
| 775 | } | |
| 776 | ||
| 777 | public static function writable($value, $message = '') | |
| 778 |     { | |
| 779 |         if (!is_writable($value)) { | |
| 780 | static::reportInvalidArgument(sprintf( | |
| 781 | $message ?: 'The path %s is not writable.', | |
| 782 | static::valueToString($value) | |
| 783 | )); | |
| 784 | } | |
| 785 | } | |
| 786 | ||
| 787 | public static function classExists($value, $message = '') | |
| 788 |     { | |
| @@ 787-795 (lines=9) @@ | ||
| 784 | } | |
| 785 | } | |
| 786 | ||
| 787 | public static function classExists($value, $message = '') | |
| 788 |     { | |
| 789 |         if (!class_exists($value)) { | |
| 790 | static::reportInvalidArgument(sprintf( | |
| 791 | $message ?: 'Expected an existing class name. Got: %s', | |
| 792 | static::valueToString($value) | |
| 793 | )); | |
| 794 | } | |
| 795 | } | |
| 796 | ||
| 797 | public static function subclassOf($value, $class, $message = '') | |
| 798 |     { | |