phpstorm-attributes icon indicating copy to clipboard operation
phpstorm-attributes copied to clipboard

Is there any documentation on ArrayShape?

Open Leonetienne opened this issue 1 year ago • 1 comments

I can't seem to find any. The example provided in this repos readme is way too shallow to be useful in the vast majority of real-world usecases.

How do I define that the keys do not matter but the value types do?

// My impression, of how a solution could look like
#[ArrayShape([
    '*' => 'string',
])]

How do I define optional keys?

#[ArrayShape([
   'name' => 'string',
   'occupation?' => 'string',
])]

How do I define multiple valid types?

#[ArrayShape([
   'spouse' => 'string|array',
])]

How do I define numeric arrays?

#[ArrayShape([
 'int', 'int', 'int'
])]

Of arbitrary size?

#[ArrayShape([
 'int+'
])]

In my experience having required, and only required keys is quite the niche usecase. But that's the only usecase shown in the readme. Is there any way to solve the usecases presented above? Otherwise I think my code would be better documented using phpdoc's description feature...

I hope you can point me in the right direction! Thanks! :3

Leonetienne avatar Feb 26 '23 01:02 Leonetienne