@@ 229-237 (lines=9) @@ | ||
226 | } |
|
227 | } |
|
228 | ||
229 | public static function natural($value, $message = '') |
|
230 | { |
|
231 | if (!is_int($value) || $value < 0) { |
|
232 | static::reportInvalidArgument(sprintf( |
|
233 | $message ?: 'Expected a non-negative integer. Got %s', |
|
234 | static::valueToString($value) |
|
235 | )); |
|
236 | } |
|
237 | } |
|
238 | ||
239 | public static function boolean($value, $message = '') |
|
240 | { |
|
@@ 412-420 (lines=9) @@ | ||
409 | } |
|
410 | } |
|
411 | ||
412 | public static function null($value, $message = '') |
|
413 | { |
|
414 | if (null !== $value) { |
|
415 | static::reportInvalidArgument(sprintf( |
|
416 | $message ?: 'Expected null. Got: %s', |
|
417 | static::valueToString($value) |
|
418 | )); |
|
419 | } |
|
420 | } |
|
421 | ||
422 | public static function notNull($value, $message = '') |
|
423 | { |
|
@@ 431-439 (lines=9) @@ | ||
428 | } |
|
429 | } |
|
430 | ||
431 | public static function true($value, $message = '') |
|
432 | { |
|
433 | if (true !== $value) { |
|
434 | static::reportInvalidArgument(sprintf( |
|
435 | $message ?: 'Expected a value to be true. Got: %s', |
|
436 | static::valueToString($value) |
|
437 | )); |
|
438 | } |
|
439 | } |
|
440 | ||
441 | public static function false($value, $message = '') |
|
442 | { |
|
@@ 441-449 (lines=9) @@ | ||
438 | } |
|
439 | } |
|
440 | ||
441 | public static function false($value, $message = '') |
|
442 | { |
|
443 | if (false !== $value) { |
|
444 | static::reportInvalidArgument(sprintf( |
|
445 | $message ?: 'Expected a value to be false. Got: %s', |
|
446 | static::valueToString($value) |
|
447 | )); |
|
448 | } |
|
449 | } |
|
450 | ||
451 | public static function eq($value, $value2, $message = '') |
|
452 | { |
|
@@ 451-460 (lines=10) @@ | ||
448 | } |
|
449 | } |
|
450 | ||
451 | public static function eq($value, $value2, $message = '') |
|
452 | { |
|
453 | if ($value2 != $value) { |
|
454 | static::reportInvalidArgument(sprintf( |
|
455 | $message ?: 'Expected a value equal to %2$s. Got: %s', |
|
456 | static::valueToString($value), |
|
457 | static::valueToString($value2) |
|
458 | )); |
|
459 | } |
|
460 | } |
|
461 | ||
462 | public static function notEq($value, $value2, $message = '') |
|
463 | { |
|
@@ 472-481 (lines=10) @@ | ||
469 | } |
|
470 | } |
|
471 | ||
472 | public static function same($value, $value2, $message = '') |
|
473 | { |
|
474 | if ($value2 !== $value) { |
|
475 | static::reportInvalidArgument(sprintf( |
|
476 | $message ?: 'Expected a value identical to %2$s. Got: %s', |
|
477 | static::valueToString($value), |
|
478 | static::valueToString($value2) |
|
479 | )); |
|
480 | } |
|
481 | } |
|
482 | ||
483 | public static function notSame($value, $value2, $message = '') |
|
484 | { |
|
@@ 493-502 (lines=10) @@ | ||
490 | } |
|
491 | } |
|
492 | ||
493 | public static function greaterThan($value, $limit, $message = '') |
|
494 | { |
|
495 | if ($value <= $limit) { |
|
496 | static::reportInvalidArgument(sprintf( |
|
497 | $message ?: 'Expected a value greater than %2$s. Got: %s', |
|
498 | static::valueToString($value), |
|
499 | static::valueToString($limit) |
|
500 | )); |
|
501 | } |
|
502 | } |
|
503 | ||
504 | public static function greaterThanEq($value, $limit, $message = '') |
|
505 | { |
|
@@ 504-513 (lines=10) @@ | ||
501 | } |
|
502 | } |
|
503 | ||
504 | public static function greaterThanEq($value, $limit, $message = '') |
|
505 | { |
|
506 | if ($value < $limit) { |
|
507 | static::reportInvalidArgument(sprintf( |
|
508 | $message ?: 'Expected a value greater than or equal to %2$s. Got: %s', |
|
509 | static::valueToString($value), |
|
510 | static::valueToString($limit) |
|
511 | )); |
|
512 | } |
|
513 | } |
|
514 | ||
515 | public static function lessThan($value, $limit, $message = '') |
|
516 | { |
|
@@ 515-524 (lines=10) @@ | ||
512 | } |
|
513 | } |
|
514 | ||
515 | public static function lessThan($value, $limit, $message = '') |
|
516 | { |
|
517 | if ($value >= $limit) { |
|
518 | static::reportInvalidArgument(sprintf( |
|
519 | $message ?: 'Expected a value less than %2$s. Got: %s', |
|
520 | static::valueToString($value), |
|
521 | static::valueToString($limit) |
|
522 | )); |
|
523 | } |
|
524 | } |
|
525 | ||
526 | public static function lessThanEq($value, $limit, $message = '') |
|
527 | { |
|
@@ 526-535 (lines=10) @@ | ||
523 | } |
|
524 | } |
|
525 | ||
526 | public static function lessThanEq($value, $limit, $message = '') |
|
527 | { |
|
528 | if ($value > $limit) { |
|
529 | static::reportInvalidArgument(sprintf( |
|
530 | $message ?: 'Expected a value less than or equal to %2$s. Got: %s', |
|
531 | static::valueToString($value), |
|
532 | static::valueToString($limit) |
|
533 | )); |
|
534 | } |
|
535 | } |
|
536 | ||
537 | public static function range($value, $min, $max, $message = '') |
|
538 | { |
|
@@ 582-590 (lines=9) @@ | ||
579 | } |
|
580 | } |
|
581 | ||
582 | public static function notWhitespaceOnly($value, $message = '') |
|
583 | { |
|
584 | if (preg_match('/^\s*$/', $value)) { |
|
585 | static::reportInvalidArgument(sprintf( |
|
586 | $message ?: 'Expected a non-whitespace string. Got: %s', |
|
587 | static::valueToString($value) |
|
588 | )); |
|
589 | } |
|
590 | } |
|
591 | ||
592 | public static function startsWith($value, $prefix, $message = '') |
|
593 | { |
|
@@ 741-750 (lines=10) @@ | ||
738 | } |
|
739 | } |
|
740 | ||
741 | public static function minLength($value, $min, $message = '') |
|
742 | { |
|
743 | if (static::strlen($value) < $min) { |
|
744 | static::reportInvalidArgument(sprintf( |
|
745 | $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', |
|
746 | static::valueToString($value), |
|
747 | $min |
|
748 | )); |
|
749 | } |
|
750 | } |
|
751 | ||
752 | public static function maxLength($value, $max, $message = '') |
|
753 | { |
|
@@ 752-761 (lines=10) @@ | ||
749 | } |
|
750 | } |
|
751 | ||
752 | public static function maxLength($value, $max, $message = '') |
|
753 | { |
|
754 | if (static::strlen($value) > $max) { |
|
755 | static::reportInvalidArgument(sprintf( |
|
756 | $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', |
|
757 | static::valueToString($value), |
|
758 | $max |
|
759 | )); |
|
760 | } |
|
761 | } |
|
762 | ||
763 | public static function lengthBetween($value, $min, $max, $message = '') |
|
764 | { |
|
@@ 813-821 (lines=9) @@ | ||
810 | } |
|
811 | } |
|
812 | ||
813 | public static function readable($value, $message = '') |
|
814 | { |
|
815 | if (!is_readable($value)) { |
|
816 | static::reportInvalidArgument(sprintf( |
|
817 | $message ?: 'The path %s is not readable.', |
|
818 | static::valueToString($value) |
|
819 | )); |
|
820 | } |
|
821 | } |
|
822 | ||
823 | public static function writable($value, $message = '') |
|
824 | { |
|
@@ 823-831 (lines=9) @@ | ||
820 | } |
|
821 | } |
|
822 | ||
823 | public static function writable($value, $message = '') |
|
824 | { |
|
825 | if (!is_writable($value)) { |
|
826 | static::reportInvalidArgument(sprintf( |
|
827 | $message ?: 'The path %s is not writable.', |
|
828 | static::valueToString($value) |
|
829 | )); |
|
830 | } |
|
831 | } |
|
832 | ||
833 | public static function classExists($value, $message = '') |
|
834 | { |
|
@@ 833-841 (lines=9) @@ | ||
830 | } |
|
831 | } |
|
832 | ||
833 | public static function classExists($value, $message = '') |
|
834 | { |
|
835 | if (!class_exists($value)) { |
|
836 | static::reportInvalidArgument(sprintf( |
|
837 | $message ?: 'Expected an existing class name. Got: %s', |
|
838 | static::valueToString($value) |
|
839 | )); |
|
840 | } |
|
841 | } |
|
842 | ||
843 | public static function subclassOf($value, $class, $message = '') |
|
844 | { |
|
@@ 854-862 (lines=9) @@ | ||
851 | } |
|
852 | } |
|
853 | ||
854 | public static function interfaceExists($value, $message = '') |
|
855 | { |
|
856 | if (!interface_exists($value)) { |
|
857 | static::reportInvalidArgument(sprintf( |
|
858 | $message ?: 'Expected an existing interface name. got %s', |
|
859 | static::valueToString($value) |
|
860 | )); |
|
861 | } |
|
862 | } |
|
863 | ||
864 | public static function implementsInterface($value, $interface, $message = '') |
|
865 | { |