Skip to content
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

Support phan annotations such as @phan-return and @phan-side-effect-free? #145

Open
TysonAndre opened this issue Jun 15, 2020 · 3 comments

Comments

@TysonAndre
Copy link

https://github.com/phan/phan/wiki/Annotating-Your-Source-Code documents the available options. https://github.com/phan/phan/wiki/About-Union-Types documents union types supported by Phan.

non-empty-string is not supported in array keys.

@prolic
Copy link
Collaborator

prolic commented Jun 15, 2020

IMHO we shouldn't add annotations for phan + phpstan + psalm. It adds to much overhead to support all of those and next week we might have another 3 additionally.
Pick one and stick to it.

@marc-mabe
Copy link
Owner

Hi @TysonAndre,

A lot has been done already in #140 & #138 and a phpstan extension is available here https://github.com/marc-mabe/php-enum-phpstan/

Type-hints are defined with standard annotations and some special hints like non-empty-string are marked with @psalm-.

What exactly are you missing?

@TysonAndre
Copy link
Author

This was for https://github.com/phan/phan , not psalm or phpstan, because I'm using phan in a project using php-enum. So phan would get the generic types without any information about key types, and not be provided the information to warn about somesubclass::getValues()['not_an_integer']

@phan-return list<null|bool|int|float|string|array> for getValues()
@phan-return list<non-empty-string> for getNames() instead of string[]
@phan-return array<string, null|bool|int|float|string|array> for getConstants()

Although I may eventually add an option for phan to read psalm-specific annotations, and ignore syntax that it doesn't understand, that approach would cause bugs in custom types declared with @psalm-type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants