php-enum icon indicating copy to clipboard operation
php-enum copied to clipboard

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

Open TysonAndre opened this issue 5 years ago • 3 comments
trafficstars

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.

TysonAndre avatar Jun 15 '20 18:06 TysonAndre

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.

prolic avatar Jun 15 '20 20:06 prolic

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?

marc-mabe avatar Jun 15 '20 20:06 marc-mabe

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

TysonAndre avatar Jun 16 '20 15:06 TysonAndre