mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
More markdown fixes
This commit is contained in:
parent
0b67844420
commit
9684be9d73
@ -28,7 +28,7 @@ Atomic types are the basic building block of all type information used in Psalm.
|
||||
* [Exception, Foo\MyClass and `Foo\MyClass<Bar>`](object_types.md#named-objectsmd)
|
||||
* [Generator](object_types.md#generators)
|
||||
* [Array types](array_types.md)
|
||||
* [array<int, string> ](array_types.md#generic-arrays)
|
||||
* [array<int, string>](array_types.md#generic-arrays)
|
||||
* [non-empty-array](array_types.md#non-empty-array)
|
||||
* [string\[\]](array_types.md#phpdoc-syntax)
|
||||
* [list & non-empty-list](array_types.md#lists)
|
||||
|
@ -9,6 +9,7 @@ Psalm supports some _magical_ utility types that brings superpower to the PHP ty
|
||||
The `key-of` utility returns the offset-type for any [array type](array_types.md).
|
||||
|
||||
Some examples:
|
||||
|
||||
- `key-of<Foo\Bar::ARRAY_CONST>` evaluates to offset-type of `ARRAY_CONST` (Psalm 3.3+)
|
||||
- `key-of<list<mixed>>` evaluates to `int`
|
||||
- `key-of<array{a: mixed, b: mixed}|array{c: mixed}>` evaluates to `'a'|'b'|'c'`
|
||||
@ -18,6 +19,7 @@ Some examples:
|
||||
### Notes on template usage
|
||||
|
||||
If you use `key-of` with a template param, you can fulfill the type check only with these allowed methods:
|
||||
|
||||
- `array_keys($t)`
|
||||
- `array_key_first($t)`
|
||||
- `array_key_last($t)`
|
||||
@ -35,7 +37,6 @@ function getKeys($array) {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## value-of<T>
|
||||
|
||||
(Psalm 5.0+)
|
||||
@ -43,6 +44,7 @@ function getKeys($array) {
|
||||
The `value-of` utility returns the value-type for any [array type](array_types.md).
|
||||
|
||||
Some examples:
|
||||
|
||||
- `value-of<Foo\Bar::ARRAY_CONST>` evaluates to value-type of `ARRAY_CONST` (Psalm 3.3+)
|
||||
- `value-of<list<float>>` evaluates to `float`
|
||||
- `value-of<array{a: bool, b: int}|array{c: string}>` evaluates to `bool|int|string`
|
||||
@ -52,6 +54,7 @@ Some examples:
|
||||
### Notes on template usage
|
||||
|
||||
If you use `value-of` with a template param, you can fulfill the type check only with these allowed methods:
|
||||
|
||||
- `array_values`
|
||||
|
||||
```php
|
||||
@ -67,7 +70,6 @@ function getValues($array) {
|
||||
|
||||
Currently `in_array($value, $t)` **does not** infer that `$value` is of `value-of<T>`.
|
||||
|
||||
|
||||
## properties-of<T>
|
||||
|
||||
(Psalm 5.0+)
|
||||
@ -103,11 +105,11 @@ class A {
|
||||
|
||||
Note that `properties-of<T>` will return **all non-static** properties. There are the following subtypes to pick only
|
||||
properties with a certain visibility:
|
||||
|
||||
- `public-properties-of<T>`
|
||||
- `protected-properties-of<T>`
|
||||
- `private-properties-of<T>`
|
||||
|
||||
|
||||
### Sealed array support
|
||||
|
||||
Use final classes if you want to properties-of and get_object_vars to return sealed arrays:
|
||||
|
Loading…
Reference in New Issue
Block a user