Skip to content

Tag reference

@assert-if-true

The @assert-if-true tag asserts the given type for a subject, but only when the function returns true.

Grammar

"@phan-assert-if-true" [ ( "!=" | "!" | "=" ) ] <Type> <AssertSubject> [ <Description> ]
"@phpstan-assert-if-true" [ ( "!=" | "!" | "=" ) ] <Type> <AssertSubject> [ <Description> ]
"@psalm-assert-if-true" [ ( "!=" | "!" | "=" ) ] <Type> <AssertSubject> [ <Description> ]

Examples

Narrowing when the check returns true.
/**
* @phan-assert-if-true string $value
*/
function isString(mixed $value): bool

Names by platform

phan
@phan-assert-if-true
phpstan
@phpstan-assert-if-true
psalm
@psalm-assert-if-true