Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup documentation #8702

Merged
merged 3 commits into from Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/annotating_code/type_syntax/atomic_types.md
Expand Up @@ -26,16 +26,14 @@ _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)
* [string\[\] &raquo;](array_types.md#phpdoc-syntax)
* [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)
Expand Down
4 changes: 2 additions & 2 deletions docs/annotating_code/type_syntax/intersection_types.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/annotating_code/type_syntax/object_types.md
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions docs/annotating_code/type_syntax/utility_types.md
Expand Up @@ -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`)

Expand Down Expand Up @@ -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`)

Expand Down Expand Up @@ -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
/**
Expand All @@ -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>`
Expand Down Expand Up @@ -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 {
/**
Expand Down
8 changes: 4 additions & 4 deletions docs/running_psalm/configuration.md
Expand Up @@ -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.
Expand Down Expand Up @@ -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>
```

Expand All @@ -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>}';
}
```
4 changes: 2 additions & 2 deletions docs/running_psalm/plugins/plugins_type_system.md
Expand Up @@ -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.
Expand Down