@@ 227-235 (lines=9) @@ | ||
224 | } |
|
225 | } |
|
226 | ||
227 | public static function natural($value, $message = '') |
|
228 | { |
|
229 | if (!is_int($value) || $value < 0) { |
|
230 | static::reportInvalidArgument(sprintf( |
|
231 | $message ?: 'Expected a non-negative integer. Got %s', |
|
232 | static::valueToString($value) |
|
233 | )); |
|
234 | } |
|
235 | } |
|
236 | ||
237 | public static function boolean($value, $message = '') |
|
238 | { |
|
@@ 410-418 (lines=9) @@ | ||
407 | } |
|
408 | } |
|
409 | ||
410 | public static function null($value, $message = '') |
|
411 | { |
|
412 | if (null !== $value) { |
|
413 | static::reportInvalidArgument(sprintf( |
|
414 | $message ?: 'Expected null. Got: %s', |
|
415 | static::valueToString($value) |
|
416 | )); |
|
417 | } |
|
418 | } |
|
419 | ||
420 | public static function notNull($value, $message = '') |
|
421 | { |
|
@@ 429-437 (lines=9) @@ | ||
426 | } |
|
427 | } |
|
428 | ||
429 | public static function true($value, $message = '') |
|
430 | { |
|
431 | if (true !== $value) { |
|
432 | static::reportInvalidArgument(sprintf( |
|
433 | $message ?: 'Expected a value to be true. Got: %s', |
|
434 | static::valueToString($value) |
|
435 | )); |
|
436 | } |
|
437 | } |
|
438 | ||
439 | public static function false($value, $message = '') |
|
440 | { |
|
@@ 439-447 (lines=9) @@ | ||
436 | } |
|
437 | } |
|
438 | ||
439 | public static function false($value, $message = '') |
|
440 | { |
|
441 | if (false !== $value) { |
|
442 | static::reportInvalidArgument(sprintf( |
|
443 | $message ?: 'Expected a value to be false. Got: %s', |
|
444 | static::valueToString($value) |
|
445 | )); |
|
446 | } |
|
447 | } |
|
448 | ||
449 | public static function eq($value, $value2, $message = '') |
|
450 | { |
|
@@ 449-458 (lines=10) @@ | ||
446 | } |
|
447 | } |
|
448 | ||
449 | public static function eq($value, $value2, $message = '') |
|
450 | { |
|
451 | if ($value2 != $value) { |
|
452 | static::reportInvalidArgument(sprintf( |
|
453 | $message ?: 'Expected a value equal to %2$s. Got: %s', |
|
454 | static::valueToString($value), |
|
455 | static::valueToString($value2) |
|
456 | )); |
|
457 | } |
|
458 | } |
|
459 | ||
460 | public static function notEq($value, $value2, $message = '') |
|
461 | { |
|
@@ 470-479 (lines=10) @@ | ||
467 | } |
|
468 | } |
|
469 | ||
470 | public static function same($value, $value2, $message = '') |
|
471 | { |
|
472 | if ($value2 !== $value) { |
|
473 | static::reportInvalidArgument(sprintf( |
|
474 | $message ?: 'Expected a value identical to %2$s. Got: %s', |
|
475 | static::valueToString($value), |
|
476 | static::valueToString($value2) |
|
477 | )); |
|
478 | } |
|
479 | } |
|
480 | ||
481 | public static function notSame($value, $value2, $message = '') |
|
482 | { |
|
@@ 491-500 (lines=10) @@ | ||
488 | } |
|
489 | } |
|
490 | ||
491 | public static function greaterThan($value, $limit, $message = '') |
|
492 | { |
|
493 | if ($value <= $limit) { |
|
494 | static::reportInvalidArgument(sprintf( |
|
495 | $message ?: 'Expected a value greater than %2$s. Got: %s', |
|
496 | static::valueToString($value), |
|
497 | static::valueToString($limit) |
|
498 | )); |
|
499 | } |
|
500 | } |
|
501 | ||
502 | public static function greaterThanEq($value, $limit, $message = '') |
|
503 | { |
|
@@ 502-511 (lines=10) @@ | ||
499 | } |
|
500 | } |
|
501 | ||
502 | public static function greaterThanEq($value, $limit, $message = '') |
|
503 | { |
|
504 | if ($value < $limit) { |
|
505 | static::reportInvalidArgument(sprintf( |
|
506 | $message ?: 'Expected a value greater than or equal to %2$s. Got: %s', |
|
507 | static::valueToString($value), |
|
508 | static::valueToString($limit) |
|
509 | )); |
|
510 | } |
|
511 | } |
|
512 | ||
513 | public static function lessThan($value, $limit, $message = '') |
|
514 | { |
|
@@ 513-522 (lines=10) @@ | ||
510 | } |
|
511 | } |
|
512 | ||
513 | public static function lessThan($value, $limit, $message = '') |
|
514 | { |
|
515 | if ($value >= $limit) { |
|
516 | static::reportInvalidArgument(sprintf( |
|
517 | $message ?: 'Expected a value less than %2$s. Got: %s', |
|
518 | static::valueToString($value), |
|
519 | static::valueToString($limit) |
|
520 | )); |
|
521 | } |
|
522 | } |
|
523 | ||
524 | public static function lessThanEq($value, $limit, $message = '') |
|
525 | { |
|
@@ 524-533 (lines=10) @@ | ||
521 | } |
|
522 | } |
|
523 | ||
524 | public static function lessThanEq($value, $limit, $message = '') |
|
525 | { |
|
526 | if ($value > $limit) { |
|
527 | static::reportInvalidArgument(sprintf( |
|
528 | $message ?: 'Expected a value less than or equal to %2$s. Got: %s', |
|
529 | static::valueToString($value), |
|
530 | static::valueToString($limit) |
|
531 | )); |
|
532 | } |
|
533 | } |
|
534 | ||
535 | public static function range($value, $min, $max, $message = '') |
|
536 | { |
|
@@ 580-588 (lines=9) @@ | ||
577 | } |
|
578 | } |
|
579 | ||
580 | public static function notWhitespaceOnly($value, $message = '') |
|
581 | { |
|
582 | if (preg_match('/^\s*$/', $value)) { |
|
583 | static::reportInvalidArgument(sprintf( |
|
584 | $message ?: 'Expected a non-whitespace string. Got: %s', |
|
585 | static::valueToString($value) |
|
586 | )); |
|
587 | } |
|
588 | } |
|
589 | ||
590 | public static function startsWith($value, $prefix, $message = '') |
|
591 | { |
|
@@ 631-639 (lines=9) @@ | ||
628 | } |
|
629 | } |
|
630 | ||
631 | public static function regex($value, $pattern, $message = '') |
|
632 | { |
|
633 | if (!preg_match($pattern, $value)) { |
|
634 | static::reportInvalidArgument(sprintf( |
|
635 | $message ?: 'The value %s does not match the expected pattern.', |
|
636 | static::valueToString($value) |
|
637 | )); |
|
638 | } |
|
639 | } |
|
640 | ||
641 | public static function notRegex($value, $pattern, $message = '') |
|
642 | { |
|
@@ 737-746 (lines=10) @@ | ||
734 | } |
|
735 | } |
|
736 | ||
737 | public static function minLength($value, $min, $message = '') |
|
738 | { |
|
739 | if (static::strlen($value) < $min) { |
|
740 | static::reportInvalidArgument(sprintf( |
|
741 | $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', |
|
742 | static::valueToString($value), |
|
743 | $min |
|
744 | )); |
|
745 | } |
|
746 | } |
|
747 | ||
748 | public static function maxLength($value, $max, $message = '') |
|
749 | { |
|
@@ 748-757 (lines=10) @@ | ||
745 | } |
|
746 | } |
|
747 | ||
748 | public static function maxLength($value, $max, $message = '') |
|
749 | { |
|
750 | if (static::strlen($value) > $max) { |
|
751 | static::reportInvalidArgument(sprintf( |
|
752 | $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', |
|
753 | static::valueToString($value), |
|
754 | $max |
|
755 | )); |
|
756 | } |
|
757 | } |
|
758 | ||
759 | public static function lengthBetween($value, $min, $max, $message = '') |
|
760 | { |
|
@@ 809-817 (lines=9) @@ | ||
806 | } |
|
807 | } |
|
808 | ||
809 | public static function readable($value, $message = '') |
|
810 | { |
|
811 | if (!is_readable($value)) { |
|
812 | static::reportInvalidArgument(sprintf( |
|
813 | $message ?: 'The path %s is not readable.', |
|
814 | static::valueToString($value) |
|
815 | )); |
|
816 | } |
|
817 | } |
|
818 | ||
819 | public static function writable($value, $message = '') |
|
820 | { |
|
@@ 819-827 (lines=9) @@ | ||
816 | } |
|
817 | } |
|
818 | ||
819 | public static function writable($value, $message = '') |
|
820 | { |
|
821 | if (!is_writable($value)) { |
|
822 | static::reportInvalidArgument(sprintf( |
|
823 | $message ?: 'The path %s is not writable.', |
|
824 | static::valueToString($value) |
|
825 | )); |
|
826 | } |
|
827 | } |
|
828 | ||
829 | public static function classExists($value, $message = '') |
|
830 | { |
|
@@ 829-837 (lines=9) @@ | ||
826 | } |
|
827 | } |
|
828 | ||
829 | public static function classExists($value, $message = '') |
|
830 | { |
|
831 | if (!class_exists($value)) { |
|
832 | static::reportInvalidArgument(sprintf( |
|
833 | $message ?: 'Expected an existing class name. Got: %s', |
|
834 | static::valueToString($value) |
|
835 | )); |
|
836 | } |
|
837 | } |
|
838 | ||
839 | public static function subclassOf($value, $class, $message = '') |
|
840 | { |