php-standard-library / phpstan-extension
PHPStan PSL extension
Installs: 466 104
Dependents: 13
Suggesters: 1
Security: 0
Stars: 14
Watchers: 4
Forks: 4
Open Issues: 14
Type:phpstan-extension
Requires
- php: ^7.4 || ^8.0
- phpstan/phpstan: ^2.0
Requires (Dev)
- azjezz/psl: ^1.6||^2.0||^3.0
- composer/semver: ^3.3
- nikic/php-parser: ^4.14.0
- php-parallel-lint/php-parallel-lint: ^1.2
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^9.6
Conflicts
- azjezz/psl: <1.6||>=4.0
This package is auto-updated.
Last update: 2024-12-12 02:32:38 UTC
README
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!
Manual installation
If you don't want to use phpstan/extension-installer
, include extension.neon in your project's PHPStan config:
includes:
- vendor/php-standard-library/phpstan-extension/extension.neon