@@ 81-89 (lines=9) @@ | ||
78 | * |
|
79 | * @throws InvalidArgumentException |
|
80 | */ |
|
81 | public static function integer($value, $message = '') |
|
82 | { |
|
83 | if (!\is_int($value)) { |
|
84 | static::reportInvalidArgument(\sprintf( |
|
85 | $message ?: 'Expected an integer. Got: %s', |
|
86 | static::typeToString($value) |
|
87 | )); |
|
88 | } |
|
89 | } |
|
90 | ||
91 | /** |
|
92 | * @psalm-pure |
|
@@ 119-127 (lines=9) @@ | ||
116 | * |
|
117 | * @throws InvalidArgumentException |
|
118 | */ |
|
119 | public static function positiveInteger($value, $message = '') |
|
120 | { |
|
121 | if (!(\is_int($value) && $value > 0)) { |
|
122 | static::reportInvalidArgument(\sprintf( |
|
123 | $message ?: 'Expected a positive integer. Got: %s', |
|
124 | static::valueToString($value) |
|
125 | )); |
|
126 | } |
|
127 | } |
|
128 | ||
129 | /** |
|
130 | * @psalm-pure |
|
@@ 176-184 (lines=9) @@ | ||
173 | * |
|
174 | * @throws InvalidArgumentException |
|
175 | */ |
|
176 | public static function natural($value, $message = '') |
|
177 | { |
|
178 | if (!\is_int($value) || $value < 0) { |
|
179 | static::reportInvalidArgument(\sprintf( |
|
180 | $message ?: 'Expected a non-negative integer. Got: %s', |
|
181 | static::valueToString($value) |
|
182 | )); |
|
183 | } |
|
184 | } |
|
185 | ||
186 | /** |
|
187 | * @psalm-pure |
|
@@ 596-604 (lines=9) @@ | ||
593 | * |
|
594 | * @throws InvalidArgumentException |
|
595 | */ |
|
596 | public static function null($value, $message = '') |
|
597 | { |
|
598 | if (null !== $value) { |
|
599 | static::reportInvalidArgument(\sprintf( |
|
600 | $message ?: 'Expected null. Got: %s', |
|
601 | static::valueToString($value) |
|
602 | )); |
|
603 | } |
|
604 | } |
|
605 | ||
606 | /** |
|
607 | * @psalm-pure |
|
@@ 633-641 (lines=9) @@ | ||
630 | * |
|
631 | * @throws InvalidArgumentException |
|
632 | */ |
|
633 | public static function true($value, $message = '') |
|
634 | { |
|
635 | if (true !== $value) { |
|
636 | static::reportInvalidArgument(\sprintf( |
|
637 | $message ?: 'Expected a value to be true. Got: %s', |
|
638 | static::valueToString($value) |
|
639 | )); |
|
640 | } |
|
641 | } |
|
642 | ||
643 | /** |
|
644 | * @psalm-pure |
|
@@ 652-660 (lines=9) @@ | ||
649 | * |
|
650 | * @throws InvalidArgumentException |
|
651 | */ |
|
652 | public static function false($value, $message = '') |
|
653 | { |
|
654 | if (false !== $value) { |
|
655 | static::reportInvalidArgument(\sprintf( |
|
656 | $message ?: 'Expected a value to be false. Got: %s', |
|
657 | static::valueToString($value) |
|
658 | )); |
|
659 | } |
|
660 | } |
|
661 | ||
662 | /** |
|
663 | * @psalm-pure |
|
@@ 775-784 (lines=10) @@ | ||
772 | * |
|
773 | * @throws InvalidArgumentException |
|
774 | */ |
|
775 | public static function eq($value, $expect, $message = '') |
|
776 | { |
|
777 | if ($expect != $value) { |
|
778 | static::reportInvalidArgument(\sprintf( |
|
779 | $message ?: 'Expected a value equal to %2$s. Got: %s', |
|
780 | static::valueToString($value), |
|
781 | static::valueToString($expect) |
|
782 | )); |
|
783 | } |
|
784 | } |
|
785 | ||
786 | /** |
|
787 | * @param mixed $value |
|
@@ 812-821 (lines=10) @@ | ||
809 | * |
|
810 | * @throws InvalidArgumentException |
|
811 | */ |
|
812 | public static function same($value, $expect, $message = '') |
|
813 | { |
|
814 | if ($expect !== $value) { |
|
815 | static::reportInvalidArgument(\sprintf( |
|
816 | $message ?: 'Expected a value identical to %2$s. Got: %s', |
|
817 | static::valueToString($value), |
|
818 | static::valueToString($expect) |
|
819 | )); |
|
820 | } |
|
821 | } |
|
822 | ||
823 | /** |
|
824 | * @psalm-pure |
|
@@ 851-860 (lines=10) @@ | ||
848 | * |
|
849 | * @throws InvalidArgumentException |
|
850 | */ |
|
851 | public static function greaterThan($value, $limit, $message = '') |
|
852 | { |
|
853 | if ($value <= $limit) { |
|
854 | static::reportInvalidArgument(\sprintf( |
|
855 | $message ?: 'Expected a value greater than %2$s. Got: %s', |
|
856 | static::valueToString($value), |
|
857 | static::valueToString($limit) |
|
858 | )); |
|
859 | } |
|
860 | } |
|
861 | ||
862 | /** |
|
863 | * @psalm-pure |
|
@@ 871-880 (lines=10) @@ | ||
868 | * |
|
869 | * @throws InvalidArgumentException |
|
870 | */ |
|
871 | public static function greaterThanEq($value, $limit, $message = '') |
|
872 | { |
|
873 | if ($value < $limit) { |
|
874 | static::reportInvalidArgument(\sprintf( |
|
875 | $message ?: 'Expected a value greater than or equal to %2$s. Got: %s', |
|
876 | static::valueToString($value), |
|
877 | static::valueToString($limit) |
|
878 | )); |
|
879 | } |
|
880 | } |
|
881 | ||
882 | /** |
|
883 | * @psalm-pure |
|
@@ 891-900 (lines=10) @@ | ||
888 | * |
|
889 | * @throws InvalidArgumentException |
|
890 | */ |
|
891 | public static function lessThan($value, $limit, $message = '') |
|
892 | { |
|
893 | if ($value >= $limit) { |
|
894 | static::reportInvalidArgument(\sprintf( |
|
895 | $message ?: 'Expected a value less than %2$s. Got: %s', |
|
896 | static::valueToString($value), |
|
897 | static::valueToString($limit) |
|
898 | )); |
|
899 | } |
|
900 | } |
|
901 | ||
902 | /** |
|
903 | * @psalm-pure |
|
@@ 911-920 (lines=10) @@ | ||
908 | * |
|
909 | * @throws InvalidArgumentException |
|
910 | */ |
|
911 | public static function lessThanEq($value, $limit, $message = '') |
|
912 | { |
|
913 | if ($value > $limit) { |
|
914 | static::reportInvalidArgument(\sprintf( |
|
915 | $message ?: 'Expected a value less than or equal to %2$s. Got: %s', |
|
916 | static::valueToString($value), |
|
917 | static::valueToString($limit) |
|
918 | )); |
|
919 | } |
|
920 | } |
|
921 | ||
922 | /** |
|
923 | * Inclusive range, so Assert::(3, 3, 5) passes. |
|
@@ 1032-1040 (lines=9) @@ | ||
1029 | * |
|
1030 | * @throws InvalidArgumentException |
|
1031 | */ |
|
1032 | public static function notWhitespaceOnly($value, $message = '') |
|
1033 | { |
|
1034 | if (\preg_match('/^\s*$/', $value)) { |
|
1035 | static::reportInvalidArgument(\sprintf( |
|
1036 | $message ?: 'Expected a non-whitespace string. Got: %s', |
|
1037 | static::valueToString($value) |
|
1038 | )); |
|
1039 | } |
|
1040 | } |
|
1041 | ||
1042 | /** |
|
1043 | * @psalm-pure |
|
@@ 1361-1370 (lines=10) @@ | ||
1358 | * |
|
1359 | * @throws InvalidArgumentException |
|
1360 | */ |
|
1361 | public static function minLength($value, $min, $message = '') |
|
1362 | { |
|
1363 | if (static::strlen($value) < $min) { |
|
1364 | static::reportInvalidArgument(\sprintf( |
|
1365 | $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', |
|
1366 | static::valueToString($value), |
|
1367 | $min |
|
1368 | )); |
|
1369 | } |
|
1370 | } |
|
1371 | ||
1372 | /** |
|
1373 | * Inclusive max. |
|
@@ 1383-1392 (lines=10) @@ | ||
1380 | * |
|
1381 | * @throws InvalidArgumentException |
|
1382 | */ |
|
1383 | public static function maxLength($value, $max, $message = '') |
|
1384 | { |
|
1385 | if (static::strlen($value) > $max) { |
|
1386 | static::reportInvalidArgument(\sprintf( |
|
1387 | $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', |
|
1388 | static::valueToString($value), |
|
1389 | $max |
|
1390 | )); |
|
1391 | } |
|
1392 | } |
|
1393 | ||
1394 | /** |
|
1395 | * Inclusive , so Assert::lengthBetween('asd', 3, 5); passes the assertion. |
|
@@ 1482-1490 (lines=9) @@ | ||
1479 | * |
|
1480 | * @throws InvalidArgumentException |
|
1481 | */ |
|
1482 | public static function readable($value, $message = '') |
|
1483 | { |
|
1484 | if (!\is_readable($value)) { |
|
1485 | static::reportInvalidArgument(\sprintf( |
|
1486 | $message ?: 'The path %s is not readable.', |
|
1487 | static::valueToString($value) |
|
1488 | )); |
|
1489 | } |
|
1490 | } |
|
1491 | ||
1492 | /** |
|
1493 | * @param string $value |
|
@@ 1498-1506 (lines=9) @@ | ||
1495 | * |
|
1496 | * @throws InvalidArgumentException |
|
1497 | */ |
|
1498 | public static function writable($value, $message = '') |
|
1499 | { |
|
1500 | if (!\is_writable($value)) { |
|
1501 | static::reportInvalidArgument(\sprintf( |
|
1502 | $message ?: 'The path %s is not writable.', |
|
1503 | static::valueToString($value) |
|
1504 | )); |
|
1505 | } |
|
1506 | } |
|
1507 | ||
1508 | /** |
|
1509 | * @psalm-assert class-string $value |
|
@@ 1516-1524 (lines=9) @@ | ||
1513 | * |
|
1514 | * @throws InvalidArgumentException |
|
1515 | */ |
|
1516 | public static function classExists($value, $message = '') |
|
1517 | { |
|
1518 | if (!\class_exists($value)) { |
|
1519 | static::reportInvalidArgument(\sprintf( |
|
1520 | $message ?: 'Expected an existing class name. Got: %s', |
|
1521 | static::valueToString($value) |
|
1522 | )); |
|
1523 | } |
|
1524 | } |
|
1525 | ||
1526 | /** |
|
1527 | * @psalm-pure |
|
@@ 1557-1565 (lines=9) @@ | ||
1554 | * |
|
1555 | * @throws InvalidArgumentException |
|
1556 | */ |
|
1557 | public static function interfaceExists($value, $message = '') |
|
1558 | { |
|
1559 | if (!\interface_exists($value)) { |
|
1560 | static::reportInvalidArgument(\sprintf( |
|
1561 | $message ?: 'Expected an existing interface name. got %s', |
|
1562 | static::valueToString($value) |
|
1563 | )); |
|
1564 | } |
|
1565 | } |
|
1566 | ||
1567 | /** |
|
1568 | * @psalm-pure |