mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
add documentation for pure-callable (#4329)
This commit is contained in:
parent
e3bb43641c
commit
91e8e26937
@ -336,6 +336,23 @@ echo Arithmetic::addCumulative(3); // outputs 3
|
|||||||
echo Arithmetic::addCumulative(3); // outputs 6
|
echo Arithmetic::addCumulative(3); // outputs 6
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `@pure-callable`
|
||||||
|
|
||||||
|
On the other hand, `pure-callable` can be used to denote a callable which needs to be pure.
|
||||||
|
|
||||||
|
```php
|
||||||
|
/**
|
||||||
|
* @param pure-callable(mixed): int $callback
|
||||||
|
*/
|
||||||
|
function foo(callable $callback) {...}
|
||||||
|
|
||||||
|
// this fails since random_int is not pure
|
||||||
|
foo(
|
||||||
|
/** @param mixed $p */
|
||||||
|
fn($p) => random_int(1, 2)
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
### `@psalm-allow-private-mutation`
|
### `@psalm-allow-private-mutation`
|
||||||
|
|
||||||
Used to annotate readonly properties that can be mutated in a private context. With this, public properties can be read from another class but only be mutated within a method of its own class.
|
Used to annotate readonly properties that can be mutated in a private context. With this, public properties can be read from another class but only be mutated within a method of its own class.
|
||||||
|
Loading…
Reference in New Issue
Block a user