php-standard-library/phpstan-extension

PHPStan PSL extension

Package info

github.com/php-standard-library/phpstan-extension

Type:phpstan-extension

pkg:composer/php-standard-library/phpstan-extension

Statistics

Installs: 1 267 511

Dependents: 17

Suggesters: 2

Stars: 21

Open Issues: 19

2.1.0 2026-03-18 10:23 UTC

Requires

Suggests

None

Provides

None

Replaces

None

MIT 138b048577442500656cf3def6ff840ee918116f


README

👁 Build
👁 Latest Stable Version
👁 License

Description

The main goal of this extension is to help PHPStan to detect the types after using Psl\Type\shape.

Given the following example:

use Psl\Type;

$specification = Type\shape([
 'name' => Type\string(),
 'age' => Type\int(),
 'location' => Type\optional(Type\shape([
 'city' => Type\string(),
 'state' => Type\string(),
 'country' => Type\string(),
 ]))
]);

$input = $specification->coerce($_GET['user']);

PHPStan assumes that $input is of type array<"age"|"location"|"name", array<"city"|"country"|"state", string>|int|string>.

If we enable the extension, you will get a more specific and correct type of array{name: string, age: int, location?: array{city: string, state: string, country: string}}.

Besides coerce, this extension also supports matches() and assert() methods.

Installation

To use this extension, require it in Composer:

composer require --dev php-standard-library/phpstan-extension

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