Skip to content

Commit 05fbd19

Browse files
committed
Add *-assert-if-true, *-assert-if-false and *-assert tags
1 parent 9e4bea7 commit 05fbd19

20 files changed

Lines changed: 375 additions & 82 deletions

docs/Writerside/tl.tree

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@
141141
<toc-element toc-title="Psalm" topic="psalm-tags.md">
142142
<toc-element topic="psalm-allow-private-mutation-tag.md" />
143143
<toc-element topic="psalm-api-tag.md" />
144-
<toc-element topic="psalm-assert-tag.md" wip="true" />
145-
<toc-element topic="psalm-assert-if-false-tag.md" wip="true" />
146-
<toc-element topic="psalm-assert-if-true-tag.md" wip="true" />
144+
<toc-element topic="psalm-assert-tag.md" />
145+
<toc-element topic="psalm-assert-if-false-tag.md" />
146+
<toc-element topic="psalm-assert-if-true-tag.md" />
147147
<toc-element topic="psalm-assert-untainted-tag.md" />
148148
<toc-element topic="psalm-check-type-tag.md" wip="true" />
149149
<toc-element topic="psalm-check-type-exact-tag.md" wip="true" />
@@ -204,9 +204,9 @@
204204
</toc-element>
205205
<toc-element toc-title="PHPStan" topic="phpstan-tags.md">
206206
<toc-element topic="phpstan-allow-private-mutation-tag.md" />
207-
<toc-element topic="phpstan-assert-tag.md" wip="true" />
208-
<toc-element topic="phpstan-assert-if-false-tag.md" wip="true" />
209-
<toc-element topic="phpstan-assert-if-true-tag.md" wip="true" />
207+
<toc-element topic="phpstan-assert-tag.md" />
208+
<toc-element topic="phpstan-assert-if-false-tag.md" />
209+
<toc-element topic="phpstan-assert-if-true-tag.md" />
210210
<toc-element topic="phpstan-consistent-constructor-tag.md" />
211211
<toc-element topic="phpstan-extends-tag.md" />
212212
<toc-element topic="phpstan-ignore-tag.md" wip="true" />
@@ -245,10 +245,10 @@
245245
</toc-element>
246246
<toc-element toc-title="Phan" topic="phan-tags.md">
247247
<toc-element topic="phan-abstract-tag.md" />
248-
<toc-element topic="phan-assert-tag.md" wip="true" />
248+
<toc-element topic="phan-assert-tag.md" />
249249
<toc-element topic="phan-assert-false-condition-tag.md" wip="true" />
250-
<toc-element topic="phan-assert-if-false-tag.md" wip="true" />
251-
<toc-element topic="phan-assert-if-true-tag.md" wip="true" />
250+
<toc-element topic="phan-assert-if-false-tag.md" />
251+
<toc-element topic="phan-assert-if-true-tag.md" />
252252
<toc-element topic="phan-assert-true-condition-tag.md" wip="true" />
253253
<toc-element topic="phan-closure-scope-tag.md" />
254254
<toc-element topic="phan-constructor-used-for-side-effects-tag.md" />
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
# @phan-assert-if-false
22

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

65
The `@phan-assert-if-false` tag asserts the given type for an
76
argument or variable when the function returns `false`. It belongs
87
to the same assertion family as [@phan-assert](phan-assert-tag.md)
98
and its counterpart
109
[@phan-assert-if-true](phan-assert-if-true-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+
"@phan-assert-if-false" <Type> <Variable> [ <Description> ]
13+
```
14+
15+
Parsing a `@phan-assert-if-false` tag produces an `AssertIfFalseTag` instance, carrying the
16+
asserted `$type` and `$variable` alongside the `$name` and optional
17+
`$description` every [Tag](phpdoc.md#tag) already provides.
18+
19+
```php
20+
final class AssertIfFalseTag extends TypedVariableTag {}
21+
```
22+
23+
The same `AssertIfFalseTag` is produced by [@psalm-assert-if-false](psalm-assert-if-false-tag.md) and [@phpstan-assert-if-false](phpstan-assert-if-false-tag.md), which restate the same
24+
assertion for their respective tools.
1925

2026
Defined by Phan; see the "Assertions" section of
2127
[Phan's Annotating Your Source Code wiki](https://github.com/phan/phan/wiki/Annotating-Your-Source-Code).
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
# @phan-assert-if-true
22

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

65
The `@phan-assert-if-true` tag asserts the given type for an
76
argument or variable when the function returns `true`. It belongs
87
to the same assertion family as [@phan-assert](phan-assert-tag.md)
98
and its counterpart
109
[@phan-assert-if-false](phan-assert-if-false-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+
"@phan-assert-if-true" <Type> <Variable> [ <Description> ]
13+
```
14+
15+
Parsing a `@phan-assert-if-true` tag produces an `AssertIfTrueTag` instance, carrying the
16+
asserted `$type` and `$variable` alongside the `$name` and optional
17+
`$description` every [Tag](phpdoc.md#tag) already provides.
18+
19+
```php
20+
final class AssertIfTrueTag extends TypedVariableTag {}
21+
```
22+
23+
The same `AssertIfTrueTag` is produced by [@psalm-assert-if-true](psalm-assert-if-true-tag.md) and [@phpstan-assert-if-true](phpstan-assert-if-true-tag.md), which restate the same
24+
assertion for their respective tools.
1925

2026
Defined by Phan; see the "Assertions" section of
2127
[Phan's Annotating Your Source Code wiki](https://github.com/phan/phan/wiki/Annotating-Your-Source-Code).
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @phan-assert
22

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

65
The `@phan-assert` tag asserts that an argument or variable is
76
narrowed to a given type after the call returns. Phan documents it
@@ -10,13 +9,20 @@ siblings — see [@phan-assert-if-true](phan-assert-if-true-tag.md) and
109
[@phan-assert-if-false](phan-assert-if-false-tag.md) — as part of the
1110
same assertion family.
1211

13-
<note>
14-
Not yet recognized by <code>TypeLang\PhpDoc\DocBlockParser</code> — parsing
15-
a docblock containing this tag returns a plain <code>Tag</code>, its whole
16-
suffix folded into the description. See
17-
<a href="custom-tags.md">Custom Tags</a> for the current workaround if you
18-
need to recognize it yourself.
19-
</note>
12+
```
13+
"@phan-assert" <Type> <Variable> [ <Description> ]
14+
```
15+
16+
Parsing a `@phan-assert` tag produces an `AssertTag` instance, carrying the
17+
asserted `$type` and `$variable` alongside the `$name` and optional
18+
`$description` every [Tag](phpdoc.md#tag) already provides.
19+
20+
```php
21+
final class AssertTag extends TypedVariableTag {}
22+
```
23+
24+
The same `AssertTag` is produced by [@psalm-assert](psalm-assert-tag.md) and [@phpstan-assert](phpstan-assert-tag.md), which restate the same
25+
assertion for their respective tools.
2026

2127
Defined by Phan; see the "Assertions" section of
2228
[Phan's Annotating Your Source Code wiki](https://github.com/phan/phan/wiki/Annotating-Your-Source-Code).
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
# @phpstan-assert-if-false
22

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

65
The `@phpstan-assert-if-false` tag asserts the given type when the
76
function returns `false`, defined by PHPStan. It is one of the
87
[@phpstan-assert](phpstan-assert-tag.md) family of narrowing tags.
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+
"@phpstan-assert-if-false" <Type> <Variable> [ <Description> ]
11+
```
12+
13+
Parsing a `@phpstan-assert-if-false` tag produces an `AssertIfFalseTag` instance, carrying the
14+
asserted `$type` and `$variable` alongside the `$name` and optional
15+
`$description` every [Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class AssertIfFalseTag extends TypedVariableTag {}
19+
```
20+
21+
The same `AssertIfFalseTag` is produced by [@psalm-assert-if-false](psalm-assert-if-false-tag.md) and [@phan-assert-if-false](phan-assert-if-false-tag.md), which restate the same
22+
assertion for their respective tools.
1723

1824
Documented by
1925
[PHPStan](https://phpstan.org/writing-php-code/phpdocs-basics#narrowing-types-after-function-call).
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
# @phpstan-assert-if-true
22

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

65
The `@phpstan-assert-if-true` tag asserts the given type when the
76
function returns `true`, defined by PHPStan. It is one of the
87
[@phpstan-assert](phpstan-assert-tag.md) family of narrowing tags.
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+
"@phpstan-assert-if-true" <Type> <Variable> [ <Description> ]
11+
```
12+
13+
Parsing a `@phpstan-assert-if-true` tag produces an `AssertIfTrueTag` instance, carrying the
14+
asserted `$type` and `$variable` alongside the `$name` and optional
15+
`$description` every [Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class AssertIfTrueTag extends TypedVariableTag {}
19+
```
20+
21+
The same `AssertIfTrueTag` is produced by [@psalm-assert-if-true](psalm-assert-if-true-tag.md) and [@phan-assert-if-true](phan-assert-if-true-tag.md), which restate the same
22+
assertion for their respective tools.
1723

1824
Documented by
1925
[PHPStan](https://phpstan.org/writing-php-code/phpdocs-basics#narrowing-types-after-function-call).
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
# @phpstan-assert
22

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

65
The `@phpstan-assert` tag asserts that an argument or variable is
76
narrowed to a given type after the call, defined by PHPStan. It has
87
`-if-true` and `-if-false` siblings for assertions that only hold when a
98
boolean-returning function returns a particular value.
109

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

1925
Documented by
2026
[PHPStan](https://phpstan.org/writing-php-code/phpdocs-basics#narrowing-types-after-function-call).
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
# @psalm-assert-if-false
22

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

65
The `@psalm-assert-if-false` tag asserts the given type for an
76
argument or variable when the function returns `false`. It is
87
defined by the static analyzer Psalm, alongside
98
[@psalm-assert](psalm-assert-tag.md).
109

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

1925
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).
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
# @psalm-assert-if-true
22

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

65
The `@psalm-assert-if-true` tag asserts the given type for an
76
argument or variable when the function returns `true`. It is
87
defined by the static analyzer Psalm, alongside
98
[@psalm-assert](psalm-assert-tag.md).
109

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

1925
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).
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
# @psalm-assert
22

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

65
The `@psalm-assert` tag asserts that an argument or variable is
76
narrowed to a given type after the call returns. It is defined by
87
the static analyzer Psalm.
98

109
```
11-
"@psalm-assert" <Type> <Variable>
10+
"@psalm-assert" <Type> <Variable> [ <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 `@psalm-assert` tag produces an `AssertTag` instance, carrying the
14+
asserted `$type` and `$variable` alongside the `$name` and optional
15+
`$description` every [Tag](phpdoc.md#tag) already provides.
16+
17+
```php
18+
final class AssertTag extends TypedVariableTag {}
19+
```
20+
21+
The same `AssertTag` is produced by [@phpstan-assert](phpstan-assert-tag.md) and [@phan-assert](phan-assert-tag.md), which restate the same
22+
assertion for their respective tools.
2123

2224
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)