Skip to content

BackEndTea/psl-phpstan-extension

Repository files navigation

PHPStan PSL extension

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}}.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published