JetBrains / JetBrains/phpstorm-attributes

Is there any documentation on ArrayShape?

Open
#24 2 comments 4 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
416
Forks
11
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.