1

I'm using Psalm style annotations to document for instance return array types, such:

/**
  * @return array{ key1: type1, key2: type2, key3: array{ nestedKey1: array<string,string> } }
  */

This works like a charm for autocomplete / static analysis, including PhpStorm. However, these lines can get just absurly long and impossible to follow, especially where nested arrays are involved.

I'm looking for a multiline syntax for this annotation, where I can have something like:

/**
  * @return array{ 
  *    key1: type1, 
  *    key2: type2, 
  *    key3: array{ 
  *      nestedKey1: array<string,string> 
  *    } 
  *  }
  */

However as it's written this doesn't appear to be valid parsed syntax. Is there some syntax that would allow me to break the definition on multiple lines?

Dinu
  • 1,374
  • 8
  • 21

2 Answers2

3

Seems to be totally supported by Psalm: https://psalm.dev/r/2feeaae2fb

It's often easier to split out individual parts into their own type aliases though, e.g.: https://psalm.dev/r/733049a5f4

weirdan
  • 2,499
  • 23
  • 27
  • Well, I'm aiming for readability though; if some of the nested structures might represent entities in their own right, this might be an approach, even defining a global @template for them. But otherwise, it's just clutter... – Dinu Sep 21 '21 at 06:34
1

Unfortunately, no, there isn't. Here's a request for this on the PhpStorm tracker:
https://youtrack.jetbrains.com/issue/WI-59784

Eugene Morozov
  • 2,790
  • 1
  • 10
  • 17