Skip to content

Commit 9e4bea7

Browse files
committed
Add typed tags
1 parent fe80429 commit 9e4bea7

39 files changed

Lines changed: 770 additions & 127 deletions

docs/Writerside/tl.tree

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
<toc-element topic="psalm-external-mutation-free-tag.md" />
153153
<toc-element topic="psalm-extends-tag.md" />
154154
<toc-element topic="psalm-flow-tag.md" wip="true" />
155-
<toc-element topic="psalm-if-this-is-tag.md" wip="true" />
155+
<toc-element topic="psalm-if-this-is-tag.md" />
156156
<toc-element topic="psalm-ignore-falsable-return-tag.md" />
157157
<toc-element topic="psalm-ignore-nullable-return-tag.md" />
158158
<toc-element topic="psalm-ignore-var-tag.md" />
@@ -161,7 +161,7 @@
161161
<toc-element topic="psalm-immutable-tag.md" />
162162
<toc-element topic="psalm-implements-tag.md" />
163163
<toc-element topic="psalm-import-type-tag.md" wip="true" />
164-
<toc-element topic="psalm-inheritors-tag.md" wip="true" />
164+
<toc-element topic="psalm-inheritors-tag.md" />
165165
<toc-element topic="psalm-internal-tag.md" />
166166
<toc-element topic="psalm-method-tag.md" />
167167
<toc-element topic="psalm-mutation-free-tag.md" />
@@ -180,10 +180,10 @@
180180
<toc-element topic="psalm-require-extends-tag.md" />
181181
<toc-element topic="psalm-require-implements-tag.md" />
182182
<toc-element topic="psalm-return-tag.md" />
183-
<toc-element topic="psalm-scope-this-tag.md" wip="true" />
183+
<toc-element topic="psalm-scope-this-tag.md" />
184184
<toc-element topic="psalm-seal-methods-tag.md" />
185185
<toc-element topic="psalm-seal-properties-tag.md" />
186-
<toc-element topic="psalm-self-out-tag.md" wip="true" />
186+
<toc-element topic="psalm-self-out-tag.md" />
187187
<toc-element topic="psalm-stub-override-tag.md" />
188188
<toc-element topic="psalm-suppress-tag.md" />
189189
<toc-element topic="psalm-taint-escape-tag.md" wip="true" />
@@ -194,13 +194,13 @@
194194
<toc-element topic="psalm-template-tag.md" />
195195
<toc-element topic="psalm-template-contravariant-tag.md" />
196196
<toc-element topic="psalm-template-covariant-tag.md" />
197-
<toc-element topic="psalm-this-out-tag.md" wip="true" />
197+
<toc-element topic="psalm-this-out-tag.md" />
198198
<toc-element topic="psalm-trace-tag.md" />
199199
<toc-element topic="psalm-type-tag.md" wip="true" />
200200
<toc-element topic="psalm-use-tag.md" />
201201
<toc-element topic="psalm-var-tag.md" />
202202
<toc-element topic="psalm-variadic-tag.md" />
203-
<toc-element topic="psalm-yield-tag.md" wip="true" />
203+
<toc-element topic="psalm-yield-tag.md" />
204204
</toc-element>
205205
<toc-element toc-title="PHPStan" topic="phpstan-tags.md">
206206
<toc-element topic="phpstan-allow-private-mutation-tag.md" />
@@ -232,16 +232,16 @@
232232
<toc-element topic="phpstan-require-extends-tag.md" />
233233
<toc-element topic="phpstan-require-implements-tag.md" />
234234
<toc-element topic="phpstan-return-tag.md" />
235-
<toc-element topic="phpstan-self-out-tag.md" wip="true" />
235+
<toc-element topic="phpstan-self-out-tag.md" />
236236
<toc-element topic="phpstan-template-tag.md" />
237237
<toc-element topic="phpstan-template-contravariant-tag.md" />
238238
<toc-element topic="phpstan-template-covariant-tag.md" />
239-
<toc-element topic="phpstan-this-out-tag.md" wip="true" />
239+
<toc-element topic="phpstan-this-out-tag.md" />
240240
<toc-element topic="phpstan-throws-tag.md" />
241241
<toc-element topic="phpstan-type-tag.md" wip="true" />
242242
<toc-element topic="phpstan-use-tag.md" />
243243
<toc-element topic="phpstan-var-tag.md" />
244-
<toc-element topic="phpstan-yield-tag.md" wip="true" />
244+
<toc-element topic="phpstan-yield-tag.md" />
245245
</toc-element>
246246
<toc-element toc-title="Phan" topic="phan-tags.md">
247247
<toc-element topic="phan-abstract-tag.md" />
@@ -250,13 +250,13 @@
250250
<toc-element topic="phan-assert-if-false-tag.md" wip="true" />
251251
<toc-element topic="phan-assert-if-true-tag.md" wip="true" />
252252
<toc-element topic="phan-assert-true-condition-tag.md" wip="true" />
253-
<toc-element topic="phan-closure-scope-tag.md" wip="true" />
253+
<toc-element topic="phan-closure-scope-tag.md" />
254254
<toc-element topic="phan-constructor-used-for-side-effects-tag.md" />
255255
<toc-element topic="phan-extends-tag.md" />
256256
<toc-element topic="phan-file-suppress-tag.md" wip="true" />
257257
<toc-element topic="phan-forbid-undeclared-magic-methods-tag.md" />
258258
<toc-element topic="phan-forbid-undeclared-magic-properties-tag.md" />
259-
<toc-element topic="phan-hardcode-return-type-tag.md" wip="true" />
259+
<toc-element topic="phan-hardcode-return-type-tag.md" />
260260
<toc-element topic="phan-immutable-tag.md" />
261261
<toc-element topic="phan-inherits-tag.md" />
262262
<toc-element topic="phan-method-tag.md" />
@@ -269,7 +269,7 @@
269269
<toc-element topic="phan-property-write-tag.md" />
270270
<toc-element topic="phan-pure-tag.md" />
271271
<toc-element topic="phan-read-only-tag.md" />
272-
<toc-element topic="phan-real-return-tag.md" wip="true" />
272+
<toc-element topic="phan-real-return-tag.md" />
273273
<toc-element topic="phan-return-tag.md" />
274274
<toc-element topic="phan-side-effect-free-tag.md" />
275275
<toc-element topic="phan-suppress-current-line-tag.md" wip="true" />
@@ -282,12 +282,12 @@
282282
<toc-element topic="phan-unused-param-tag.md" />
283283
<toc-element topic="phan-var-tag.md" />
284284
<toc-element topic="phan-write-only-tag.md" />
285-
<toc-element topic="phanclosurescope-tag.md" wip="true" />
285+
<toc-element topic="phanclosurescope-tag.md" />
286286
</toc-element>
287287
<toc-element toc-title="PhpStorm" topic="phpstorm-tags.md">
288288
<toc-element topic="noinspection-tag.md" wip="true" />
289289
<toc-element topic="language-tag.md" wip="true" />
290-
<toc-element topic="expected-exception-tag.md" wip="true" />
290+
<toc-element topic="expected-exception-tag.md" />
291291
<toc-element topic="formatter-off-tag.md" />
292292
<toc-element topic="formatter-on-tag.md" />
293293
</toc-element>
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @expectedException
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@expectedException` tag declares the `Throwable` a test method is
76
expected to throw. It is an old PHPUnit-era convention that predates the
@@ -11,12 +10,12 @@ expected to throw. It is an old PHPUnit-era convention that predates the
1110
"@expectedException" <Type> [ <Description> ]
1211
```
1312

14-
<note>
15-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
16-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
17-
suffix folded into the description. See
18-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
19-
need to recognize it yourself.
20-
</note>
13+
Parsing a `@expectedException` tag produces a `ExpectedExceptionTag` instance, carrying the
14+
parsed `$type` alongside the `$name` and optional `$description` every
15+
[Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class ExpectedExceptionTag extends TypedTag {}
19+
```
2120

2221
A historical PHPUnit convention, not a PhpStorm tag.
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @phan-closure-scope
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@phan-closure-scope` tag binds the type of `$this` inside a
76
`Closure`, letting Phan analyze the closure's body as though it were
@@ -11,12 +10,12 @@ bound to an instance of the given class.
1110
"@phan-closure-scope" <Type>
1211
```
1312

14-
<note>
15-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
16-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
17-
suffix folded into the description. See
18-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
19-
need to recognize it yourself.
20-
</note>
13+
Parsing a `@phan-closure-scope` tag produces a `PhanClosureScopeTag` instance, carrying the
14+
parsed `$type` alongside the `$name` and optional `$description` every
15+
[Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class PhanClosureScopeTag extends TypedTag {}
19+
```
2120

2221
Defined by [Phan's Annotating Your Source Code wiki](https://github.com/phan/phan/wiki/Annotating-Your-Source-Code#phan-closure-scope).
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# @phan-hardcode-return-type
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@phan-hardcode-return-type` tag forces Phan to use the
76
documented return type instead of the type it would otherwise infer
87
from the method body.
98

10-
<note>
11-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
12-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
13-
suffix folded into the description. See
14-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
15-
need to recognize it yourself.
16-
</note>
9+
```
10+
"@phan-hardcode-return-type" <Type> [ <Description> ]
11+
```
12+
13+
Parsing a `@phan-hardcode-return-type` tag produces a `PhanHardcodeReturnTypeTag` instance, carrying the
14+
parsed `$type` alongside the `$name` and optional `$description` every
15+
[Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class PhanHardcodeReturnTypeTag extends TypedTag {}
19+
```
1720

1821
Defined by Phan.
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# @phan-real-return
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@phan-real-return` tag documents the actual native return
76
type of a function or method, kept distinct from the type
87
documented via [@return](return-tag.md).
98

10-
<note>
11-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
12-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
13-
suffix folded into the description. See
14-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
15-
need to recognize it yourself.
16-
</note>
9+
```
10+
"@phan-real-return" <Type> [ <Description> ]
11+
```
12+
13+
Parsing a `@phan-real-return` tag produces a `PhanRealReturnTag` instance, carrying the
14+
parsed `$type` alongside the `$name` and optional `$description` every
15+
[Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class PhanRealReturnTag extends TypedTag {}
19+
```
1720

1821
Defined by Phan, a static analyzer for PHP; no dedicated
1922
documentation page could be confirmed for this tag.
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# @phanclosurescope
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
4+
<secondary-label ref="alias-tag"/>
55

66
The `@phanclosurescope` tag is an older alias of
77
[@phan-closure-scope](phan-closure-scope-tag.md), binding the
88
type of `$this` inside a `Closure`.
99

10-
<note>
11-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
12-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
13-
suffix folded into the description. See
14-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
15-
need to recognize it yourself.
16-
</note>
10+
This library recognizes `@phanclosurescope` as an alias of the canonical
11+
[@phan-closure-scope](phan-closure-scope-tag.md) tag: it parses identically and produces
12+
the exact same tag instance, keeping the vendor-prefixed name it was
13+
written with.
1714

1815
Defined by [Phan](https://github.com/phan/phan/wiki/Annotating-Your-Source-Code).
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
# @phpstan-self-out
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@phpstan-self-out` tag documents the refined type of `$this`
76
after a method call, letting PHPStan track how a fluent or
87
mutating method narrows the object's own type. It is defined by the
98
static analyzer PHPStan, which also accepts the alias
109
`@phpstan-this-out` (see [phpstan-this-out-tag.md](phpstan-this-out-tag.md)).
1110

12-
<note>
13-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
14-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
15-
suffix folded into the description. See
16-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
17-
need to recognize it yourself.
18-
</note>
11+
```
12+
"@phpstan-self-out" <Type> [ <Description> ]
13+
```
14+
15+
Parsing a `@phpstan-self-out` tag produces a `SelfOutTag` instance, carrying the
16+
parsed `$type` alongside the `$name` and optional `$description` every
17+
[Tag](phpdoc.md#tag) already provides.
18+
19+
```php
20+
final class SelfOutTag extends TypedTag {}
21+
```
22+
23+
The same `SelfOutTag` is produced by [@psalm-self-out](psalm-self-out-tag.md), which restates the same concept for its tool.
1924

2025
See PHPStan's
2126
[PHPDoc basics](https://phpstan.org/writing-php-code/phpdocs-basics#change-type-of-current-object-after-calling-a-method).
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
# @phpstan-this-out
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
4+
<secondary-label ref="alias-tag"/>
55

66
The `@phpstan-this-out` tag is an alias of `@phpstan-self-out` (see
77
[phpstan-self-out-tag.md](phpstan-self-out-tag.md)). It documents
88
the refined type of `$this` after a method call.
99

10-
<note>
11-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
12-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
13-
suffix folded into the description. See
14-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
15-
need to recognize it yourself.
16-
</note>
10+
This library recognizes `@phpstan-this-out` as an alias of the canonical
11+
[@phpstan-self-out](phpstan-self-out-tag.md) tag: it parses identically and produces
12+
the exact same tag instance, keeping the vendor-prefixed name it was
13+
written with.
1714

1815
See PHPStan's
1916
[PHPDoc basics](https://phpstan.org/writing-php-code/phpdocs-basics#change-type-of-current-object-after-calling-a-method).
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @phpstan-yield
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@phpstan-yield` tag documents the type yielded by a
76
`Generator`, distinct from the type it returns on completion. It is
@@ -11,12 +10,14 @@ defined by the static analyzer PHPStan.
1110
"@phpstan-yield" <Type> [ <Description> ]
1211
```
1312

14-
<note>
15-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
16-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
17-
suffix folded into the description. See
18-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
19-
need to recognize it yourself.
20-
</note>
13+
Parsing a `@phpstan-yield` tag produces a `YieldTag` instance, carrying the
14+
parsed `$type` alongside the `$name` and optional `$description` every
15+
[Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class YieldTag extends TypedTag {}
19+
```
20+
21+
The same `YieldTag` is produced by [@psalm-yield](psalm-yield-tag.md), which restates the same concept for its tool.
2122

2223
See PHPStan's [PHPDoc basics](https://phpstan.org/writing-php-code/phpdocs-basics) page.
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @psalm-if-this-is
22

33
<primary-label ref="phpdoc-component"/>
4-
<secondary-label ref="not-implemented"/>
54

65
The `@psalm-if-this-is` tag narrows the type of `$this` inside a
76
method when the given type matches. It is defined by the static
@@ -11,12 +10,12 @@ analyzer Psalm, alongside [@psalm-assert](psalm-assert-tag.md).
1110
"@psalm-if-this-is" <Type>
1211
```
1312

14-
<note>
15-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
16-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
17-
suffix folded into the description. See
18-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
19-
need to recognize it yourself.
20-
</note>
13+
Parsing a `@psalm-if-this-is` tag produces a `PsalmIfThisIsTag` instance, carrying the
14+
parsed `$type` alongside the `$name` and optional `$description` every
15+
[Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class PsalmIfThisIsTag extends TypedTag {}
19+
```
2120

2221
See [Psalm's supported annotations](https://psalm.dev/docs/annotating_code/supported_annotations/#psalm-assert-psalm-assert-if-true-psalm-assert-if-false-psalm-if-this-is-and-psalm-this-out).

0 commit comments

Comments
 (0)