Open BenMorel opened 2 years ago
I found these snippets:
Not currently, but I think PHPStan supports something like this and it would probably be good to add support to Psalm.
I think we'd probably want to enforce array<array-key, mixed>
style with this and not allow mixed[]
, but that's up for discussion and may depend on implementation difficulty (I think mixed[]
may get transformed to array<array-key, mixed>
internally before an issue could be raised, so it might require extra code to track that).
This can be done using https://github.com/slevomat/coding-standard/#slevomatcodingstandardtypehintsparametertypehint- and related sniffs (see their traversableTypeHints
option).
To me, it looks like a style choice rather than something Psalm should enforce.
There's more to it, though: Psalm should also, IMHO, complain when using a type with generics without providing the @template
parameters. Example with Doctrine Collections:
function foo(): Collection {} // should complain, to force documenting K and V in Collection<K,V>
Psalm currently does not complain either here.
I don't think a coding standards tool can understand the code deep enough to report this kind of lack of documentation, and I do think that this belongs to a static analysis tool.
I found these snippets:
After searching the documentation & open issues, I cannot find if Psalm has the following option.
Is it possible to force Psalm to complain when using an
array
type without a docblock? For example:https://psalm.dev/r/9d82083039
I'd like to enforce in our codebase that every function where an array is used as a parameter or return type is properly documented, but Psalm only complains once you attempt to use something inside the array.