backendtea/psl-phpstan-extension

PHPStan psl 扩展

安装: 449

依赖: 0

建议: 0

安全: 0

星星: 2

关注者: 3

分支: 0

开放问题: 1

类型:phpstan-extension

0.0.1 2022-05-25 20:41 UTC

This package is auto-updated.

Last update: 2024-08-26 01:40:47 UTC


README

描述

此扩展的主要作用是帮助phpstan在使用Psl\Type\shape后检测类型。它的目的是产生与psalm插件相同的输出。以下是一个示例

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 假定$input的类型为array<"age"|"location"|"name", array<"city"|"country"|"state", string>|int|string>

如果我们启用此扩展,您将获得更具体和正确的类型array{name: string, age: int, location?: array{city: string, state: string, country: string}}