Skip to content

Commit 39716a8

Browse files
committed
Output examples
1 parent 6b81aaa commit 39716a8

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

README.md

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# psalm-show-type
22
Analog for psalm-trace but with pretty print
33

4-
Installation:
4+
### Installation
55

66
```console
77
$ composer require --dev klimick/psalm-show-type
88
$ vendor/bin/psalm-plugin enable Klimick\\PsalmShowType\\ShowTypePlugin
99
```
1010

1111

12-
Usage:
12+
### Usage
1313

1414
```php
1515
<?php
@@ -18,11 +18,76 @@ Usage:
1818
/** @show-type */
1919
$a = 42;
2020

21-
// Or return (not supported by @psalm-trace):
21+
// With return statement (not supported by @psalm-trace):
2222
$fn = function(): array {
2323
/** @show-type */
2424
return [
2525
'value' => 42,
2626
];
2727
};
28+
29+
// Type from arrow fn expression (not supported by @psalm-trace):
30+
$arrowFn = fn() => /** @show-type */ str_contains('psalm-show-type', 'show-type');
31+
```
32+
33+
### Output examples
34+
35+
#### class
36+
37+
```
38+
@psalm-trace: Foo\Bar\Str
39+
```
40+
```
41+
@show-type: Str
42+
```
43+
44+
#### generic class
45+
46+
```
47+
@psalm-trace: SplDoublyLinkedList<int, Foo\Bar\Str>
48+
```
49+
```
50+
@show-type: SplDoublyLinkedList<TKey: int, TValue: Str>
51+
```
52+
53+
#### array\iterable
54+
55+
```
56+
@psalm-trace: array<int, Foo\Bar\Str>
57+
```
58+
```
59+
@show-type: array<TKey: int, TValue: Str>
60+
```
61+
62+
#### list
63+
64+
```
65+
@psalm-trace: list<Foo\Bar\Str>
66+
```
67+
```
68+
@show-type: list<TValue: Str>
69+
```
70+
71+
#### array shape
72+
73+
```
74+
@psalm-trace: array{prop1: Foo\Bar\Str, prop2: SplDoublyLinkedList<int, Foo\Bar\Str>}
75+
```
76+
```
77+
@show-type: array{
78+
prop1: Str,
79+
prop2: SplDoublyLinkedList<TKey: int, TValue: Str>,
80+
}
81+
```
82+
83+
#### callable/closure
84+
85+
```
86+
@psalm-trace: callble(Foo\Bar\Num): array{prop1: Foo\Bar\Str, prop2: SplDoublyLinkedList<int, Foo\Bar\Str>}
87+
```
88+
```
89+
@show-type: callble(Num): array{
90+
prop1: Str,
91+
prop2: SplDoublyLinkedList<TKey: int, TValue: Str>,
92+
}
2893
```

0 commit comments

Comments
 (0)