Vscode-intelephense: Support generic types in php doc annotations

Created on 5 Mar 2019  路  8Comments  路  Source: bmewburn/vscode-intelephense

Shopware uses the following annotations to define arrays:
grafik

I am not sure, if this is annotation is correct and should be working. But intelephense as for now does not recognize it correctly:
grafik

enhancement

Most helpful comment

Even phan supports generic types https://github.com/phan/phan/wiki/Generic-Types.

So it's 3 (most) popular static analyzers.

All 8 comments

I think this is psalm syntax and is not currently supported

Why not using @return array|int[]|string[] instead?

The first element is the key type not a value union type

It would be great if intelephense supported generic/template types. It's not just pslam, phpstan too will have support for it soon. So these annotations are becoming defacto standard.

https://arnaud.le-blanc.net/post/phpstan-generics.html
https://psalm.dev/docs/annotating_code/templated_annotations/

Even phan supports generic types https://github.com/phan/phan/wiki/Generic-Types.

So it's 3 (most) popular static analyzers.

Hello, this issue was closed, but AFAICT this hasn't been implemented yet?

@jaydiablo It is implemented:

/** @var array<string,(float|int)> */
$arr = [];

foreach($arr as $k=>$v){
  $k; // string
  $v; // float|int
}

@KapitanOczywisty thanks for the reply! We're seeing a case where Intelephense doesn't see the type of items of a collection (implements IteratorAggregate), but we've noticed that Psalm doesn't either (PHPStan does), so looking into it more. If I find it's something that Intelephense should be detecting I'll create a new issue.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

swashata picture swashata  路  3Comments

muuvmuuv picture muuvmuuv  路  4Comments

nn-hh picture nn-hh  路  3Comments

zlianon picture zlianon  路  4Comments

usrnm-nk picture usrnm-nk  路  3Comments