-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Choose a common phpdoc tag to assert that a parameter is of a given union type #3
Comments
Why only about union types? One could also assert a single (simple type). What's more interesting than the tag name is the syntax needed for the type itself. See these Psalm docs: https://github.com/vimeo/psalm/blob/master/docs/annotating_code/assertion_syntax.md There's also This feature should also work with generics:
|
By union type, I mean a union type with 1 or more types, which includes the case of "a single (simple type)"
I'd agree - that should follow naturally in implementations from the way an analyzer already parses types/union types for other tags
I haven't gotten around to implementing that, but it'd be easy enough to add a rule to Phan or other analyzers to parse it and ignore it if support for the prefix wasn't implemented. |
I'd describe it as a "type" then because the user might also want to assert an intersection type. |
Intersection types would also be permissible (I planned to implement pretty much anything you could already put in a
I was thinking of "type" as the things that union types (and intersection types) contain. I thought you were referring to "atomic types"
|
@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.mdtruthy
that aren't union typestruthy
are used in the common tag instead of the tool-specific phpdoc annotationsRelated to phpstan/phpstan#2223
cc @ondrejmirtes @muglug @staabm
The text was updated successfully, but these errors were encountered: