@@ 952-962 (lines=11) @@ | ||
949 | * |
|
950 | * @throws InvalidArgumentException |
|
951 | */ |
|
952 | public static function range($value, $min, $max, $message = '') |
|
953 | { |
|
954 | if ($value < $min || $value > $max) { |
|
955 | static::reportInvalidArgument(\sprintf( |
|
956 | $message ?: 'Expected a value between %2$s and %3$s. Got: %s', |
|
957 | static::valueToString($value), |
|
958 | static::valueToString($min), |
|
959 | static::valueToString($max) |
|
960 | )); |
|
961 | } |
|
962 | } |
|
963 | ||
964 | /** |
|
965 | * Does strict comparison, so Assert::oneOf(3, ['3']) does not pass the assertion. |
|
@@ 1338-1350 (lines=13) @@ | ||
1335 | * |
|
1336 | * @throws InvalidArgumentException |
|
1337 | */ |
|
1338 | public static function lengthBetween($value, $min, $max, $message = '') |
|
1339 | { |
|
1340 | $length = static::strlen($value); |
|
1341 | ||
1342 | if ($length < $min || $length > $max) { |
|
1343 | static::reportInvalidArgument(\sprintf( |
|
1344 | $message ?: 'Expected a value to contain between %2$s and %3$s characters. Got: %s', |
|
1345 | static::valueToString($value), |
|
1346 | $min, |
|
1347 | $max |
|
1348 | )); |
|
1349 | } |
|
1350 | } |
|
1351 | ||
1352 | /** |
|
1353 | * Will also pass if $value is a directory, use Assert::file() instead if you need to be sure it is a file. |