From 816594a732bac4996b6ff22dcb0c0467eb3c6728 Mon Sep 17 00:00:00 2001 From: phpstan-bot Date: Thu, 19 Feb 2026 11:54:35 +0000 Subject: [PATCH] Document supported assertions, prefixes, and chain API in README The README only showed a basic example with Assertion::integer(). Added a "Supported Assertions" section covering: - All 28 supported assertion methods - nullOr* prefix for nullable type narrowing - all* and allNot* prefixes for array/iterable narrowing - Fluent chain API (Assert::that(), ->nullOr(), ->all()) - Function-style API (Assert\that(), Assert\thatNullOr(), Assert\thatAll()) Co-Authored-By: Claude Opus 4.6 --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index e71282b..6111236 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,47 @@ function demo(?int $a) { } ``` +## Supported Assertions + +This extension understands the following `Assertion` static methods and narrows types accordingly: + +`integer`, `string`, `float`, `numeric`, `boolean`, `scalar`, `objectOrClass`, `isResource`, `isCallable`, `isArray`, `isInstanceOf`, `notIsInstanceOf`, `true`, `false`, `null`, `notNull`, `same`, `notSame`, `subclassOf`, `integerish`, `keyExists`, `keyNotExists`, `propertyExists`, `methodExists`, `classExists`, `interfaceExists`, `notBlank`, `isJsonString` + +### `nullOr*` Prefix + +Every supported assertion can be prefixed with `nullOr` to accept `null` in addition to the asserted type: + +```php +Assertion::nullOrString($value); +// $value is string|null +``` + +### `all*` Prefix + +Every supported assertion can be prefixed with `all` to narrow the item type of arrays and iterables: + +```php +/** @var mixed[] $values */ +Assertion::allInteger($values); +// $values is array +``` + +The `allNot*` prefix is also supported for `allNotNull`, `allNotIsInstanceOf`, `allNotSame`, and `allNotBlank`. + +### Fluent Chain API + +The extension supports `Assert::that()` chains including `->nullOr()` and `->all()` modifiers: + +```php +Assert::that($value)->string(); +Assert::that($value)->nullOr()->string(); // string|null +Assert::thatNullOr($value)->string(); // string|null +Assert::that($values)->all()->string(); // array +Assert::thatAll($values)->string(); // array +``` + +The function-style API (`Assert\that()`, `Assert\thatNullOr()`, `Assert\thatAll()`) is also supported. + ## Installation To use this extension, require it in [Composer](https://getcomposer.org/):