backendtea/psl-phpstan-extension

PHPStan psl extension

Installs: 449

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 0

Open Issues: 1

Type:phpstan-extension

0.0.1 2022-05-25 20:41 UTC

This package is auto-updated.

Last update: 2024-10-26 02:00:25 UTC


README

Description

The main scope of this extension is to help phpstan to detect the types after using Psl\Type\shape. Its intended to produce the same output as the psalm plugin. 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}}.