diff --git a/src/Assert.php b/src/Assert.php index b28e1784..712a643a 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -39,18 +39,22 @@ class Assert * @psalm-pure * @psalm-assert string $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function string($value, $message = '') { if (!\is_string($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected a string. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : \sprintf( + $message ?: 'Expected a string. Got: %s', + static::typeToString($value) + ) + ); } } @@ -58,8 +62,8 @@ public static function string($value, $message = '') * @psalm-pure * @psalm-assert non-empty-string $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -73,18 +77,22 @@ public static function stringNotEmpty($value, $message = '') * @psalm-pure * @psalm-assert int $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function integer($value, $message = '') { if (!\is_int($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected an integer. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected an integer. Got: %s', + static::typeToString($value) + ) + ); } } @@ -92,18 +100,22 @@ public static function integer($value, $message = '') * @psalm-pure * @psalm-assert numeric $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function integerish($value, $message = '') { if (!\is_numeric($value) || $value != (int) $value) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected an integerish value. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected an integerish value. Got: %s', + static::typeToString($value) + ) + ); } } @@ -111,18 +123,22 @@ public static function integerish($value, $message = '') * @psalm-pure * @psalm-assert float $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function float($value, $message = '') { if (!\is_float($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected a float. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected a float. Got: %s', + static::typeToString($value) + ) + ); } } @@ -130,18 +146,22 @@ public static function float($value, $message = '') * @psalm-pure * @psalm-assert numeric $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function numeric($value, $message = '') { if (!\is_numeric($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected a numeric. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected a numeric. Got: %s', + static::typeToString($value) + ) + ); } } @@ -149,8 +169,8 @@ public static function numeric($value, $message = '') * @psalm-pure * @psalm-assert int $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -168,18 +188,22 @@ public static function natural($value, $message = '') * @psalm-pure * @psalm-assert bool $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function boolean($value, $message = '') { if (!\is_bool($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected a boolean. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected a boolean. Got: %s', + static::typeToString($value) + ) + ); } } @@ -187,18 +211,22 @@ public static function boolean($value, $message = '') * @psalm-pure * @psalm-assert scalar $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function scalar($value, $message = '') { if (!\is_scalar($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected a scalar. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected a scalar. Got: %s', + static::typeToString($value) + ) + ); } } @@ -206,18 +234,22 @@ public static function scalar($value, $message = '') * @psalm-pure * @psalm-assert object $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function object($value, $message = '') { if (!\is_object($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected an object. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected an object. Got: %s', + static::typeToString($value) + ) + ); } } @@ -234,10 +266,14 @@ public static function object($value, $message = '') public static function resource($value, $type = null, $message = '') { if (!\is_resource($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected a resource. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected a resource. Got: %s', + static::typeToString($value) + ) + ); } if ($type && $type !== \get_resource_type($value)) { @@ -253,18 +289,22 @@ public static function resource($value, $type = null, $message = '') * @psalm-pure * @psalm-assert callable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function isCallable($value, $message = '') { if (!\is_callable($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected a callable. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected a callable. Got: %s', + static::typeToString($value) + ) + ); } } @@ -272,18 +312,22 @@ public static function isCallable($value, $message = '') * @psalm-pure * @psalm-assert array $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function isArray($value, $message = '') { if (!\is_array($value)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected an array. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected an array. Got: %s', + static::typeToString($value) + ) + ); } } @@ -293,8 +337,8 @@ public static function isArray($value, $message = '') * * @deprecated use "isIterable" or "isInstanceOf" instead * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -309,10 +353,14 @@ public static function isTraversable($value, $message = '') ); if (!\is_array($value) && !($value instanceof Traversable)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected a traversable. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected a traversable. Got: %s', + static::typeToString($value) + ) + ); } } @@ -320,18 +368,22 @@ public static function isTraversable($value, $message = '') * @psalm-pure * @psalm-assert array|ArrayAccess $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function isArrayAccessible($value, $message = '') { if (!\is_array($value) && !($value instanceof ArrayAccess)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected an array accessible. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected an array accessible. Got: %s', + static::typeToString($value) + ) + ); } } @@ -339,8 +391,8 @@ public static function isArrayAccessible($value, $message = '') * @psalm-pure * @psalm-assert countable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -352,10 +404,14 @@ public static function isCountable($value, $message = '') && !($value instanceof ResourceBundle) && !($value instanceof SimpleXMLElement) ) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected a countable. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected a countable. Got: %s', + static::typeToString($value) + ) + ); } } @@ -363,18 +419,22 @@ public static function isCountable($value, $message = '') * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function isIterable($value, $message = '') { if (!\is_array($value) && !($value instanceof Traversable)) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected an iterable. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected an iterable. Got: %s', + static::typeToString($value) + ) + ); } } @@ -445,7 +505,7 @@ public static function isInstanceOfAny($value, array $classes, $message = '') static::reportInvalidArgument(\sprintf( $message ?: 'Expected an instance of any of %2$s. Got: %s', static::typeToString($value), - \implode(', ', \array_map(array('static', 'valueToString'), $classes)) + \implode(', ', \array_map(['static', 'valueToString'], $classes)) )); } @@ -523,7 +583,7 @@ public static function isAnyOf($value, array $classes, $message = '') static::reportInvalidArgument(sprintf( $message ?: 'Expected an any of instance of this class or to this class among his parents other than %2$s. Got: %s', static::typeToString($value), - \implode(', ', \array_map(array('static', 'valueToString'), $classes)) + \implode(', ', \array_map(['static', 'valueToString'], $classes)) )); } @@ -531,8 +591,8 @@ public static function isAnyOf($value, array $classes, $message = '') * @psalm-pure * @psalm-assert empty $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -550,8 +610,8 @@ public static function isEmpty($value, $message = '') * @psalm-pure * @psalm-assert !empty $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -569,8 +629,8 @@ public static function notEmpty($value, $message = '') * @psalm-pure * @psalm-assert null $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -588,8 +648,8 @@ public static function null($value, $message = '') * @psalm-pure * @psalm-assert !null $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -606,8 +666,8 @@ public static function notNull($value, $message = '') * @psalm-pure * @psalm-assert true $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -625,8 +685,8 @@ public static function true($value, $message = '') * @psalm-pure * @psalm-assert false $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -644,8 +704,8 @@ public static function false($value, $message = '') * @psalm-pure * @psalm-assert !false $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -659,8 +719,8 @@ public static function notFalse($value, $message = '') } /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -675,8 +735,8 @@ public static function ip($value, $message = '') } /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -691,8 +751,8 @@ public static function ipv4($value, $message = '') } /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -707,8 +767,8 @@ public static function ipv6($value, $message = '') } /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -725,8 +785,7 @@ public static function email($value, $message = '') /** * Does non strict comparisons on the items, so ['3', 3] will not pass the assertion. * - * @param array $values - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -747,9 +806,9 @@ public static function uniqueValues(array $values, $message = '') } /** - * @param mixed $value + * @param mixed $value * @param mixed $expect - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -765,9 +824,9 @@ public static function eq($value, $expect, $message = '') } /** - * @param mixed $value + * @param mixed $value * @param mixed $expect - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -784,9 +843,9 @@ public static function notEq($value, $expect, $message = '') /** * @psalm-pure * - * @param mixed $value + * @param mixed $value * @param mixed $expect - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -804,9 +863,9 @@ public static function same($value, $expect, $message = '') /** * @psalm-pure * - * @param mixed $value + * @param mixed $value * @param mixed $expect - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -823,9 +882,9 @@ public static function notSame($value, $expect, $message = '') /** * @psalm-pure * - * @param mixed $value + * @param mixed $value * @param mixed $limit - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -843,9 +902,9 @@ public static function greaterThan($value, $limit, $message = '') /** * @psalm-pure * - * @param mixed $value + * @param mixed $value * @param mixed $limit - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -863,9 +922,9 @@ public static function greaterThanEq($value, $limit, $message = '') /** * @psalm-pure * - * @param mixed $value + * @param mixed $value * @param mixed $limit - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -883,9 +942,9 @@ public static function lessThan($value, $limit, $message = '') /** * @psalm-pure * - * @param mixed $value + * @param mixed $value * @param mixed $limit - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -905,10 +964,10 @@ public static function lessThanEq($value, $limit, $message = '') * * @psalm-pure * - * @param mixed $value + * @param mixed $value * @param mixed $min * @param mixed $max - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -929,9 +988,9 @@ public static function range($value, $min, $max, $message = '') * * @psalm-pure * - * @param mixed $value + * @param mixed $value * @param array $values - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -945,9 +1004,9 @@ public static function oneOf($value, array $values, $message = '') * * @psalm-pure * - * @param mixed $value + * @param mixed $value * @param array $values - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -967,7 +1026,7 @@ public static function inArray($value, array $values, $message = '') * * @param string $value * @param string $subString - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -987,7 +1046,7 @@ public static function contains($value, $subString, $message = '') * * @param string $value * @param string $subString - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1005,8 +1064,8 @@ public static function notContains($value, $subString, $message = '') /** * @psalm-pure * - * @param string $value - * @param string $message + * @param string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1023,9 +1082,9 @@ public static function notWhitespaceOnly($value, $message = '') /** * @psalm-pure * - * @param string $value - * @param string $prefix - * @param string $message + * @param string $value + * @param string $prefix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1043,9 +1102,9 @@ public static function startsWith($value, $prefix, $message = '') /** * @psalm-pure * - * @param string $value - * @param string $prefix - * @param string $message + * @param string $value + * @param string $prefix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1063,8 +1122,8 @@ public static function notStartsWith($value, $prefix, $message = '') /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1094,7 +1153,7 @@ public static function startsWithLetter($value, $message = '') * * @param string $value * @param string $suffix - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1114,7 +1173,7 @@ public static function endsWith($value, $suffix, $message = '') * * @param string $value * @param string $suffix - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1134,7 +1193,7 @@ public static function notEndsWith($value, $suffix, $message = '') * * @param string $value * @param string $pattern - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1153,7 +1212,7 @@ public static function regex($value, $pattern, $message = '') * * @param string $value * @param string $pattern - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1172,8 +1231,8 @@ public static function notRegex($value, $pattern, $message = '') /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1192,8 +1251,8 @@ public static function unicodeLetters($value, $message = '') /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1217,8 +1276,8 @@ public static function alpha($value, $message = '') /** * @psalm-pure * - * @param string $value - * @param string $message + * @param string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1240,8 +1299,8 @@ public static function digits($value, $message = '') /** * @psalm-pure * - * @param string $value - * @param string $message + * @param string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1264,8 +1323,8 @@ public static function alnum($value, $message = '') * @psalm-pure * @psalm-assert lowercase-string $value * - * @param string $value - * @param string $message + * @param string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1288,8 +1347,8 @@ public static function lower($value, $message = '') * @psalm-pure * @psalm-assert !lowercase-string $value * - * @param string $value - * @param string $message + * @param string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1313,7 +1372,7 @@ public static function upper($value, $message = '') * * @param string $value * @param int $length - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1401,8 +1460,8 @@ public static function lengthBetween($value, $min, $max, $message = '') /** * Will also pass if $value is a directory, use Assert::file() instead if you need to be sure it is a file. * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1419,8 +1478,8 @@ public static function fileExists($value, $message = '') } /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1437,8 +1496,8 @@ public static function file($value, $message = '') } /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1455,8 +1514,8 @@ public static function directory($value, $message = '') } /** - * @param string $value - * @param string $message + * @param string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1471,8 +1530,8 @@ public static function readable($value, $message = '') } /** - * @param string $value - * @param string $message + * @param string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1489,8 +1548,8 @@ public static function writable($value, $message = '') /** * @psalm-assert class-string $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1530,8 +1589,8 @@ public static function subclassOf($value, $class, $message = '') /** * @psalm-assert class-string $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1551,9 +1610,9 @@ public static function interfaceExists($value, $message = '') * @psalm-param class-string $interface * @psalm-assert class-string $value * - * @param mixed $value + * @param mixed $value * @param mixed $interface - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1692,18 +1751,22 @@ public static function keyNotExists($array, $key, $message = '') * @psalm-pure * @psalm-assert array-key $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function validArrayKey($value, $message = '') { if (!(\is_int($value) || \is_string($value))) { - static::reportInvalidArgument(\sprintf( - $message ?: 'Expected string or integer. Got: %s', - static::typeToString($value) - )); + static::reportInvalidArgument( + is_callable($message) + ? $message() + : sprintf( + $message ?: 'Expected string or integer. Got: %s', + static::typeToString($value) + ) + ); } } @@ -1798,7 +1861,7 @@ public static function countBetween($array, $min, $max, $message = '') * @psalm-assert list $array * * @param mixed $array - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1816,7 +1879,7 @@ public static function isList($array, $message = '') * @psalm-assert non-empty-list $array * * @param mixed $array - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1833,7 +1896,7 @@ public static function isNonEmptyList($array, $message = '') * @psalm-assert array $array * * @param mixed $array - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1857,7 +1920,7 @@ public static function isMap($array, $message = '') * @psalm-assert !empty $array * * @param mixed $array - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1870,8 +1933,8 @@ public static function isNonEmptyMap($array, $message = '') /** * @psalm-pure * - * @param string $value - * @param string $message + * @param string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -2031,7 +2094,7 @@ protected static function strlen($value) } /** - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException * @@ -2039,6 +2102,10 @@ protected static function strlen($value) */ protected static function reportInvalidArgument($message) { + if (is_callable($message)) { + $message = $message(); + } + throw new InvalidArgumentException($message); } diff --git a/src/Mixin.php b/src/Mixin.php index 3ad9b2d0..ea46a758 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -18,8 +18,8 @@ interface Mixin * @psalm-pure * @psalm-assert null|string $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -29,8 +29,8 @@ public static function nullOrString($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -40,8 +40,8 @@ public static function allString($value, $message = ''); * @psalm-pure * @psalm-assert null|non-empty-string $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -51,8 +51,8 @@ public static function nullOrStringNotEmpty($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -62,8 +62,8 @@ public static function allStringNotEmpty($value, $message = ''); * @psalm-pure * @psalm-assert null|int $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -73,8 +73,8 @@ public static function nullOrInteger($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -84,8 +84,8 @@ public static function allInteger($value, $message = ''); * @psalm-pure * @psalm-assert null|numeric $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -95,8 +95,8 @@ public static function nullOrIntegerish($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -106,8 +106,8 @@ public static function allIntegerish($value, $message = ''); * @psalm-pure * @psalm-assert null|float $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -117,8 +117,8 @@ public static function nullOrFloat($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -128,8 +128,8 @@ public static function allFloat($value, $message = ''); * @psalm-pure * @psalm-assert null|numeric $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -139,8 +139,8 @@ public static function nullOrNumeric($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -150,8 +150,8 @@ public static function allNumeric($value, $message = ''); * @psalm-pure * @psalm-assert null|int $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -161,8 +161,8 @@ public static function nullOrNatural($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -172,8 +172,8 @@ public static function allNatural($value, $message = ''); * @psalm-pure * @psalm-assert null|bool $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -183,8 +183,8 @@ public static function nullOrBoolean($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -194,8 +194,8 @@ public static function allBoolean($value, $message = ''); * @psalm-pure * @psalm-assert null|scalar $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -205,8 +205,8 @@ public static function nullOrScalar($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -216,8 +216,8 @@ public static function allScalar($value, $message = ''); * @psalm-pure * @psalm-assert null|object $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -227,8 +227,8 @@ public static function nullOrObject($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -262,8 +262,8 @@ public static function allResource($value, $type = null, $message = ''); * @psalm-pure * @psalm-assert null|callable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -273,8 +273,8 @@ public static function nullOrIsCallable($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -284,8 +284,8 @@ public static function allIsCallable($value, $message = ''); * @psalm-pure * @psalm-assert null|array $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -295,8 +295,8 @@ public static function nullOrIsArray($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -308,8 +308,8 @@ public static function allIsArray($value, $message = ''); * * @deprecated use "isIterable" or "isInstanceOf" instead * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -321,8 +321,8 @@ public static function nullOrIsTraversable($value, $message = ''); * * @deprecated use "isIterable" or "isInstanceOf" instead * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -332,8 +332,8 @@ public static function allIsTraversable($value, $message = ''); * @psalm-pure * @psalm-assert null|array|ArrayAccess $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -343,8 +343,8 @@ public static function nullOrIsArrayAccessible($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -354,8 +354,8 @@ public static function allIsArrayAccessible($value, $message = ''); * @psalm-pure * @psalm-assert null|countable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -365,8 +365,8 @@ public static function nullOrIsCountable($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -376,8 +376,8 @@ public static function allIsCountable($value, $message = ''); * @psalm-pure * @psalm-assert null|iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -387,8 +387,8 @@ public static function nullOrIsIterable($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -554,8 +554,8 @@ public static function allIsAnyOf($value, $classes, $message = ''); * @psalm-pure * @psalm-assert empty $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -565,8 +565,8 @@ public static function nullOrIsEmpty($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -575,8 +575,8 @@ public static function allIsEmpty($value, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -585,8 +585,8 @@ public static function nullOrNotEmpty($value, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -596,8 +596,8 @@ public static function allNotEmpty($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -606,8 +606,8 @@ public static function allNull($value, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -617,8 +617,8 @@ public static function allNotNull($value, $message = ''); * @psalm-pure * @psalm-assert null|true $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -628,8 +628,8 @@ public static function nullOrTrue($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -639,8 +639,8 @@ public static function allTrue($value, $message = ''); * @psalm-pure * @psalm-assert null|false $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -650,8 +650,8 @@ public static function nullOrFalse($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -660,8 +660,8 @@ public static function allFalse($value, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -670,124 +670,122 @@ public static function nullOrNotFalse($value, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allNotFalse($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrIp($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allIp($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrIpv4($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allIpv4($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrIpv6($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allIpv6($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrEmail($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allEmail($value, $message = ''); /** - * @param null|array $values - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrUniqueValues($values, $message = ''); /** - * @param iterable $values - * @param string $message + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allUniqueValues($values, $message = ''); /** - * @param mixed $value - * @param mixed $expect - * @param string $message + * @param mixed $value + * @param mixed $expect + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrEq($value, $expect, $message = ''); /** - * @param mixed $value - * @param mixed $expect - * @param string $message + * @param mixed $value + * @param mixed $expect + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allEq($value, $expect, $message = ''); /** - * @param mixed $value - * @param mixed $expect - * @param string $message + * @param mixed $value + * @param mixed $expect + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrNotEq($value, $expect, $message = ''); /** - * @param mixed $value - * @param mixed $expect - * @param string $message + * @param mixed $value + * @param mixed $expect + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -796,9 +794,9 @@ public static function allNotEq($value, $expect, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $expect - * @param string $message + * @param mixed $value + * @param mixed $expect + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -807,9 +805,9 @@ public static function nullOrSame($value, $expect, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $expect - * @param string $message + * @param mixed $value + * @param mixed $expect + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -818,9 +816,9 @@ public static function allSame($value, $expect, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $expect - * @param string $message + * @param mixed $value + * @param mixed $expect + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -829,9 +827,9 @@ public static function nullOrNotSame($value, $expect, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $expect - * @param string $message + * @param mixed $value + * @param mixed $expect + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -840,9 +838,9 @@ public static function allNotSame($value, $expect, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $limit - * @param string $message + * @param mixed $value + * @param mixed $limit + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -851,9 +849,9 @@ public static function nullOrGreaterThan($value, $limit, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $limit - * @param string $message + * @param mixed $value + * @param mixed $limit + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -862,9 +860,9 @@ public static function allGreaterThan($value, $limit, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $limit - * @param string $message + * @param mixed $value + * @param mixed $limit + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -873,9 +871,9 @@ public static function nullOrGreaterThanEq($value, $limit, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $limit - * @param string $message + * @param mixed $value + * @param mixed $limit + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -884,9 +882,9 @@ public static function allGreaterThanEq($value, $limit, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $limit - * @param string $message + * @param mixed $value + * @param mixed $limit + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -895,9 +893,9 @@ public static function nullOrLessThan($value, $limit, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $limit - * @param string $message + * @param mixed $value + * @param mixed $limit + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -906,9 +904,9 @@ public static function allLessThan($value, $limit, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $limit - * @param string $message + * @param mixed $value + * @param mixed $limit + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -917,9 +915,9 @@ public static function nullOrLessThanEq($value, $limit, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $limit - * @param string $message + * @param mixed $value + * @param mixed $limit + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -928,10 +926,10 @@ public static function allLessThanEq($value, $limit, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $min - * @param mixed $max - * @param string $message + * @param mixed $value + * @param mixed $min + * @param mixed $max + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -940,10 +938,10 @@ public static function nullOrRange($value, $min, $max, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param mixed $min - * @param mixed $max - * @param string $message + * @param mixed $value + * @param mixed $min + * @param mixed $max + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -952,9 +950,9 @@ public static function allRange($value, $min, $max, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param array $values - * @param string $message + * @param mixed $value + * @param array $values + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -963,9 +961,9 @@ public static function nullOrOneOf($value, $values, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param array $values - * @param string $message + * @param mixed $value + * @param array $values + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -974,9 +972,9 @@ public static function allOneOf($value, $values, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param array $values - * @param string $message + * @param mixed $value + * @param array $values + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -985,9 +983,9 @@ public static function nullOrInArray($value, $values, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param array $values - * @param string $message + * @param mixed $value + * @param array $values + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -996,9 +994,9 @@ public static function allInArray($value, $values, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $subString - * @param string $message + * @param null|string $value + * @param string $subString + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1007,9 +1005,9 @@ public static function nullOrContains($value, $subString, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $subString - * @param string $message + * @param iterable $value + * @param string $subString + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1018,9 +1016,9 @@ public static function allContains($value, $subString, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $subString - * @param string $message + * @param null|string $value + * @param string $subString + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1029,9 +1027,9 @@ public static function nullOrNotContains($value, $subString, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $subString - * @param string $message + * @param iterable $value + * @param string $subString + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1040,8 +1038,8 @@ public static function allNotContains($value, $subString, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $message + * @param null|string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1050,8 +1048,8 @@ public static function nullOrNotWhitespaceOnly($value, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $message + * @param iterable $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1060,9 +1058,9 @@ public static function allNotWhitespaceOnly($value, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $prefix - * @param string $message + * @param null|string $value + * @param string $prefix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1071,9 +1069,9 @@ public static function nullOrStartsWith($value, $prefix, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $prefix - * @param string $message + * @param iterable $value + * @param string $prefix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1082,9 +1080,9 @@ public static function allStartsWith($value, $prefix, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $prefix - * @param string $message + * @param null|string $value + * @param string $prefix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1093,9 +1091,9 @@ public static function nullOrNotStartsWith($value, $prefix, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $prefix - * @param string $message + * @param iterable $value + * @param string $prefix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1104,8 +1102,8 @@ public static function allNotStartsWith($value, $prefix, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1114,8 +1112,8 @@ public static function nullOrStartsWithLetter($value, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1124,9 +1122,9 @@ public static function allStartsWithLetter($value, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $suffix - * @param string $message + * @param null|string $value + * @param string $suffix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1135,9 +1133,9 @@ public static function nullOrEndsWith($value, $suffix, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $suffix - * @param string $message + * @param iterable $value + * @param string $suffix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1146,9 +1144,9 @@ public static function allEndsWith($value, $suffix, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $suffix - * @param string $message + * @param null|string $value + * @param string $suffix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1157,9 +1155,9 @@ public static function nullOrNotEndsWith($value, $suffix, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $suffix - * @param string $message + * @param iterable $value + * @param string $suffix + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1168,9 +1166,9 @@ public static function allNotEndsWith($value, $suffix, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $pattern - * @param string $message + * @param null|string $value + * @param string $pattern + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1179,9 +1177,9 @@ public static function nullOrRegex($value, $pattern, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $pattern - * @param string $message + * @param iterable $value + * @param string $pattern + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1190,9 +1188,9 @@ public static function allRegex($value, $pattern, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $pattern - * @param string $message + * @param null|string $value + * @param string $pattern + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1201,9 +1199,9 @@ public static function nullOrNotRegex($value, $pattern, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $pattern - * @param string $message + * @param iterable $value + * @param string $pattern + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1212,8 +1210,8 @@ public static function allNotRegex($value, $pattern, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1222,8 +1220,8 @@ public static function nullOrUnicodeLetters($value, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1232,8 +1230,8 @@ public static function allUnicodeLetters($value, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1242,8 +1240,8 @@ public static function nullOrAlpha($value, $message = ''); /** * @psalm-pure * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1252,8 +1250,8 @@ public static function allAlpha($value, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $message + * @param null|string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1262,8 +1260,8 @@ public static function nullOrDigits($value, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $message + * @param iterable $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1272,8 +1270,8 @@ public static function allDigits($value, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $message + * @param null|string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1282,8 +1280,8 @@ public static function nullOrAlnum($value, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $message + * @param iterable $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1293,8 +1291,8 @@ public static function allAlnum($value, $message = ''); * @psalm-pure * @psalm-assert null|lowercase-string $value * - * @param null|string $value - * @param string $message + * @param null|string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1304,8 +1302,8 @@ public static function nullOrLower($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param iterable $value - * @param string $message + * @param iterable $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1314,8 +1312,8 @@ public static function allLower($value, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $message + * @param null|string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1324,8 +1322,8 @@ public static function nullOrUpper($value, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $message + * @param iterable $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1334,9 +1332,9 @@ public static function allUpper($value, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param int $length - * @param string $message + * @param null|string $value + * @param int $length + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1345,9 +1343,9 @@ public static function nullOrLength($value, $length, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param int $length - * @param string $message + * @param iterable $value + * @param int $length + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1422,80 +1420,80 @@ public static function nullOrLengthBetween($value, $min, $max, $message = ''); public static function allLengthBetween($value, $min, $max, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrFileExists($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allFileExists($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrFile($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allFile($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrDirectory($value, $message = ''); /** - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allDirectory($value, $message = ''); /** - * @param null|string $value - * @param string $message + * @param null|string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrReadable($value, $message = ''); /** - * @param iterable $value - * @param string $message + * @param iterable $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function allReadable($value, $message = ''); /** - * @param null|string $value - * @param string $message + * @param null|string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ public static function nullOrWritable($value, $message = ''); /** - * @param iterable $value - * @param string $message + * @param iterable $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1504,8 +1502,8 @@ public static function allWritable($value, $message = ''); /** * @psalm-assert null|class-string $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1514,8 +1512,8 @@ public static function nullOrClassExists($value, $message = ''); /** * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1552,8 +1550,8 @@ public static function allSubclassOf($value, $class, $message = ''); /** * @psalm-assert null|class-string $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1562,8 +1560,8 @@ public static function nullOrInterfaceExists($value, $message = ''); /** * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1575,9 +1573,9 @@ public static function allInterfaceExists($value, $message = ''); * @psalm-param class-string $interface * @psalm-assert null|class-string $value * - * @param mixed $value - * @param mixed $interface - * @param string $message + * @param mixed $value + * @param mixed $interface + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1589,9 +1587,9 @@ public static function nullOrImplementsInterface($value, $interface, $message = * @psalm-param class-string $interface * @psalm-assert iterable> $value * - * @param mixed $value - * @param mixed $interface - * @param string $message + * @param mixed $value + * @param mixed $interface + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1741,8 +1739,8 @@ public static function allKeyNotExists($array, $key, $message = ''); * @psalm-pure * @psalm-assert null|array-key $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1752,8 +1750,8 @@ public static function nullOrValidArrayKey($value, $message = ''); * @psalm-pure * @psalm-assert iterable $value * - * @param mixed $value - * @param string $message + * @param mixed $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1837,8 +1835,8 @@ public static function allCountBetween($array, $min, $max, $message = ''); * @psalm-pure * @psalm-assert null|list $array * - * @param mixed $array - * @param string $message + * @param mixed $array + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1848,8 +1846,8 @@ public static function nullOrIsList($array, $message = ''); * @psalm-pure * @psalm-assert iterable $array * - * @param mixed $array - * @param string $message + * @param mixed $array + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1859,8 +1857,8 @@ public static function allIsList($array, $message = ''); * @psalm-pure * @psalm-assert null|non-empty-list $array * - * @param mixed $array - * @param string $message + * @param mixed $array + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1870,8 +1868,8 @@ public static function nullOrIsNonEmptyList($array, $message = ''); * @psalm-pure * @psalm-assert iterable $array * - * @param mixed $array - * @param string $message + * @param mixed $array + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1883,8 +1881,8 @@ public static function allIsNonEmptyList($array, $message = ''); * @psalm-param null|mixed|array $array * @psalm-assert null|array $array * - * @param mixed $array - * @param string $message + * @param mixed $array + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1896,8 +1894,8 @@ public static function nullOrIsMap($array, $message = ''); * @psalm-param iterable> $array * @psalm-assert iterable> $array * - * @param mixed $array - * @param string $message + * @param mixed $array + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1908,8 +1906,8 @@ public static function allIsMap($array, $message = ''); * @psalm-template T * @psalm-param null|mixed|array $array * - * @param mixed $array - * @param string $message + * @param mixed $array + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1920,8 +1918,8 @@ public static function nullOrIsNonEmptyMap($array, $message = ''); * @psalm-template T * @psalm-param iterable> $array * - * @param mixed $array - * @param string $message + * @param mixed $array + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1930,8 +1928,8 @@ public static function allIsNonEmptyMap($array, $message = ''); /** * @psalm-pure * - * @param null|string $value - * @param string $message + * @param null|string $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ @@ -1940,8 +1938,8 @@ public static function nullOrUuid($value, $message = ''); /** * @psalm-pure * - * @param iterable $value - * @param string $message + * @param iterable $value + * @param string|callable():string $message * * @throws InvalidArgumentException */ diff --git a/tests/AssertTest.php b/tests/AssertTest.php index c1f708b9..e8f40938 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -718,6 +718,21 @@ public function testConvertValuesToStrings($method, $args, $exceptionMessage) call_user_func_array(array('Webmozart\Assert\Assert', $method), $args); } + public function testLazyExceptionMessage() + { + $exceptionMessage = 'Audax ususs ducunt ad historia.'; + + $isInit = false; + + $thunk = function () use ($exceptionMessage, &$isInit) { $isInit = true; return $exceptionMessage; }; + + Assert::string('', $thunk); + self::assertFalse($isInit); + + $this->setExpectedException('\InvalidArgumentException', $exceptionMessage); + Assert::string(null, $thunk); + } + public function testAnUnknownMethodThrowsABadMethodCall() { $this->setExpectedException('\BadMethodCallException');