Skip to content

Tag reference

@psalm-if-this-is

The @psalm-if-this-is tag narrows the type of $this inside a method when the given type matches. It is defined by the static analyzer Psalm, alongside @psalm-assert.

Grammar

"@psalm-if-this-is" <Type> [ <Description> ]

Examples

A method callable only on a narrower type of the object.
/**
* @psalm-if-this-is Collection<int>
*/
public function sum(): int

Names by platform

psalm
@psalm-if-this-is

Parsing a @psalm-if-this-is tag produces a PsalmIfThisIsTag instance, carrying the parsed $type alongside the $name and optional $description every Tag already provides.

final class PsalmIfThisIsTag extends TypedTag {}

See Psalm’s supported annotations.