@@ 225-233 (lines=9) @@ | ||
222 | } |
|
223 | } |
|
224 | ||
225 | public static function natural($value, $message = '') |
|
226 | { |
|
227 | if (!is_int($value) || $value < 0) { |
|
228 | static::reportInvalidArgument(sprintf( |
|
229 | $message ?: 'Expected a non-negative integer. Got %s', |
|
230 | static::valueToString($value) |
|
231 | )); |
|
232 | } |
|
233 | } |
|
234 | ||
235 | public static function boolean($value, $message = '') |
|
236 | { |
|
@@ 408-416 (lines=9) @@ | ||
405 | } |
|
406 | } |
|
407 | ||
408 | public static function null($value, $message = '') |
|
409 | { |
|
410 | if (null !== $value) { |
|
411 | static::reportInvalidArgument(sprintf( |
|
412 | $message ?: 'Expected null. Got: %s', |
|
413 | static::valueToString($value) |
|
414 | )); |
|
415 | } |
|
416 | } |
|
417 | ||
418 | public static function notNull($value, $message = '') |
|
419 | { |
|
@@ 427-435 (lines=9) @@ | ||
424 | } |
|
425 | } |
|
426 | ||
427 | public static function true($value, $message = '') |
|
428 | { |
|
429 | if (true !== $value) { |
|
430 | static::reportInvalidArgument(sprintf( |
|
431 | $message ?: 'Expected a value to be true. Got: %s', |
|
432 | static::valueToString($value) |
|
433 | )); |
|
434 | } |
|
435 | } |
|
436 | ||
437 | public static function false($value, $message = '') |
|
438 | { |
|
@@ 437-445 (lines=9) @@ | ||
434 | } |
|
435 | } |
|
436 | ||
437 | public static function false($value, $message = '') |
|
438 | { |
|
439 | if (false !== $value) { |
|
440 | static::reportInvalidArgument(sprintf( |
|
441 | $message ?: 'Expected a value to be false. Got: %s', |
|
442 | static::valueToString($value) |
|
443 | )); |
|
444 | } |
|
445 | } |
|
446 | ||
447 | public static function eq($value, $value2, $message = '') |
|
448 | { |
|
@@ 447-456 (lines=10) @@ | ||
444 | } |
|
445 | } |
|
446 | ||
447 | public static function eq($value, $value2, $message = '') |
|
448 | { |
|
449 | if ($value2 != $value) { |
|
450 | static::reportInvalidArgument(sprintf( |
|
451 | $message ?: 'Expected a value equal to %2$s. Got: %s', |
|
452 | static::valueToString($value), |
|
453 | static::valueToString($value2) |
|
454 | )); |
|
455 | } |
|
456 | } |
|
457 | ||
458 | public static function notEq($value, $value2, $message = '') |
|
459 | { |
|
@@ 468-477 (lines=10) @@ | ||
465 | } |
|
466 | } |
|
467 | ||
468 | public static function same($value, $value2, $message = '') |
|
469 | { |
|
470 | if ($value2 !== $value) { |
|
471 | static::reportInvalidArgument(sprintf( |
|
472 | $message ?: 'Expected a value identical to %2$s. Got: %s', |
|
473 | static::valueToString($value), |
|
474 | static::valueToString($value2) |
|
475 | )); |
|
476 | } |
|
477 | } |
|
478 | ||
479 | public static function notSame($value, $value2, $message = '') |
|
480 | { |
|
@@ 489-498 (lines=10) @@ | ||
486 | } |
|
487 | } |
|
488 | ||
489 | public static function greaterThan($value, $limit, $message = '') |
|
490 | { |
|
491 | if ($value <= $limit) { |
|
492 | static::reportInvalidArgument(sprintf( |
|
493 | $message ?: 'Expected a value greater than %2$s. Got: %s', |
|
494 | static::valueToString($value), |
|
495 | static::valueToString($limit) |
|
496 | )); |
|
497 | } |
|
498 | } |
|
499 | ||
500 | public static function greaterThanEq($value, $limit, $message = '') |
|
501 | { |
|
@@ 500-509 (lines=10) @@ | ||
497 | } |
|
498 | } |
|
499 | ||
500 | public static function greaterThanEq($value, $limit, $message = '') |
|
501 | { |
|
502 | if ($value < $limit) { |
|
503 | static::reportInvalidArgument(sprintf( |
|
504 | $message ?: 'Expected a value greater than or equal to %2$s. Got: %s', |
|
505 | static::valueToString($value), |
|
506 | static::valueToString($limit) |
|
507 | )); |
|
508 | } |
|
509 | } |
|
510 | ||
511 | public static function lessThan($value, $limit, $message = '') |
|
512 | { |
|
@@ 511-520 (lines=10) @@ | ||
508 | } |
|
509 | } |
|
510 | ||
511 | public static function lessThan($value, $limit, $message = '') |
|
512 | { |
|
513 | if ($value >= $limit) { |
|
514 | static::reportInvalidArgument(sprintf( |
|
515 | $message ?: 'Expected a value less than %2$s. Got: %s', |
|
516 | static::valueToString($value), |
|
517 | static::valueToString($limit) |
|
518 | )); |
|
519 | } |
|
520 | } |
|
521 | ||
522 | public static function lessThanEq($value, $limit, $message = '') |
|
523 | { |
|
@@ 522-531 (lines=10) @@ | ||
519 | } |
|
520 | } |
|
521 | ||
522 | public static function lessThanEq($value, $limit, $message = '') |
|
523 | { |
|
524 | if ($value > $limit) { |
|
525 | static::reportInvalidArgument(sprintf( |
|
526 | $message ?: 'Expected a value less than or equal to %2$s. Got: %s', |
|
527 | static::valueToString($value), |
|
528 | static::valueToString($limit) |
|
529 | )); |
|
530 | } |
|
531 | } |
|
532 | ||
533 | public static function range($value, $min, $max, $message = '') |
|
534 | { |
|
@@ 578-586 (lines=9) @@ | ||
575 | } |
|
576 | } |
|
577 | ||
578 | public static function notWhitespaceOnly($value, $message = '') |
|
579 | { |
|
580 | if (preg_match('/^\s*$/', $value)) { |
|
581 | static::reportInvalidArgument(sprintf( |
|
582 | $message ?: 'Expected a non-whitespace string. Got: %s', |
|
583 | static::valueToString($value) |
|
584 | )); |
|
585 | } |
|
586 | } |
|
587 | ||
588 | public static function startsWith($value, $prefix, $message = '') |
|
589 | { |
|
@@ 629-637 (lines=9) @@ | ||
626 | } |
|
627 | } |
|
628 | ||
629 | public static function regex($value, $pattern, $message = '') |
|
630 | { |
|
631 | if (!preg_match($pattern, $value)) { |
|
632 | static::reportInvalidArgument(sprintf( |
|
633 | $message ?: 'The value %s does not match the expected pattern.', |
|
634 | static::valueToString($value) |
|
635 | )); |
|
636 | } |
|
637 | } |
|
638 | ||
639 | public static function alpha($value, $message = '') |
|
640 | { |
|
@@ 725-734 (lines=10) @@ | ||
722 | } |
|
723 | } |
|
724 | ||
725 | public static function minLength($value, $min, $message = '') |
|
726 | { |
|
727 | if (static::strlen($value) < $min) { |
|
728 | static::reportInvalidArgument(sprintf( |
|
729 | $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', |
|
730 | static::valueToString($value), |
|
731 | $min |
|
732 | )); |
|
733 | } |
|
734 | } |
|
735 | ||
736 | public static function maxLength($value, $max, $message = '') |
|
737 | { |
|
@@ 736-745 (lines=10) @@ | ||
733 | } |
|
734 | } |
|
735 | ||
736 | public static function maxLength($value, $max, $message = '') |
|
737 | { |
|
738 | if (static::strlen($value) > $max) { |
|
739 | static::reportInvalidArgument(sprintf( |
|
740 | $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', |
|
741 | static::valueToString($value), |
|
742 | $max |
|
743 | )); |
|
744 | } |
|
745 | } |
|
746 | ||
747 | public static function lengthBetween($value, $min, $max, $message = '') |
|
748 | { |
|
@@ 797-805 (lines=9) @@ | ||
794 | } |
|
795 | } |
|
796 | ||
797 | public static function readable($value, $message = '') |
|
798 | { |
|
799 | if (!is_readable($value)) { |
|
800 | static::reportInvalidArgument(sprintf( |
|
801 | $message ?: 'The path %s is not readable.', |
|
802 | static::valueToString($value) |
|
803 | )); |
|
804 | } |
|
805 | } |
|
806 | ||
807 | public static function writable($value, $message = '') |
|
808 | { |
|
@@ 807-815 (lines=9) @@ | ||
804 | } |
|
805 | } |
|
806 | ||
807 | public static function writable($value, $message = '') |
|
808 | { |
|
809 | if (!is_writable($value)) { |
|
810 | static::reportInvalidArgument(sprintf( |
|
811 | $message ?: 'The path %s is not writable.', |
|
812 | static::valueToString($value) |
|
813 | )); |
|
814 | } |
|
815 | } |
|
816 | ||
817 | public static function classExists($value, $message = '') |
|
818 | { |
|
@@ 817-825 (lines=9) @@ | ||
814 | } |
|
815 | } |
|
816 | ||
817 | public static function classExists($value, $message = '') |
|
818 | { |
|
819 | if (!class_exists($value)) { |
|
820 | static::reportInvalidArgument(sprintf( |
|
821 | $message ?: 'Expected an existing class name. Got: %s', |
|
822 | static::valueToString($value) |
|
823 | )); |
|
824 | } |
|
825 | } |
|
826 | ||
827 | public static function subclassOf($value, $class, $message = '') |
|
828 | { |