Assert helper, throws exceptions.
Download a latest package or use Composer:
composer require czproject/assert
CzProject\Assert
requires PHP 5.6.0 or later.
use CzProject\Assert\Assert;
function add($a, $b)
{
Assert::int($a);
Assert::int($b);
return $a + $b;
}
assert($value, $msg = NULL)
- checks if value isTRUE
bool($value, $msg = NULL)
- checks if value isbool
int($value, $msg = NULL)
- checks if value isint
intOrNull($value, $msg = NULL)
- checks if value isint|NULL
float($value, $msg = NULL)
- checks if value isfloat
floatOrNull($value, $msg = NULL)
- checks if value isfloat|NULL
number($value, $msg = NULL)
- checks if value isfloat|int
numberOrNull($value, $msg = NULL)
- checks if value isfloat|int|NULL
string($value, $msg = NULL)
- checks if value isstring
stringOrNull($value, $msg = NULL)
- checks if value isstring|NULL
type($value, $type, $msg = NULL)
- checks if value is instance of given typetypeOrNull($value, $type, $msg = NULL)
- checks if value is instance of given type orNULL
null($value, $msg = NULL)
- checks if value isNULL
in($value, $arr, $msg = NULL)
- checks if value is in arrayinArray($value, $arr, $msg = NULL)
- alias forAssert::in()
services:
-
class: CzProject\Assert\Bridges\PhpStan\StaticMethodTypeSpecifyingExtension
tags:
- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension
License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/