@@ 945-955 (lines=11) @@ | ||
942 | * |
|
943 | * @throws InvalidArgumentException |
|
944 | */ |
|
945 | public static function range($value, $min, $max, $message = '') |
|
946 | { |
|
947 | if ($value < $min || $value > $max) { |
|
948 | static::reportInvalidArgument(\sprintf( |
|
949 | $message ?: 'Expected a value between %2$s and %3$s. Got: %s', |
|
950 | static::valueToString($value), |
|
951 | static::valueToString($min), |
|
952 | static::valueToString($max) |
|
953 | )); |
|
954 | } |
|
955 | } |
|
956 | ||
957 | /** |
|
958 | * Does strict comparison, so Assert::oneOf(3, ['3']) does not pass the assertion. |
|
@@ 1331-1343 (lines=13) @@ | ||
1328 | * |
|
1329 | * @throws InvalidArgumentException |
|
1330 | */ |
|
1331 | public static function lengthBetween($value, $min, $max, $message = '') |
|
1332 | { |
|
1333 | $length = static::strlen($value); |
|
1334 | ||
1335 | if ($length < $min || $length > $max) { |
|
1336 | static::reportInvalidArgument(\sprintf( |
|
1337 | $message ?: 'Expected a value to contain between %2$s and %3$s characters. Got: %s', |
|
1338 | static::valueToString($value), |
|
1339 | $min, |
|
1340 | $max |
|
1341 | )); |
|
1342 | } |
|
1343 | } |
|
1344 | ||
1345 | /** |
|
1346 | * Will also pass if $value is a directory, use Assert::file() instead if you need to be sure it is a file. |