@@ 218-226 (lines=9) @@ | ||
215 | } |
|
216 | } |
|
217 | ||
218 | public static function natural($value, $message = '') |
|
219 | { |
|
220 | if (!is_int($value) || $value < 0) { |
|
221 | static::reportInvalidArgument(sprintf( |
|
222 | $message ?: 'Expected a non-negative integer. Got %s', |
|
223 | static::valueToString($value) |
|
224 | )); |
|
225 | } |
|
226 | } |
|
227 | ||
228 | public static function boolean($value, $message = '') |
|
229 | { |
|
@@ 376-384 (lines=9) @@ | ||
373 | } |
|
374 | } |
|
375 | ||
376 | public static function null($value, $message = '') |
|
377 | { |
|
378 | if (null !== $value) { |
|
379 | static::reportInvalidArgument(sprintf( |
|
380 | $message ?: 'Expected null. Got: %s', |
|
381 | static::valueToString($value) |
|
382 | )); |
|
383 | } |
|
384 | } |
|
385 | ||
386 | public static function notNull($value, $message = '') |
|
387 | { |
|
@@ 395-403 (lines=9) @@ | ||
392 | } |
|
393 | } |
|
394 | ||
395 | public static function true($value, $message = '') |
|
396 | { |
|
397 | if (true !== $value) { |
|
398 | static::reportInvalidArgument(sprintf( |
|
399 | $message ?: 'Expected a value to be true. Got: %s', |
|
400 | static::valueToString($value) |
|
401 | )); |
|
402 | } |
|
403 | } |
|
404 | ||
405 | public static function false($value, $message = '') |
|
406 | { |
|
@@ 405-413 (lines=9) @@ | ||
402 | } |
|
403 | } |
|
404 | ||
405 | public static function false($value, $message = '') |
|
406 | { |
|
407 | if (false !== $value) { |
|
408 | static::reportInvalidArgument(sprintf( |
|
409 | $message ?: 'Expected a value to be false. Got: %s', |
|
410 | static::valueToString($value) |
|
411 | )); |
|
412 | } |
|
413 | } |
|
414 | ||
415 | public static function eq($value, $value2, $message = '') |
|
416 | { |
|
@@ 415-424 (lines=10) @@ | ||
412 | } |
|
413 | } |
|
414 | ||
415 | public static function eq($value, $value2, $message = '') |
|
416 | { |
|
417 | if ($value2 != $value) { |
|
418 | static::reportInvalidArgument(sprintf( |
|
419 | $message ?: 'Expected a value equal to %2$s. Got: %s', |
|
420 | static::valueToString($value), |
|
421 | static::valueToString($value2) |
|
422 | )); |
|
423 | } |
|
424 | } |
|
425 | ||
426 | public static function notEq($value, $value2, $message = '') |
|
427 | { |
|
@@ 436-445 (lines=10) @@ | ||
433 | } |
|
434 | } |
|
435 | ||
436 | public static function same($value, $value2, $message = '') |
|
437 | { |
|
438 | if ($value2 !== $value) { |
|
439 | static::reportInvalidArgument(sprintf( |
|
440 | $message ?: 'Expected a value identical to %2$s. Got: %s', |
|
441 | static::valueToString($value), |
|
442 | static::valueToString($value2) |
|
443 | )); |
|
444 | } |
|
445 | } |
|
446 | ||
447 | public static function notSame($value, $value2, $message = '') |
|
448 | { |
|
@@ 457-466 (lines=10) @@ | ||
454 | } |
|
455 | } |
|
456 | ||
457 | public static function greaterThan($value, $limit, $message = '') |
|
458 | { |
|
459 | if ($value <= $limit) { |
|
460 | static::reportInvalidArgument(sprintf( |
|
461 | $message ?: 'Expected a value greater than %2$s. Got: %s', |
|
462 | static::valueToString($value), |
|
463 | static::valueToString($limit) |
|
464 | )); |
|
465 | } |
|
466 | } |
|
467 | ||
468 | public static function greaterThanEq($value, $limit, $message = '') |
|
469 | { |
|
@@ 468-477 (lines=10) @@ | ||
465 | } |
|
466 | } |
|
467 | ||
468 | public static function greaterThanEq($value, $limit, $message = '') |
|
469 | { |
|
470 | if ($value < $limit) { |
|
471 | static::reportInvalidArgument(sprintf( |
|
472 | $message ?: 'Expected a value greater than or equal to %2$s. Got: %s', |
|
473 | static::valueToString($value), |
|
474 | static::valueToString($limit) |
|
475 | )); |
|
476 | } |
|
477 | } |
|
478 | ||
479 | public static function lessThan($value, $limit, $message = '') |
|
480 | { |
|
@@ 479-488 (lines=10) @@ | ||
476 | } |
|
477 | } |
|
478 | ||
479 | public static function lessThan($value, $limit, $message = '') |
|
480 | { |
|
481 | if ($value >= $limit) { |
|
482 | static::reportInvalidArgument(sprintf( |
|
483 | $message ?: 'Expected a value less than %2$s. Got: %s', |
|
484 | static::valueToString($value), |
|
485 | static::valueToString($limit) |
|
486 | )); |
|
487 | } |
|
488 | } |
|
489 | ||
490 | public static function lessThanEq($value, $limit, $message = '') |
|
491 | { |
|
@@ 490-499 (lines=10) @@ | ||
487 | } |
|
488 | } |
|
489 | ||
490 | public static function lessThanEq($value, $limit, $message = '') |
|
491 | { |
|
492 | if ($value > $limit) { |
|
493 | static::reportInvalidArgument(sprintf( |
|
494 | $message ?: 'Expected a value less than or equal to %2$s. Got: %s', |
|
495 | static::valueToString($value), |
|
496 | static::valueToString($limit) |
|
497 | )); |
|
498 | } |
|
499 | } |
|
500 | ||
501 | public static function range($value, $min, $max, $message = '') |
|
502 | { |
|
@@ 535-543 (lines=9) @@ | ||
532 | } |
|
533 | } |
|
534 | ||
535 | public static function notWhitespaceOnly($value, $message = '') |
|
536 | { |
|
537 | if (preg_match('/^\s*$/', $value)) { |
|
538 | static::reportInvalidArgument(sprintf( |
|
539 | $message ?: 'Expected a non-whitespace string. Got: %s', |
|
540 | static::valueToString($value) |
|
541 | )); |
|
542 | } |
|
543 | } |
|
544 | ||
545 | public static function startsWith($value, $prefix, $message = '') |
|
546 | { |
|
@@ 586-594 (lines=9) @@ | ||
583 | } |
|
584 | } |
|
585 | ||
586 | public static function regex($value, $pattern, $message = '') |
|
587 | { |
|
588 | if (!preg_match($pattern, $value)) { |
|
589 | static::reportInvalidArgument(sprintf( |
|
590 | $message ?: 'The value %s does not match the expected pattern.', |
|
591 | static::valueToString($value) |
|
592 | )); |
|
593 | } |
|
594 | } |
|
595 | ||
596 | public static function alpha($value, $message = '') |
|
597 | { |
|
@@ 682-691 (lines=10) @@ | ||
679 | } |
|
680 | } |
|
681 | ||
682 | public static function minLength($value, $min, $message = '') |
|
683 | { |
|
684 | if (static::strlen($value) < $min) { |
|
685 | static::reportInvalidArgument(sprintf( |
|
686 | $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', |
|
687 | static::valueToString($value), |
|
688 | $min |
|
689 | )); |
|
690 | } |
|
691 | } |
|
692 | ||
693 | public static function maxLength($value, $max, $message = '') |
|
694 | { |
|
@@ 693-702 (lines=10) @@ | ||
690 | } |
|
691 | } |
|
692 | ||
693 | public static function maxLength($value, $max, $message = '') |
|
694 | { |
|
695 | if (static::strlen($value) > $max) { |
|
696 | static::reportInvalidArgument(sprintf( |
|
697 | $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', |
|
698 | static::valueToString($value), |
|
699 | $max |
|
700 | )); |
|
701 | } |
|
702 | } |
|
703 | ||
704 | public static function lengthBetween($value, $min, $max, $message = '') |
|
705 | { |
|
@@ 754-762 (lines=9) @@ | ||
751 | } |
|
752 | } |
|
753 | ||
754 | public static function readable($value, $message = '') |
|
755 | { |
|
756 | if (!is_readable($value)) { |
|
757 | static::reportInvalidArgument(sprintf( |
|
758 | $message ?: 'The path %s is not readable.', |
|
759 | static::valueToString($value) |
|
760 | )); |
|
761 | } |
|
762 | } |
|
763 | ||
764 | public static function writable($value, $message = '') |
|
765 | { |
|
@@ 764-772 (lines=9) @@ | ||
761 | } |
|
762 | } |
|
763 | ||
764 | public static function writable($value, $message = '') |
|
765 | { |
|
766 | if (!is_writable($value)) { |
|
767 | static::reportInvalidArgument(sprintf( |
|
768 | $message ?: 'The path %s is not writable.', |
|
769 | static::valueToString($value) |
|
770 | )); |
|
771 | } |
|
772 | } |
|
773 | ||
774 | public static function classExists($value, $message = '') |
|
775 | { |
|
@@ 774-782 (lines=9) @@ | ||
771 | } |
|
772 | } |
|
773 | ||
774 | public static function classExists($value, $message = '') |
|
775 | { |
|
776 | if (!class_exists($value)) { |
|
777 | static::reportInvalidArgument(sprintf( |
|
778 | $message ?: 'Expected an existing class name. Got: %s', |
|
779 | static::valueToString($value) |
|
780 | )); |
|
781 | } |
|
782 | } |
|
783 | ||
784 | public static function subclassOf($value, $class, $message = '') |
|
785 | { |