|
@@ 938-948 (lines=11) @@
|
| 935 |
|
* |
| 936 |
|
* @throws InvalidArgumentException |
| 937 |
|
*/ |
| 938 |
|
public static function range($value, $min, $max, $message = '') |
| 939 |
|
{ |
| 940 |
|
if ($value < $min || $value > $max) { |
| 941 |
|
static::reportInvalidArgument(\sprintf( |
| 942 |
|
$message ?: 'Expected a value between %2$s and %3$s. Got: %s', |
| 943 |
|
static::valueToString($value), |
| 944 |
|
static::valueToString($min), |
| 945 |
|
static::valueToString($max) |
| 946 |
|
)); |
| 947 |
|
} |
| 948 |
|
} |
| 949 |
|
|
| 950 |
|
/** |
| 951 |
|
* Does strict comparison, so Assert::oneOf(3, ['3']) does not pass the assertion. |
|
@@ 1314-1326 (lines=13) @@
|
| 1311 |
|
* |
| 1312 |
|
* @throws InvalidArgumentException |
| 1313 |
|
*/ |
| 1314 |
|
public static function lengthBetween($value, $min, $max, $message = '') |
| 1315 |
|
{ |
| 1316 |
|
$length = static::strlen($value); |
| 1317 |
|
|
| 1318 |
|
if ($length < $min || $length > $max) { |
| 1319 |
|
static::reportInvalidArgument(\sprintf( |
| 1320 |
|
$message ?: 'Expected a value to contain between %2$s and %3$s characters. Got: %s', |
| 1321 |
|
static::valueToString($value), |
| 1322 |
|
$min, |
| 1323 |
|
$max |
| 1324 |
|
)); |
| 1325 |
|
} |
| 1326 |
|
} |
| 1327 |
|
|
| 1328 |
|
/** |
| 1329 |
|
* Will also pass if $value is a directory, use Assert::file() instead if you need to be sure it is a file. |