# Assert

## Installation

```shell
composer require sonsofphp/assert
```

## Usage

```php
<?php

use SonsOfPHP\Component\Assert\Assert;
use SonsOfPHP\Component\Assert\InvalidArgumentException;

$data = 'test';
Assert::string($data);

// @throws InvalidArgumentException
Assert::int($data);

// Disable exceptions
Assert::disable();

// @return bool
Assert::int($data);

// Re-enable exceptions
Assert::enable();
```

## Assertions

```php
Assert::array($value);
Assert::bool($value);
Assert::callable($value);
Assert::empty($value);
Assert::eq($value, $value2);
Assert::false($value);
Assert::float($value);
Assert::int($value);
Assert::null($value);
Assert::numeric($value);
Assert::object($value);
Assert::resource($value);
Assert::same($value, $value2);
Assert::scalar($value);
Assert::string($value);
Assert::true($value);
```

## Magic Assertions

```php
// "all"
// Throws exception if any value in $values is not the correct type
Assert::allString($values);
Assert::allString(['one', 'two', 3]); // Throws Exception

// "not"
// Throws exception if $value is the type
Assert::notString($value);
Assert::notString('opps'); // Throws Exception

// "nullOr"
// Throws exception if $value is not null or not type
Assert::nullOrString($value);
Assert::nullOrString(42); // Throws Exception
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonsofphp.com/components/assert.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
