code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public static function eq($value, $expect, $message = '') { if ($expect != $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value equal to %2$s. Got: %s', static::valueToString($value), static::valueToString($expect) )); } }
@param mixed $value @param mixed $expect @param string $message @throws InvalidArgumentException
eq
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function notEq($value, $expect, $message = '') { if ($expect == $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a different value than %s.', static::valueToString($expect) )); } }
@param mixed $value @param mixed $expect @param string $message @throws InvalidArgumentException
notEq
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function same($value, $expect, $message = '') { if ($expect !== $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value identical to %2$s. Got: %s', static::valueToString($value), static::valueToString($expect) )); } }
@psalm-pure @param mixed $value @param mixed $expect @param string $message @throws InvalidArgumentException
same
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function notSame($value, $expect, $message = '') { if ($expect === $value) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value not identical to %s.', static::valueToString($expect) )); } }
@psalm-pure @param mixed $value @param mixed $expect @param string $message @throws InvalidArgumentException
notSame
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function range($value, $min, $max, $message = '') { if ($value < $min || $value > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value between %2$s and %3$s. Got: %s', static::valueToString($value), static::valueToString($min), static::valueToString($max) )); } }
Inclusive range, so Assert::(3, 3, 5) passes. @psalm-pure @param mixed $value @param mixed $min @param mixed $max @param string $message @throws InvalidArgumentException
range
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function oneOf($value, array $values, $message = '') { static::inArray($value, $values, $message); }
A more human-readable alias of Assert::inArray(). @psalm-pure @param mixed $value @param array $values @param string $message @throws InvalidArgumentException
oneOf
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function inArray($value, array $values, $message = '') { if (!\in_array($value, $values, true)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected one of: %2$s. Got: %s', static::valueToString($value), \implode(', ', \array_map(array(static::class, 'valueToString'), $values)) )); } }
Does strict comparison, so Assert::inArray(3, ['3']) does not pass the assertion. @psalm-pure @param mixed $value @param array $values @param string $message @throws InvalidArgumentException
inArray
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function contains($value, $subString, $message = '') { if (false === \strpos($value, $subString)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain %2$s. Got: %s', static::valueToString($value), static::valueToString($subString) )); } }
@psalm-pure @param string $value @param string $subString @param string $message @throws InvalidArgumentException
contains
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function notContains($value, $subString, $message = '') { if (false !== \strpos($value, $subString)) { static::reportInvalidArgument(\sprintf( $message ?: '%2$s was not expected to be contained in a value. Got: %s', static::valueToString($value), static::valueToString($subString) )); } }
@psalm-pure @param string $value @param string $subString @param string $message @throws InvalidArgumentException
notContains
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function notWhitespaceOnly($value, $message = '') { if (\preg_match('/^\s*$/', $value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a non-whitespace string. Got: %s', static::valueToString($value) )); } }
@psalm-pure @param string $value @param string $message @throws InvalidArgumentException
notWhitespaceOnly
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function startsWith($value, $prefix, $message = '') { if (0 !== \strpos($value, $prefix)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to start with %2$s. Got: %s', static::valueToString($value), static::valueToString($prefix) )); } }
@psalm-pure @param string $value @param string $prefix @param string $message @throws InvalidArgumentException
startsWith
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function notStartsWith($value, $prefix, $message = '') { if (0 === \strpos($value, $prefix)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value not to start with %2$s. Got: %s', static::valueToString($value), static::valueToString($prefix) )); } }
@psalm-pure @param string $value @param string $prefix @param string $message @throws InvalidArgumentException
notStartsWith
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function startsWithLetter($value, $message = '') { static::string($value); $valid = isset($value[0]); if ($valid) { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = \ctype_alpha($value[0]); \setlocale(LC_CTYPE, $locale); } if (!$valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to start with a letter. Got: %s', static::valueToString($value) )); } }
@psalm-pure @param mixed $value @param string $message @throws InvalidArgumentException
startsWithLetter
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function endsWith($value, $suffix, $message = '') { if ($suffix !== \substr($value, -\strlen($suffix))) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to end with %2$s. Got: %s', static::valueToString($value), static::valueToString($suffix) )); } }
@psalm-pure @param string $value @param string $suffix @param string $message @throws InvalidArgumentException
endsWith
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function notEndsWith($value, $suffix, $message = '') { if ($suffix === \substr($value, -\strlen($suffix))) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value not to end with %2$s. Got: %s', static::valueToString($value), static::valueToString($suffix) )); } }
@psalm-pure @param string $value @param string $suffix @param string $message @throws InvalidArgumentException
notEndsWith
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function regex($value, $pattern, $message = '') { if (!\preg_match($pattern, $value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The value %s does not match the expected pattern.', static::valueToString($value) )); } }
@psalm-pure @param string $value @param string $pattern @param string $message @throws InvalidArgumentException
regex
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function notRegex($value, $pattern, $message = '') { if (\preg_match($pattern, $value, $matches, PREG_OFFSET_CAPTURE)) { static::reportInvalidArgument(\sprintf( $message ?: 'The value %s matches the pattern %s (at offset %d).', static::valueToString($value), static::valueToString($pattern), $matches[0][1] )); } }
@psalm-pure @param string $value @param string $pattern @param string $message @throws InvalidArgumentException
notRegex
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function unicodeLetters($value, $message = '') { static::string($value); if (!\preg_match('/^\p{L}+$/u', $value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain only Unicode letters. Got: %s', static::valueToString($value) )); } }
@psalm-pure @param mixed $value @param string $message @throws InvalidArgumentException
unicodeLetters
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function alpha($value, $message = '') { static::string($value); $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_alpha($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain only letters. Got: %s', static::valueToString($value) )); } }
@psalm-pure @param mixed $value @param string $message @throws InvalidArgumentException
alpha
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function digits($value, $message = '') { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_digit($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain digits only. Got: %s', static::valueToString($value) )); } }
@psalm-pure @param string $value @param string $message @throws InvalidArgumentException
digits
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function alnum($value, $message = '') { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_alnum($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain letters and digits only. Got: %s', static::valueToString($value) )); } }
@psalm-pure @param string $value @param string $message @throws InvalidArgumentException
alnum
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function lower($value, $message = '') { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_lower($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain lowercase characters only. Got: %s', static::valueToString($value) )); } }
@psalm-pure @psalm-assert lowercase-string $value @param string $value @param string $message @throws InvalidArgumentException
lower
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function upper($value, $message = '') { $locale = \setlocale(LC_CTYPE, 0); \setlocale(LC_CTYPE, 'C'); $valid = !\ctype_upper($value); \setlocale(LC_CTYPE, $locale); if ($valid) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain uppercase characters only. Got: %s', static::valueToString($value) )); } }
@psalm-pure @psalm-assert !lowercase-string $value @param string $value @param string $message @throws InvalidArgumentException
upper
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function length($value, $length, $message = '') { if ($length !== static::strlen($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain %2$s characters. Got: %s', static::valueToString($value), $length )); } }
@psalm-pure @param string $value @param int $length @param string $message @throws InvalidArgumentException
length
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function minLength($value, $min, $message = '') { if (static::strlen($value) < $min) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', static::valueToString($value), $min )); } }
Inclusive min. @psalm-pure @param string $value @param int|float $min @param string $message @throws InvalidArgumentException
minLength
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function maxLength($value, $max, $message = '') { if (static::strlen($value) > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', static::valueToString($value), $max )); } }
Inclusive max. @psalm-pure @param string $value @param int|float $max @param string $message @throws InvalidArgumentException
maxLength
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function lengthBetween($value, $min, $max, $message = '') { $length = static::strlen($value); if ($length < $min || $length > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a value to contain between %2$s and %3$s characters. Got: %s', static::valueToString($value), $min, $max )); } }
Inclusive , so Assert::lengthBetween('asd', 3, 5); passes the assertion. @psalm-pure @param string $value @param int|float $min @param int|float $max @param string $message @throws InvalidArgumentException
lengthBetween
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function fileExists($value, $message = '') { if (!\file_exists($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The path %s does not exist.', static::valueToString($value) )); } }
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 @throws InvalidArgumentException
fileExists
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function file($value, $message = '') { if (!\is_file($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The path %s is not a file.', static::valueToString($value) )); } }
@param mixed $value @param string $message @throws InvalidArgumentException
file
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function directory($value, $message = '') { if (!\is_dir($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The path %s is not a directory.', static::valueToString($value) )); } }
@param mixed $value @param string $message @throws InvalidArgumentException
directory
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function readable($value, $message = '') { if (!\is_readable($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The path %s is not readable.', static::valueToString($value) )); } }
@param string $value @param string $message @throws InvalidArgumentException
readable
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function writable($value, $message = '') { if (!\is_writable($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'The path %s is not writable.', static::valueToString($value) )); } }
@param string $value @param string $message @throws InvalidArgumentException
writable
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function classExists($value, $message = '') { if (!\class_exists($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an existing class name. Got: %s', static::valueToString($value) )); } }
@psalm-assert class-string $value @param mixed $value @param string $message @throws InvalidArgumentException
classExists
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function subclassOf($value, $class, $message = '') { if (!\is_subclass_of($value, $class)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a sub-class of %2$s. Got: %s', static::valueToString($value), static::valueToString($class) )); } }
@psalm-pure @psalm-template ExpectedType of object @psalm-param class-string<ExpectedType> $class @psalm-assert class-string<ExpectedType>|ExpectedType $value @param mixed $value @param string|object $class @param string $message @throws InvalidArgumentException
subclassOf
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function interfaceExists($value, $message = '') { if (!\interface_exists($value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an existing interface name. got %s', static::valueToString($value) )); } }
@psalm-assert class-string $value @param mixed $value @param string $message @throws InvalidArgumentException
interfaceExists
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function implementsInterface($value, $interface, $message = '') { if (!\in_array($interface, \class_implements($value))) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an implementation of %2$s. Got: %s', static::valueToString($value), static::valueToString($interface) )); } }
@psalm-pure @psalm-template ExpectedType of object @psalm-param class-string<ExpectedType> $interface @psalm-assert class-string<ExpectedType>|ExpectedType $value @param mixed $value @param mixed $interface @param string $message @throws InvalidArgumentException
implementsInterface
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function propertyExists($classOrObject, $property, $message = '') { if (!\property_exists($classOrObject, $property)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the property %s to exist.', static::valueToString($property) )); } }
@psalm-pure @psalm-param class-string|object $classOrObject @param string|object $classOrObject @param mixed $property @param string $message @throws InvalidArgumentException
propertyExists
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function propertyNotExists($classOrObject, $property, $message = '') { if (\property_exists($classOrObject, $property)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the property %s to not exist.', static::valueToString($property) )); } }
@psalm-pure @psalm-param class-string|object $classOrObject @param string|object $classOrObject @param mixed $property @param string $message @throws InvalidArgumentException
propertyNotExists
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function methodExists($classOrObject, $method, $message = '') { if (!(\is_string($classOrObject) || \is_object($classOrObject)) || !\method_exists($classOrObject, $method)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the method %s to exist.', static::valueToString($method) )); } }
@psalm-pure @psalm-param class-string|object $classOrObject @param string|object $classOrObject @param mixed $method @param string $message @throws InvalidArgumentException
methodExists
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function methodNotExists($classOrObject, $method, $message = '') { if ((\is_string($classOrObject) || \is_object($classOrObject)) && \method_exists($classOrObject, $method)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the method %s to not exist.', static::valueToString($method) )); } }
@psalm-pure @psalm-param class-string|object $classOrObject @param string|object $classOrObject @param mixed $method @param string $message @throws InvalidArgumentException
methodNotExists
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function keyExists($array, $key, $message = '') { if (!(isset($array[$key]) || \array_key_exists($key, $array))) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the key %s to exist.', static::valueToString($key) )); } }
@psalm-pure @param array $array @param string|int $key @param string $message @throws InvalidArgumentException
keyExists
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function keyNotExists($array, $key, $message = '') { if (isset($array[$key]) || \array_key_exists($key, $array)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the key %s to not exist.', static::valueToString($key) )); } }
@psalm-pure @param array $array @param string|int $key @param string $message @throws InvalidArgumentException
keyNotExists
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
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) )); } }
Checks if a value is a valid array key (int or string). @psalm-pure @psalm-assert array-key $value @param mixed $value @param string $message @throws InvalidArgumentException
validArrayKey
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function count($array, $number, $message = '') { static::eq( \count($array), $number, \sprintf( $message ?: 'Expected an array to contain %d elements. Got: %d.', $number, \count($array) ) ); }
Does not check if $array is countable, this can generate a warning on php versions after 7.2. @param Countable|array $array @param int $number @param string $message @throws InvalidArgumentException
count
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function minCount($array, $min, $message = '') { if (\count($array) < $min) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an array to contain at least %2$d elements. Got: %d', \count($array), $min )); } }
Does not check if $array is countable, this can generate a warning on php versions after 7.2. @param Countable|array $array @param int|float $min @param string $message @throws InvalidArgumentException
minCount
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function maxCount($array, $max, $message = '') { if (\count($array) > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an array to contain at most %2$d elements. Got: %d', \count($array), $max )); } }
Does not check if $array is countable, this can generate a warning on php versions after 7.2. @param Countable|array $array @param int|float $max @param string $message @throws InvalidArgumentException
maxCount
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function countBetween($array, $min, $max, $message = '') { $count = \count($array); if ($count < $min || $count > $max) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected an array to contain between %2$d and %3$d elements. Got: %d', $count, $min, $max )); } }
Does not check if $array is countable, this can generate a warning on php versions after 7.2. @param Countable|array $array @param int|float $min @param int|float $max @param string $message @throws InvalidArgumentException
countBetween
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function isList($array, $message = '') { if (!\is_array($array)) { static::reportInvalidArgument( $message ?: 'Expected list - non-associative array.' ); } if (\function_exists('array_is_list')) { if (!\array_is_list($array)) { static::reportInvalidArgument( $message ?: 'Expected list - non-associative array.' ); } return; } if (array() === $array) { return; } $keys = array_keys($array); if (array_keys($keys) !== $keys) { static::reportInvalidArgument( $message ?: 'Expected list - non-associative array.' ); } }
@psalm-pure @psalm-assert list $array @param mixed $array @param string $message @throws InvalidArgumentException
isList
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function isNonEmptyList($array, $message = '') { static::isList($array, $message); static::notEmpty($array, $message); }
@psalm-pure @psalm-assert non-empty-list $array @param mixed $array @param string $message @throws InvalidArgumentException
isNonEmptyList
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function isMap($array, $message = '') { if ( !\is_array($array) || \array_keys($array) !== \array_filter(\array_keys($array), '\is_string') ) { static::reportInvalidArgument( $message ?: 'Expected map - associative array with string keys.' ); } }
@psalm-pure @psalm-template T @psalm-param mixed|array<T> $array @psalm-assert array<string, T> $array @param mixed $array @param string $message @throws InvalidArgumentException
isMap
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function isNonEmptyMap($array, $message = '') { static::isMap($array, $message); static::notEmpty($array, $message); }
@psalm-pure @psalm-template T @psalm-param mixed|array<T> $array @psalm-assert array<string, T> $array @psalm-assert !empty $array @param mixed $array @param string $message @throws InvalidArgumentException
isNonEmptyMap
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function uuid($value, $message = '') { $value = \str_replace(array('urn:', 'uuid:', '{', '}'), '', $value); // The nil UUID is special form of UUID that is specified to have all // 128 bits set to zero. if ('00000000-0000-0000-0000-000000000000' === $value) { return; } if (!\preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $value)) { static::reportInvalidArgument(\sprintf( $message ?: 'Value %s is not a valid UUID.', static::valueToString($value) )); } }
@psalm-pure @param string $value @param string $message @throws InvalidArgumentException
uuid
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function throws(Closure $expression, $class = 'Exception', $message = '') { static::string($class); $actual = 'none'; try { $expression(); } catch (Exception $e) { $actual = \get_class($e); if ($e instanceof $class) { return; } } catch (Throwable $e) { $actual = \get_class($e); if ($e instanceof $class) { return; } } static::reportInvalidArgument($message ?: \sprintf( 'Expected to throw "%s", got "%s"', $class, $actual )); }
@psalm-param class-string<Throwable> $class @param Closure $expression @param string $class @param string $message @throws InvalidArgumentException
throws
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
protected static function typeToString($value) { return \is_object($value) ? \get_class($value) : \gettype($value); }
@psalm-pure @param mixed $value @return string
typeToString
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
protected static function reportInvalidArgument($message) { throw new InvalidArgumentException($message); }
@param string $message @throws InvalidArgumentException @psalm-pure this method is not supposed to perform side-effects @psalm-return never
reportInvalidArgument
php
webmozarts/assert
src/Assert.php
https://github.com/webmozarts/assert/blob/master/src/Assert.php
MIT
public static function nullOrString($value, $message = '') { null === $value || static::string($value, $message); }
@psalm-pure @psalm-assert string|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrString
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allString($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::string($entry, $message); } }
@psalm-pure @psalm-assert iterable<string> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allString
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrString($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::string($entry, $message); } }
@psalm-pure @psalm-assert iterable<string|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrString
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrStringNotEmpty($value, $message = '') { null === $value || static::stringNotEmpty($value, $message); }
@psalm-pure @psalm-assert non-empty-string|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrStringNotEmpty
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allStringNotEmpty($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::stringNotEmpty($entry, $message); } }
@psalm-pure @psalm-assert iterable<non-empty-string> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allStringNotEmpty
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrStringNotEmpty($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::stringNotEmpty($entry, $message); } }
@psalm-pure @psalm-assert iterable<non-empty-string|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrStringNotEmpty
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrInteger($value, $message = '') { null === $value || static::integer($value, $message); }
@psalm-pure @psalm-assert int|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrInteger
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allInteger($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::integer($entry, $message); } }
@psalm-pure @psalm-assert iterable<int> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allInteger
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrInteger($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::integer($entry, $message); } }
@psalm-pure @psalm-assert iterable<int|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrInteger
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrIntegerish($value, $message = '') { null === $value || static::integerish($value, $message); }
@psalm-pure @psalm-assert numeric|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrIntegerish
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allIntegerish($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::integerish($entry, $message); } }
@psalm-pure @psalm-assert iterable<numeric> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allIntegerish
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrIntegerish($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::integerish($entry, $message); } }
@psalm-pure @psalm-assert iterable<numeric|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrIntegerish
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrPositiveInteger($value, $message = '') { null === $value || static::positiveInteger($value, $message); }
@psalm-pure @psalm-assert positive-int|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrPositiveInteger
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allPositiveInteger($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::positiveInteger($entry, $message); } }
@psalm-pure @psalm-assert iterable<positive-int> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allPositiveInteger
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrPositiveInteger($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::positiveInteger($entry, $message); } }
@psalm-pure @psalm-assert iterable<positive-int|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrPositiveInteger
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrFloat($value, $message = '') { null === $value || static::float($value, $message); }
@psalm-pure @psalm-assert float|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrFloat
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allFloat($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::float($entry, $message); } }
@psalm-pure @psalm-assert iterable<float> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allFloat
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrFloat($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::float($entry, $message); } }
@psalm-pure @psalm-assert iterable<float|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrFloat
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrNumeric($value, $message = '') { null === $value || static::numeric($value, $message); }
@psalm-pure @psalm-assert numeric|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrNumeric
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNumeric($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::numeric($entry, $message); } }
@psalm-pure @psalm-assert iterable<numeric> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNumeric
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrNumeric($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::numeric($entry, $message); } }
@psalm-pure @psalm-assert iterable<numeric|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrNumeric
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrNatural($value, $message = '') { null === $value || static::natural($value, $message); }
@psalm-pure @psalm-assert positive-int|0|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrNatural
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNatural($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::natural($entry, $message); } }
@psalm-pure @psalm-assert iterable<positive-int|0> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNatural
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrNatural($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::natural($entry, $message); } }
@psalm-pure @psalm-assert iterable<positive-int|0|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrNatural
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrBoolean($value, $message = '') { null === $value || static::boolean($value, $message); }
@psalm-pure @psalm-assert bool|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrBoolean
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allBoolean($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::boolean($entry, $message); } }
@psalm-pure @psalm-assert iterable<bool> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allBoolean
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrBoolean($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::boolean($entry, $message); } }
@psalm-pure @psalm-assert iterable<bool|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrBoolean
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrScalar($value, $message = '') { null === $value || static::scalar($value, $message); }
@psalm-pure @psalm-assert scalar|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrScalar
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allScalar($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::scalar($entry, $message); } }
@psalm-pure @psalm-assert iterable<scalar> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allScalar
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrScalar($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::scalar($entry, $message); } }
@psalm-pure @psalm-assert iterable<scalar|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrScalar
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrObject($value, $message = '') { null === $value || static::object($value, $message); }
@psalm-pure @psalm-assert object|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrObject
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allObject($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::object($entry, $message); } }
@psalm-pure @psalm-assert iterable<object> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allObject
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrObject($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::object($entry, $message); } }
@psalm-pure @psalm-assert iterable<object|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrObject
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrResource($value, $type = null, $message = '') { null === $value || static::resource($value, $type, $message); }
@psalm-pure @psalm-assert resource|null $value @param mixed $value @param string|null $type type of resource this should be. @see https://www.php.net/manual/en/function.get-resource-type.php @param string $message @return void @throws InvalidArgumentException
nullOrResource
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allResource($value, $type = null, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::resource($entry, $type, $message); } }
@psalm-pure @psalm-assert iterable<resource> $value @param mixed $value @param string|null $type type of resource this should be. @see https://www.php.net/manual/en/function.get-resource-type.php @param string $message @return void @throws InvalidArgumentException
allResource
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrResource($value, $type = null, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::resource($entry, $type, $message); } }
@psalm-pure @psalm-assert iterable<resource|null> $value @param mixed $value @param string|null $type type of resource this should be. @see https://www.php.net/manual/en/function.get-resource-type.php @param string $message @return void @throws InvalidArgumentException
allNullOrResource
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrIsCallable($value, $message = '') { null === $value || static::isCallable($value, $message); }
@psalm-pure @psalm-assert callable|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrIsCallable
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allIsCallable($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::isCallable($entry, $message); } }
@psalm-pure @psalm-assert iterable<callable> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allIsCallable
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrIsCallable($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::isCallable($entry, $message); } }
@psalm-pure @psalm-assert iterable<callable|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrIsCallable
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrIsArray($value, $message = '') { null === $value || static::isArray($value, $message); }
@psalm-pure @psalm-assert array|null $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrIsArray
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allIsArray($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::isArray($entry, $message); } }
@psalm-pure @psalm-assert iterable<array> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allIsArray
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrIsArray($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::isArray($entry, $message); } }
@psalm-pure @psalm-assert iterable<array|null> $value @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrIsArray
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function nullOrIsTraversable($value, $message = '') { null === $value || static::isTraversable($value, $message); }
@psalm-pure @psalm-assert iterable|null $value @deprecated use "isIterable" or "isInstanceOf" instead @param mixed $value @param string $message @return void @throws InvalidArgumentException
nullOrIsTraversable
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allIsTraversable($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { static::isTraversable($entry, $message); } }
@psalm-pure @psalm-assert iterable<iterable> $value @deprecated use "isIterable" or "isInstanceOf" instead @param mixed $value @param string $message @return void @throws InvalidArgumentException
allIsTraversable
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT
public static function allNullOrIsTraversable($value, $message = '') { static::isIterable($value); foreach ($value as $entry) { null === $entry || static::isTraversable($entry, $message); } }
@psalm-pure @psalm-assert iterable<iterable|null> $value @deprecated use "isIterable" or "isInstanceOf" instead @param mixed $value @param string $message @return void @throws InvalidArgumentException
allNullOrIsTraversable
php
webmozarts/assert
src/Mixin.php
https://github.com/webmozarts/assert/blob/master/src/Mixin.php
MIT