webmozart/assert
webmozart/assert is a lightweight PHP assertion library for validating method input/output. It provides many type and value checks via a single Assert class and throws InvalidArgumentException with consistent, readable default error messages (or custom ones).
list* methods.instanceOf messagesisList type documentation.isAOf, isInstanceOf, etc type documentation.all* assertion values back to mixed.stringNotEmpty by internally using notSame.[@param](https://github.com/param) declaration for isMap.isTraversable, use isIterable or isInstanceOf instead.declare(strict_types=1) to all classes.notInArray and notOneOf.isInitialized, to check if a class property is initialized.negativeInteger and notNegativeIntegerisStatic and notStaticallNullOr* methods, with [@psalm-assert](https://github.com/psalm-assert) annotations, for better Psalm support.__callStaticisList will now deal correctly with (modified) lists that contain NaNreportInvalidArgument now has a return type of never.symfony/polyfill-ctype as a dependency, and require ext-ctype instead.
symfony/polyfill-ctype in your project if you need it, as it provides ext-ctypeWebmozart\Assert\InvalidArgumentExceptionAssert::positiveInteger()all*() and nullOr*() methods to improve psalm compatibility.all* & nullOr* methods[@psalm-pure](https://github.com/psalm-pure) annotation to Assert::notFalse()[@psalm-assert](https://github.com/psalm-assert) annotations where appropriateAssert::notStartsWith()Assert::notEndsWith()Assert::inArray()[@psalm-pure](https://github.com/psalm-pure) annotations to pure assertionsDateTime(Immutable) objects now display their date & time.Assert::count() now use the values to render the exception message.Assert::notFalse()Assert::isAOf()Assert::isAnyOf()Assert::isNotA()Assert::validArrayKey()Assert::isNonEmptyList()Assert::isNonEmptyMap()[@throws](https://github.com/throws) InvalidArgumentException annotations to all methods that throw.[@psalm-assert](https://github.com/psalm-assert) for the list type to the isList assertion.ResourceBundle & SimpleXMLElement now pass the isCountable assertions.
They are countable, without implementing the Countable interface.range now has the proper variables.isList and isMap. As it is a valid form of both.
If a non-empty variant is needed, use isNonEmptyList or isNonEmptyMap.Assert::uniqueValues()Assert::unicodeLetters()Assert::email()[@psalm-assert](https://github.com/psalm-assert) annotations where appropriate.Assert::endsWith() would not give the correct result when dealing with a multibyte suffix.Assert::length(), minLength, maxLength, lengthBetween would not give the correct result when dealing with multibyte characters.NOTE: These 2 changes may break your assertions if you relied on the fact that multibyte characters didn't behave correctly.
Assert::isTraversable() in favor of Assert::isIterable()
trigger_error. It is now annotated as well.Assert::ip()Assert::ipv4()Assert::ipv6()Assert::notRegex()Assert::interfaceExists()Assert::isList()Assert::isMap()__toString()Assert::minCount()Assert::maxCount()Assert::countBetween()Assert::isCountable()Assert::notWhitespaceOnly()Assert::natural()Assert::notContains()Assert::isArrayAccessible()Assert::isInstanceOfAny()Assert::isIterable()stringNotEmpty will no longer report "0" is an empty stringAssert::isTraversable() in favor of Assert::isIterable()Assert::throws()Assert::count()Assert::reportInvalidArgument() for custom subclassesAssert::object()Assert::propertyExists()Assert::propertyNotExists()Assert::methodExists()Assert::methodNotExists()Assert::uuid()all* & nullOr* methods are now declared on an interface, instead of [@method](https://github.com/method) annotations.
This interface is linked to the Assert class with a [@mixin](https://github.com/mixin) annotation. Most IDEs have supported this
for a long time, and you should not lose any autocompletion capabilities. PHPStan has supported this since
version 0.12.20. This package is marked incompatible (with a composer conflict) with phpstan version prior to that.
If you do not use PHPStan than this does not matter.void return type.How can I help you explore Laravel packages today?