mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #8689 from Nicelocal/fix_formatting
This commit is contained in:
commit
4d53d26f00
@ -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<x, y>` »](scalar_types.md#int-range)
|
||||
* [`int-mask<1, 2, 4>` »](scalar_types.md#int-mask1-2-4)
|
||||
* [`int-mask-of<MyClass::CLASS_CONSTANT_*>` »](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<x, y>` »](scalar_types.md#int-range)
|
||||
* [`int-mask<1, 2, 4>` »](scalar_types.md#int-mask1-2-4)
|
||||
* [`int-mask-of<MyClass::CLASS_CONSTANT_*>` »](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<Bar>` »](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<Bar>` »](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<T>` »](utility_types.md#key-oft)
|
||||
* [`value-of<T>` »](utility_types.md#value-oft)
|
||||
* [`properties-of<T>` »](utility_types.md#properties-oft)
|
||||
* [`class-string-map<T as Foo, T>` »](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<T>` »](utility_types.md#key-oft)
|
||||
* [`value-of<T>` »](utility_types.md#value-oft)
|
||||
* [`properties-of<T>` »](utility_types.md#properties-oft)
|
||||
* [`class-string-map<T as Foo, T>` »](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<TKey, TValue>` »](other_types.md)
|
||||
* [void »](other_types.md)
|
||||
* [resource »](other_types.md)
|
||||
* [closed-resource »](other_types.md)
|
||||
* [`iterable<TKey, TValue>` »](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)
|
||||
|
@ -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<int, string>`. 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<int, string, mixed, void>`:
|
||||
|
||||
|
@ -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, y>`.
|
||||
`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<MyClass::CLASS_CONSTANT_*>` 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<Foo>`](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.
|
||||
|
||||
|
@ -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:
|
||||
|
@ -119,7 +119,7 @@ properties with a certain visibility:
|
||||
- `private-properties-of<T>`
|
||||
|
||||
|
||||
### 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):
|
||||
|
||||
|
@ -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`
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user