Improve PHPDoc of id()
Details
- Reviewers
valerio.bozzolan - Group Reviewers
O1: Blessed Committers - Commits
- rARC6718b32a64f2: Improve PHPDoc of id()
Check the types that are returned by id
Diff Detail
- Repository
- rARC Arcanist
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
I don’t believe this style of doc annotation is used elsewhere. What’s the purpose of this?
I think the purpose is to tell the IDE that the function receives a type and returns that exact type.
Just for my curiosity, what IDE are you using? :)
It is to indicate language server aware editors what type the object has and this results in code completion to work:
For more details, see here:
https://phpstan.org/blog/generics-in-php-using-phpdocs#type-variables
Unless we can come up with a better/more common notation to show this information, I'm +1 on this - I like static type information, and this one looks fine to me.
I'm not familiar with many PHP tools - is there another notation somewhere?
AFAIK, this https://we.phorge.it/book/arcanist/function/id/ is the only thing we do with the annotation (other then having it for humans). I don't think we have any home-grown static type checks.
Seems like there is not a standard for it, but many of the implementation seem to support it:
- https://phpactor.readthedocs.io/en/master/reference/types.html?highlight=template#generic-types
- https://phpstan.org/blog/generics-in-php-using-phpdocs#type-variables
- https://intelephense.com/
AFAIK, this https://we.phorge.it/book/arcanist/function/id/ is the only thing we do with the annotation (other then having it for humans). I don't think we have any home-grown static type checks.
I think I'll tinker in my extensions with these toolings 🤔
Maybe at one point, if it provides any values, we can adopt some of these techniques into core.
Premising I've already seen this syntax in Java but not in PHP, I'm happy that now your IDE says something useful. Maybe a better title is "Improve PHPDoc of id()".