phpstan / phpstan-webmozart-assert
PHPStan webmozart/assert extension
Installs: 24 373 680
Dependents: 929
Suggesters: 1
Security: 0
Stars: 183
Watchers: 5
Forks: 32
Open Issues: 8
Type:phpstan-extension
pkg:composer/phpstan/phpstan-webmozart-assert
Requires
- php: ^7.4 || ^8.0
- phpstan/phpstan: ^2.0
Requires (Dev)
- nikic/php-parser: ^5.1
- php-parallel-lint/php-parallel-lint: ^1.2
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^9.6
- webmozart/assert: ^1.11.0
- 2.0.x-dev
- 2.0.0
- 1.2.x-dev
- 1.2.11
- 1.2.10
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.12.16
- 0.12.15
- 0.12.14
- 0.12.13
- 0.12.12
- 0.12.11
- 0.12.10
- 0.12.9
- 0.12.8
- 0.12.7
- 0.12.6
- 0.12.5
- 0.12.4
- 0.12.3
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.3
- 0.11.2
- 0.11.1
- 0.11
- 0.10
- dev-lint-workflows
- dev-readme-supported-assertions
- dev-react-on-issue-opened
- dev-add-php-85-to-ci
- dev-gitattributes-export-ignore
- dev-add-claude-md
- dev-renovate/major-github-actions
- dev-renovate/major-root-composer
This package is auto-updated.
Last update: 2026-02-24 20:35:01 UTC
README
Description
The main scope of this extension is to help PHPStan to detect the type of object after the Webmozart\Assert\Assert validation.
<?php declare(strict_types = 1); use Webmozart\Assert\Assert; function demo(?int $a) { // ... Assert::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 Assert::* methods and narrows types accordingly.
All assertions also work with the nullOr*(), all*(), and allNullOr*() prefixes (e.g. Assert::nullOrString(), Assert::allInteger(), Assert::allNullOrNotEmpty()).
Type checks
integer, positiveInteger, natural, float, numeric, integerish, boolean, scalar, string, stringNotEmpty, object, resource, isCallable, isArray, isIterable, isTraversable, isList, isNonEmptyList, isMap, isNonEmptyMap, isCountable, isArrayAccessible
Instance and class checks
isInstanceOf, isInstanceOfAny, notInstanceOf, isAOf, isAnyOf, isNotA, subclassOf, implementsInterface, classExists, interfaceExists
Comparison
same, notSame, eq, notEq, greaterThan, greaterThanEq, lessThan, lessThanEq, range, true, false, null, notNull, notFalse, inArray, oneOf
String assertions
contains, startsWith, endsWith, startsWithLetter, unicodeLetters, alpha, digits, alnum, lower, upper, uuid, ip, ipv4, ipv6, email, notWhitespaceOnly, length, minLength, maxLength, lengthBetween
Count assertions
count, minCount, maxCount, countBetween
Object and array
keyExists, keyNotExists, validArrayKey, methodExists, propertyExists
Negative all* assertions
allNotNull, allNotInstanceOf, allNotSame
Installation
To use this extension, require it in Composer:
composer require --dev phpstan/phpstan-webmozart-assert
If you also install phpstan/extension-installer then you're all set!
Manual installation
If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:
includes:
- vendor/phpstan/phpstan-webmozart-assert/extension.neon