From 9c23824b08d20b443de2267914bfc693c46ab371 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 9 Nov 2022 10:17:38 +0100 Subject: [PATCH 1/2] Try fix formatting --- .../type_syntax/atomic_types.md | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/docs/annotating_code/type_syntax/atomic_types.md b/docs/annotating_code/type_syntax/atomic_types.md index cfe64147397..a4f9add7bd2 100644 --- a/docs/annotating_code/type_syntax/atomic_types.md +++ b/docs/annotating_code/type_syntax/atomic_types.md @@ -5,58 +5,58 @@ Atomic types are the basic building block of all type information used in Psalm. _Click on the » next to each type to view detailed documentation and examples._ * [Scalar types »](scalar_types.md) - * [bool »](scalar_types.md#scalar) - * [int »](scalar_types.md#scalar) - * [float »](scalar_types.md#scalar) - * [string »](scalar_types.md#scalar) - * [`int-range` »](scalar_types.md#int-range) - * [`int-mask<1, 2, 4>` »](scalar_types.md#int-mask1-2-4) - * [`int-mask-of` »](scalar_types.md#int-mask-ofmyclassclass_constant_) - * [class-string and class-string<Foo> »](scalar_types.md#class-string-interface-string) - * [trait-string »](scalar_types.md#trait-string) - * [enum-string »](scalar_types.md#enum-string) - * [callable-string »](scalar_types.md#callable-string) - * [numeric-string »](scalar_types.md#numeric-string) - * [literal-string »](scalar_types.md#literal-string) - * [literal-int »](scalar_types.md#literal-int) - * [array-key »](scalar_types.md#array-key) - * [numeric »](scalar_types.md#numeric) - * [scalar »](scalar_types.md#scalar) + * [bool »](scalar_types.md#scalar) + * [int »](scalar_types.md#scalar) + * [float »](scalar_types.md#scalar) + * [string »](scalar_types.md#scalar) + * [`int-range` »](scalar_types.md#int-range) + * [`int-mask<1, 2, 4>` »](scalar_types.md#int-mask1-2-4) + * [`int-mask-of` »](scalar_types.md#int-mask-ofmyclassclass_constant_) + * [class-string and class-string<Foo> »](scalar_types.md#class-string-interface-string) + * [trait-string »](scalar_types.md#trait-string) + * [enum-string »](scalar_types.md#enum-string) + * [callable-string »](scalar_types.md#callable-string) + * [numeric-string »](scalar_types.md#numeric-string) + * [literal-string »](scalar_types.md#literal-string) + * [literal-int »](scalar_types.md#literal-int) + * [array-key »](scalar_types.md#array-key) + * [numeric »](scalar_types.md#numeric) + * [scalar »](scalar_types.md#scalar) * [Object types »](object_types.md) - * [object »](object_types.md#unnamed-objects) - * [object{foo: string} »](object_types.md#object-properties) - * [Exception, Foo\MyClass and `Foo\MyClass` »](object_types.md#named-objectsmd) - * [Generator](object_types.md#generators) + * [object »](object_types.md#unnamed-objects) + * [object{foo: string} »](object_types.md#object-properties) + * [Exception, Foo\MyClass and `Foo\MyClass` »](object_types.md#named-objectsmd) + * [Generator](object_types.md#generators) * [Array types »](array_types.md) - * [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) - * [list<string> »](array_types.md#lists) - * [array{foo: int, bar: string} and list{int, string} »](array_types.md#object-like-arrays) - * [Sealed arrays »](array_types.md#sealed-object-like-arrays) - * [Unsealed arrays »](array_types.md#unsealed-object-like-arrays) - * [callable-array »](array_types.md#callable-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) + * [list<string> »](array_types.md#lists) + * [array{foo: int, bar: string} and list{int, string} »](array_types.md#object-like-arrays) + * [Sealed arrays »](array_types.md#sealed-object-like-arrays) + * [Unsealed arrays »](array_types.md#unsealed-object-like-arrays) + * [callable-array »](array_types.md#callable-arrays) * [Callable types »](callable_types.md) * [Value types »](value_types.md) - * [null »](value_types.md#null) - * [true, false »](value_types.md#true-false) - * [6, 7.0, "forty-two" and 'forty two' »](value_types.md#some_string-4-314) - * [Foo\Bar::MY_SCALAR_CONST »](value_types.md#regular-class-constants) + * [null »](value_types.md#null) + * [true, false »](value_types.md#true-false) + * [6, 7.0, "forty-two" and 'forty two' »](value_types.md#some_string-4-314) + * [Foo\Bar::MY_SCALAR_CONST »](value_types.md#regular-class-constants) * [Utility types »](utility_types.md) - * [(T is true ? string : bool) »](conditional_types.md) - * [`key-of` »](utility_types.md#key-oft) - * [`value-of` »](utility_types.md#value-oft) - * [`properties-of` »](utility_types.md#properties-oft) - * [`class-string-map` »](utility_types.md#class-string-mapt-as-foo-t) - * [`T[K]` »](utility_types.md#tk) - * [Type aliases »](utility_types.md#type-aliases) - * [Variable templates »](utility_types.md#variable-templates) + * [(T is true ? string : bool) »](conditional_types.md) + * [`key-of` »](utility_types.md#key-oft) + * [`value-of` »](utility_types.md#value-oft) + * [`properties-of` »](utility_types.md#properties-oft) + * [`class-string-map` »](utility_types.md#class-string-mapt-as-foo-t) + * [`T[K]` »](utility_types.md#tk) + * [Type aliases »](utility_types.md#type-aliases) + * [Variable templates »](utility_types.md#variable-templates) * [Other types »](other_types.md) - * [`iterable` »](other_types.md) - * [void »](other_types.md) - * [resource »](other_types.md) - * [closed-resource »](other_types.md) + * [`iterable` »](other_types.md) + * [void »](other_types.md) + * [resource »](other_types.md) + * [closed-resource »](other_types.md) * [Top and bottom types »](top_bottom_types.md) - * [mixed »](top_bottom_types.md#mixed) - * [never »](top_bottom_types.md#never) + * [mixed »](top_bottom_types.md#mixed) + * [never »](top_bottom_types.md#never) From f8b9e9759286f8b301bc5aaaf0c0a029af64ca05 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 9 Nov 2022 12:28:47 +0100 Subject: [PATCH 2/2] Fix heading indentation --- .../type_syntax/object_types.md | 10 ++++---- .../type_syntax/scalar_types.md | 24 +++++++++---------- .../type_syntax/top_bottom_types.md | 1 + .../type_syntax/utility_types.md | 2 +- .../type_syntax/value_types.md | 8 +++---- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/annotating_code/type_syntax/object_types.md b/docs/annotating_code/type_syntax/object_types.md index 33e6a63fb73..77ab57dde49 100644 --- a/docs/annotating_code/type_syntax/object_types.md +++ b/docs/annotating_code/type_syntax/object_types.md @@ -7,15 +7,15 @@ _Click on the » next to each type to view detailed documentation and examp - [Exception, Foo\MyClass and Foo\MyClass<Bar> »](#named-objects) - [Generator](#generators) -### Unnamed objects +## Unnamed objects `object` are examples of unnamed object types. This type is also a valid type in PHP. -### Named objects +## Named objects `stdClass`, `Foo`, `Bar\Baz` etc. are examples of named object types. These types are also valid types in PHP. -### Object properties +## Object properties Psalm supports specifying the properties of an object and their expected types, e.g.: @@ -34,11 +34,11 @@ Optional properties can be denoted by a trailing `?`, e.g.: /** @param object{optional?: string} */ ``` -### Generic object types +## Generic object types Psalm supports using generic object types like `ArrayObject`. Any generic object should be typehinted with appropriate [`@template` tags](../templated_annotations.md). -### Generators +## Generators Generator types support up to four parameters, e.g. `Generator`: diff --git a/docs/annotating_code/type_syntax/scalar_types.md b/docs/annotating_code/type_syntax/scalar_types.md index b202294d570..0f38ddcdcea 100644 --- a/docs/annotating_code/type_syntax/scalar_types.md +++ b/docs/annotating_code/type_syntax/scalar_types.md @@ -20,12 +20,12 @@ _Click on the » next to each type to view detailed documentation and examp * [numeric »](scalar_types.md#numeric) * [scalar »](scalar_types.md#scalar) -### scalar +## scalar `int`, `bool`, `float`, `string` are examples of scalar types. Scalar types represent scalar values in PHP. These types are also valid types in PHP 7. The type `scalar` is the supertype of all scalar types. -### int-range +## int-range Integer ranges indicate an integer within a range, specified using generic syntax: `int`. `x` and `y` must be integer numbers. @@ -51,15 +51,15 @@ Represents the type that is the result of a bitmask combination of its parameter Represents the type that is the result of a bitmask combination of its parameters. This is the same concept as [`int-mask`](#int-mask1-2-4) but this type is used with a reference to constants in code: `int-mask-of` will correspond to `0|1|2|3|4|5|6|7` if there are three constants called `CLASS_CONSTANT_{A,B,C}` with values 1, 2 and 4. -### array-key +## array-key `array-key` is the supertype (but not a union) of `int` and `string`. -### numeric +## numeric `numeric` is a supertype of `int` or `float` and [`numeric-string`](#numeric-string). -### class-string, interface-string +## class-string, interface-string Psalm supports a special meta-type for `MyClass::class` constants, `class-string`, which can be used everywhere `string` can. @@ -79,23 +79,23 @@ function takesClassName(string $s) : void {} You can also parameterize `class-string` with an object name e.g. [`class-string`](value_types.md#regular-class-constants). This tells Psalm that any matching type must either be a class string of `Foo` or one of its descendants. -### trait-string +## trait-string Psalm also supports a `trait-string` annotation denoting a trait that exists. -### enum-string +## enum-string Psalm also supports a `enum-string` annotation denote an enum that exists. -### callable-string +## callable-string `callable-string` denotes a string value that has passed an `is_callable` check. -### numeric-string +## numeric-string `numeric-string` denotes a string value that has passed an `is_numeric` check. -### literal-string +## literal-string `literal-string` denotes a string value that is entirely composed of strings in your application. @@ -113,7 +113,7 @@ Strings that don't pass this type check: - `$_GET["foo"]` - `"hello " . $_GET["foo"]` -### literal-int +## literal-int `literal-int` denotes an int value that is entirely composed of literal integers in your application. @@ -128,7 +128,7 @@ Integers that don't pass this type check: - `(int) $_GET["foo"]` - `((int)$_GET["foo"]) + 2` -### lowercase-string, non-empty-string, non-empty-lowercase-string +## lowercase-string, non-empty-string, non-empty-lowercase-string A non empty string, lowercased or both at once. diff --git a/docs/annotating_code/type_syntax/top_bottom_types.md b/docs/annotating_code/type_syntax/top_bottom_types.md index 324c021a72a..3500cfbc97c 100644 --- a/docs/annotating_code/type_syntax/top_bottom_types.md +++ b/docs/annotating_code/type_syntax/top_bottom_types.md @@ -6,6 +6,7 @@ This is the _top type_ in PHP's type system, and represents a lack of type information. Psalm warns about `mixed` types when the `reportMixedIssues` flag is turned on, or when you're on level 1. ## `never` + It can be aliased to `no-return` or `never-return` in docblocks. Note: it replaced the old `empty` type that used to exist in Psalm This is the _bottom type_ in PHP's type system. It's used to describe a type that has no possible value. It can happen in multiple cases: diff --git a/docs/annotating_code/type_syntax/utility_types.md b/docs/annotating_code/type_syntax/utility_types.md index 6f6670d5802..dabdca0b68c 100644 --- a/docs/annotating_code/type_syntax/utility_types.md +++ b/docs/annotating_code/type_syntax/utility_types.md @@ -119,7 +119,7 @@ properties with a certain visibility: - `private-properties-of` -### Limited template support +### 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): diff --git a/docs/annotating_code/type_syntax/value_types.md b/docs/annotating_code/type_syntax/value_types.md index 610274202a2..f1e833acfd0 100644 --- a/docs/annotating_code/type_syntax/value_types.md +++ b/docs/annotating_code/type_syntax/value_types.md @@ -9,19 +9,19 @@ _Click on the » next to each type to view detailed documentation and examp - [6, 7.0, "forty-two" and 'forty two' »](#some_string-4-314) - [Foo\Bar::MY_SCALAR_CONST »](#regular-class-constants) -### null +## null This is the `null` value, destroyer of worlds. Use it sparingly. Psalm supports you writing `?Foo` to mean `null|Foo`. -### true, false +## true, false Use of `true` and `false` is also PHPDoc-compatible -### "some_string", 4, 3.14 +## "some_string", 4, 3.14 Psalm also allows you specify literal values in types, e.g. `@return "good"|"bad"` -### Regular class constants +## Regular class constants Psalm allows you to include class constants in types, e.g. `@return Foo::GOOD|Foo::BAD`. You can also specify explicit class strings e.g. `Foo::class|Bar::class`