1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Cleanup documentation (#8702)

* Cleanup documentation

* Cleanup

* Cleanup
This commit is contained in:
Daniil Gentili 2022-11-12 20:50:46 +01:00 committed by GitHub
parent a79255cc99
commit 98a5dc313d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 18 deletions

View File

@ -26,7 +26,7 @@ _Click on the » next to each type to view detailed documentation and examp
* [object »](object_types.md#unnamed-objects)
* [object{foo: string} »](object_types.md#object-properties)
* [Exception, Foo\MyClass and `Foo\MyClass<Bar>` &raquo;](object_types.md#named-objectsmd)
* [Generator](object_types.md#generators)
* [Generator &raquo;](object_types.md#generators)
* [Array types &raquo;](array_types.md)
* [array&lt;int, string&gt; &raquo;](array_types.md#generic-arrays)
* [non-empty-array &raquo;](array_types.md#non-empty-array)
@ -34,8 +34,6 @@ _Click on the &raquo; next to each type to view detailed documentation and examp
* [list & non-empty-list &raquo;](array_types.md#lists)
* [list&lt;string&gt; &raquo;](array_types.md#lists)
* [array{foo: int, bar: string} and list{int, string} &raquo;](array_types.md#object-like-arrays)
* [Sealed arrays &raquo;](array_types.md#sealed-object-like-arrays)
* [Unsealed arrays &raquo;](array_types.md#unsealed-object-like-arrays)
* [callable-array &raquo;](array_types.md#callable-arrays)
* [Callable types &raquo;](callable_types.md)
* [Value types &raquo;](value_types.md)

View File

@ -15,8 +15,8 @@ required to implement multiple interfaces.
Another use case is being able to merge object-like arrays:
```php
/**
* @psalm-type A=strict-array{a: int}
* @psalm-type B=strict-array{b: int}
* @psalm-type A=array{a: int}
* @psalm-type B=array{b: int}
*
* @param A $a
* @param B $b

View File

@ -5,7 +5,7 @@ _Click on the &raquo; next to each type to view detailed documentation and examp
- [object &raquo;](#unnamed-objects)
- [object{foo: string} &raquo;](#object-properties)
- [Exception, Foo\MyClass and Foo\MyClass&lt;Bar&gt; &raquo;](#named-objects)
- [Generator](#generators)
- [Generator &raquo;](#generators)
## Unnamed objects

View File

@ -22,7 +22,7 @@ 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<strict-array{a: mixed, b: mixed}|strict-array{c: mixed}>` evaluates to `'a'|'b'|'c'`
- `key-of<array{a: mixed, b: mixed}|array{c: mixed}>` evaluates to `'a'|'b'|'c'`
- `key-of<string[]>` evaluates to `array-key`
- `key-of<T>` evaluates to the template param's offset-type (ensure `@template T of array`)
@ -56,7 +56,7 @@ The `value-of` utility returns the value-type for any [array type](array_types.m
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<strict-array{a: bool, b: int}|strict-array{c: string}>` evaluates to `bool|int|string`
- `value-of<array{a: bool, b: int}|array{c: string}>` evaluates to `bool|int|string`
- `value-of<string[]>` evaluates to `string`
- `value-of<T>` evaluates to the template param's value-type (ensure `@template T of array`)
@ -121,7 +121,7 @@ properties with a certain visibility:
### Sealed array support
Use final classes if you want to properties-of and get_object_vars to return [sealed arrays](array_types.md#sealed-object-like-arrays):
Use final classes if you want to properties-of and get_object_vars to return sealed arrays:
```php
/**
@ -144,10 +144,10 @@ final class B extends A {
}
$a = asArray(new A);
/** @psalm-trace $a */; // unsealed-strict-array{foo: string, bar: int}
/** @psalm-trace $a */; // array{foo: string, bar: int, ...}
$b = asArray(new B);
/** @psalm-trace $b */; // strict-array{foo: string, bar: int, baz: float}
/** @psalm-trace $b */; // array{foo: string, bar: int, baz: float}
```
## `class-string-map<T as Foo, T>`
@ -273,7 +273,7 @@ Psalm allows defining type aliases for complex types (like array shapes) which m
```php
/**
* @psalm-type PhoneType = strict-array{phone: string}
* @psalm-type PhoneType = array{phone: string}
*/
class Phone {
/**

View File

@ -430,7 +430,7 @@ Please note that changing this setting might introduce unwanted side effects and
maxShapedArraySize="100"
>
```
This setting controls the maximum size of shaped arrays that will be transformed into a shaped `strict-array{key1: "value", key2: T}` type during Psalm analysis.
This setting controls the maximum size of shaped arrays that will be transformed into a shaped `array{key1: "value", key2: T}` type during Psalm analysis.
Arrays bigger than this value (100 by default) will be transformed in a generic `non-empty-array` type, instead.
Please note that changing this setting might introduce unwanted side effects and those side effects won't be considered as bugs.
@ -524,8 +524,8 @@ The following configuration declares custom types for super-globals (`$GLOBALS`
```xml
<globals>
<var name="GLOBALS" type="strict-array{DB: MyVendor\DatabaseConnection, VIEW: MyVendor\TemplateView}" />
<var name="_GET" type="strict-array{data: array<string, string>}" />
<var name="GLOBALS" type="array{DB: MyVendor\DatabaseConnection, VIEW: MyVendor\TemplateView}" />
<var name="_GET" type="array{data: array<string, string>}" />
</globals>
```
@ -545,6 +545,6 @@ Plugins can access or modify the global configuration in plugins using
```php
$config = \Psalm\Config::getInstance();
if (!isset($config->globals['$GLOBALS'])) {
$config->globals['$GLOBALS'] = 'strict-array{data: array<string, string>}';
$config->globals['$GLOBALS'] = 'array{data: array<string, string>}';
}
```

View File

@ -172,8 +172,8 @@ if (true === $first) {
`TKeyedArray` represents an 'object-like array' - an array with known keys.
``` php
$x = ["a" => 1, "b" => 2]; // is TKeyedArray, strict-array{a: int, b: int}
$y = rand(0, 1) ? ["a" => null] : ["a" => 1, "b" => "b"]; // is TKeyedArray with optional keys/values, strict-array{a: ?int, b?: string}
$x = ["a" => 1, "b" => 2]; // is TKeyedArray, array{a: int, b: int}
$y = rand(0, 1) ? ["a" => null] : ["a" => 1, "b" => "b"]; // is TKeyedArray with optional keys/values, array{a: ?int, b?: string}
```
Note that not all associative arrays are considered object-like. If the keys are not known, the array is treated as a mapping between two types.