https://github.com/czproject/assert
Assert helper.
https://github.com/czproject/assert
assert assertions php
Last synced: 12 months ago
JSON representation
Assert helper.
- Host: GitHub
- URL: https://github.com/czproject/assert
- Owner: czproject
- License: other
- Created: 2017-08-22T15:22:30.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2025-07-02T09:00:52.000Z (about 1 year ago)
- Last Synced: 2025-07-22T08:55:10.887Z (about 1 year ago)
- Topics: assert, assertions, php
- Language: PHP
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license.md
Awesome Lists containing this project
README
# CzProject\Assert
[](https://github.com/czproject/assert/actions)
[](https://packagist.org/packages/czproject/assert)
[](https://github.com/czproject/assert/releases)
[](https://github.com/czproject/assert/blob/master/license.md)
Assert helper, throws exceptions.
## Installation
[Download a latest package](https://github.com/czproject/assert/releases) or use [Composer](http://getcomposer.org/):
```
composer require czproject/assert
```
`CzProject\Assert` requires PHP 8.0 or later.
## Usage
``` php
use CzProject\Assert\Assert;
function add($a, $b)
{
Assert::int($a);
Assert::int($b);
return $a + $b;
}
```
* `assert($value, $msg = NULL)` - checks if value is `TRUE`
* `bool($value, $msg = NULL)` - checks if value is `bool`
* `int($value, $msg = NULL)` - checks if value is `int`
* `intOrNull($value, $msg = NULL)` - checks if value is `int|NULL`
* `float($value, $msg = NULL)` - checks if value is `float`
* `floatOrNull($value, $msg = NULL)` - checks if value is `float|NULL`
* `number($value, $msg = NULL)` - checks if value is `float|int`
* `numberOrNull($value, $msg = NULL)` - checks if value is `float|int|NULL`
* `string($value, $msg = NULL)` - checks if value is `string`
* `stringOrNull($value, $msg = NULL)` - checks if value is `string|NULL`
* `type($value, $type, $msg = NULL)` - checks if value is instance of given type
* `typeOrNull($value, $type, $msg = NULL)` - checks if value is instance of given type or `NULL`
* `null($value, $msg = NULL)` - checks if value is `NULL`
* `in($value, $arr, $msg = NULL)` - checks if value is in array
* `inArray($value, $arr, $msg = NULL)` - alias for `Assert::in()`
## PhpStan extension
```neon
services:
-
class: CzProject\Assert\Bridges\PhpStan\StaticMethodTypeSpecifyingExtension
tags:
- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension
```
------------------------------
License: [New BSD License](license.md)
Author: Jan Pecha, https://www.janpecha.cz/