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