Skip to content

Choose a common phpdoc tag to assert that a parameter is of a given union type #3

@TysonAndre

Description

@TysonAndre

@param-assert UnionType $paramName or @x-assert UnionType $paramName are my best ideas so far.

Phan has @phan-assert, Psalm has @psalm-assert, PHPStan has an open issue, and I haven't checked to see if any similar tags exist elsewhere.

Psalm also has @psalm-assert-if-true and @psalm-assert-if-false - https://github.com/vimeo/psalm/blob/master/docs/annotating_code/adding_assertions.md

  • Possibly document implemented extensions such as truthy that aren't union types
  • Tool authors may wish to emit warnings if non-union types such as truthy are used in the common tag instead of the tool-specific phpdoc annotations
  • Having a common annotation will make it much easier for IDEs and other tools to make use of annotations in libraries in the future (e.g. webmozart/assert)

Related to phpstan/phpstan#2223

cc @ondrejmirtes @muglug @staabm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions