klimick / psalm-show-type

此包已被废弃,不再维护。作者建议使用 fp4php/psalm-toolkit 包。

psalm-trace 的类似工具,具有美化打印功能

安装数: 3,835

依赖项: 1

建议者: 0

安全性: 0

星标: 2

关注者: 4

分支: 1

开放问题: 0

类型:psalm-plugin

v1.0.3 2021-07-28 17:42 UTC

This package is not auto-updated.

Last update: 2022-07-05 19:04:50 UTC


README

psalm-trace 的类似工具,具有美化打印功能

安装

$ composer require --dev klimick/psalm-show-type
$ vendor/bin/psalm-plugin enable Klimick\\PsalmShowType\\ShowTypePlugin

用法

<?php

// With assignment:
/** @show-type */
$a = 42;

// With return statement (not supported by @psalm-trace):
$fn = function(): array {
    /** @show-type */
    return [
        'value' => 42,
    ];
};

// Type from arrow fn expression (not supported by @psalm-trace):
$arrowFn = fn() => /** @show-type */ str_contains('psalm-show-type', 'show-type');

输出示例

@psalm-trace: Foo\Bar\Str
@show-type: Str

泛型类

@psalm-trace: SplDoublyLinkedList<int, Foo\Bar\Str>
@show-type: SplDoublyLinkedList<TKey: int, TValue: Str>

数组/迭代器

@psalm-trace: array<int, Foo\Bar\Str>
@show-type: array<TKey: int, TValue: Str>

列表

@psalm-trace: list<Foo\Bar\Str>
@show-type: list<TValue: Str>

数组结构

@psalm-trace: array{prop1: Foo\Bar\Str, prop2: SplDoublyLinkedList<int, Foo\Bar\Str>}
@show-type: array{
    prop1: Str,
    prop2: SplDoublyLinkedList<TKey: int, TValue: Str>,
}

可调用/闭包

@psalm-trace: callable(Foo\Bar\Num): array{prop1: Foo\Bar\Str, prop2: SplDoublyLinkedList<int, Foo\Bar\Str>}
@show-type: callable(Num): array{
    prop1: Str,
    prop2: SplDoublyLinkedList<TKey: int, TValue: Str>,
}