Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpstan Beberlei Assert Laravel Package

phpstan/phpstan-beberlei-assert

PHPStan extension for beberlei/assert. Adds improved static analysis and type inference for Assert::that and related assertions, helping PHPStan understand refined types after checks and reducing false positives in codebases using beberlei/assert.

View on GitHub
Deep Wiki
Context7

PHPStan beberlei/assert extension

Build Latest Stable Version License

Description

The main scope of this extension is to help PHPStan to detect the type of object after the Assert\Assertion validation.

<?php declare(strict_types = 1);
use Assert\Assertion;

function demo(?int $a) {
	// ...

	Assertion::integer($a);
	// PHPStan is now aware that $a can no longer be `null` at this point

	return ($a === 10);
}

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:

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:

/** @var mixed[] $values */
Assertion::allInteger($values);
// $values is array<int>

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:

Assert::that($value)->string();
Assert::that($value)->nullOr()->string(); // string|null
Assert::thatNullOr($value)->string();     // string|null
Assert::that($values)->all()->string();   // array<string>
Assert::thatAll($values)->string();       // array<string>

The function-style API (Assert\that(), Assert\thatNullOr(), Assert\thatAll()) is also supported.

Installation

To use this extension, require it in Composer:

composer require --dev phpstan/phpstan-beberlei-assert

If you also install phpstan/extension-installer then you're all set!

If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:

includes:
    - vendor/phpstan/phpstan-beberlei-assert/extension.neon
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
ilhamsyabani/laravel-volt-starter
thethunderturner/filament-latex
ghostcompiler/laravel-querybuilder
webrek/laravel-telescope-mongodb
anousss007/blatui
zatona-eg/zatona-eg-api
cocosmos/filament-sticky-save-bar
patrickbussmann/oauth2-apple
3brs/enterprise-security-bundle
anousss007/vigilance
supportpal/eloquent-model
ardenexal/fhir-models
laravel-at/laravel-image-sanitize
romalytar/yammi-audit-log-laravel
ardenexal/fhir-validation
arshaviras/weather-widget
laravel-chronicle/core
sunchayn/nimbus
daikazu/eloquent-salesforce-objects
unseen-codes/chat