Assert helper, throws exceptions.
Download a latest package or use Composer:
composer require czproject/assert
CzProject\Assert requires PHP 8.0 or later.
useCzProject\Assert\Assert;
functionadd($a, $b)
{
Assert::int($a);
Assert::int($b);
return$a + $b;
}assert($value, $msg = NULL)- checks if value isTRUEbool($value, $msg = NULL)- checks if value isboolint($value, $msg = NULL)- checks if value isintintOrNull($value, $msg = NULL)- checks if value isint|NULLfloat($value, $msg = NULL)- checks if value isfloatfloatOrNull($value, $msg = NULL)- checks if value isfloat|NULLnumber($value, $msg = NULL)- checks if value isfloat|intnumberOrNull($value, $msg = NULL)- checks if value isfloat|int|NULLstring($value, $msg = NULL)- checks if value isstringstringOrNull($value, $msg = NULL)- checks if value isstring|NULLtype($value, $type, $msg = NULL)- checks if value is instance of given typetypeOrNull($value, $type, $msg = NULL)- checks if value is instance of given type orNULLnull($value, $msg = NULL)- checks if value isNULLin($value, $arr, $msg = NULL)- checks if value is in arrayinArray($value, $arr, $msg = NULL)- alias forAssert::in()
services:-class:CzProject\Assert\Bridges\PhpStan\StaticMethodTypeSpecifyingExtensiontags:- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtensionLicense: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/